Fortran 无法打印派生类型内可分配的已分配状态

Fortran 无法打印派生类型内可分配的已分配状态,fortran,gfortran,allocatable-array,Fortran,Gfortran,Allocatable Array,我想知道为什么这段代码在最后一次打印时返回错误 使用gfortran 7.4.0失败,但使用ifort 18.0.3效果良好 program test implicit none type :: syntax integer, allocatable :: f(:) end type type(syntax), allocatable :: rhs(:) allocate(rhs(2)) print*, allocated(rhs(2)%f) print*, allocated(rhs(s

我想知道为什么这段代码在最后一次打印时返回错误

使用gfortran 7.4.0失败,但使用ifort 18.0.3效果良好

program test
implicit none
type :: syntax
  integer, allocatable :: f(:)
end type
type(syntax), allocatable :: rhs(:)

allocate(rhs(2))
print*, allocated(rhs(2)%f)
print*, allocated(rhs(size(rhs))%f)
end program
gfortran错误为:

F
程序接收信号SIGSEGV:分段故障-内存引用无效。
此错误的回溯跟踪:
#0 0x7f4cf40442da英寸???
#1 0x7f4cf4043503英寸???
#2 0x7f4cf3c76f1f英寸???
#3 0x55aa522e5e50处于测试状态
at/home/pena/Escritorio/c.f90:10
#主电路中有4个0x55aa522e5f0d
at/home/pena/Escritorio/c.f90:11
分段中提琴(`核心'一般)

这是gfortran中的一个bug,在版本8中不存在

如果您无法升级编译器,那么有一个简单的替代方法:只需为
size(rhs)
使用一个临时变量:

使用gfortran 7.4.0提供输出:

 F
 F

@francescalus我刚刚在帖子中提到了这个错误。ifort的结果如何?在两个打印语句之间放置时打印的内容
print*,大小(rhs)
。有了gfortran 7.3.0(Cygwin),我得到了
F
2
T
@albert,ifort给出的解决方案是:谢谢你,我会做的。
 F
 F