Module testmod Type :: root_type integer, allocatable :: a contains Generic, Public :: Assignment(=) => Copy Procedure, Pass(this) :: Copy => SubCopy End type root_type Type, extends(root_type) :: child_type End type child_type contains Subroutine SubCopy(other,this) Class(root_type), Intent(In) :: this Class(root_type), Intent(InOut) :: other Allocate(other%a,source=this%a) end Subroutine SubCopy End Module testmod Program Test Use testmod, only: child_type Type(child_type), allocatable :: x,y allocate(x) allocate(y,source=x) end Program Test
compiles with ifort 17.05 to 18.01 and with gfortran 7.2, but the ifort exec yields a seg fault at run time:
forrtl: severe (174): SIGSEGV, segmentation fault occurred Image PC Routine Line Source a.out 000000000040396D Unknown Unknown Unknown libpthread-2.26.s 000014D0F3566DA0 Unknown Unknown Unknown a.out 0000000000402A8E Unknown Unknown Unknown a.out 00000000004029DE Unknown Unknown Unknown libc-2.26.so 000014D0F31BDF4A __libc_start_main Unknown Unknown a.out 00000000004028EA Unknown Unknown Unknown
workaround is to either use "root_type" directly, or to comment the generic assignment. I am almost certain that this is a bug, but maybe others can confirm or tell me what I did wrong.
The standard specifies for the ALLOCATE statement, "If source-expr is allocatable, it shall be allocated." which is not the case in the code you show: in your SubCopy procedure, the instructions need to take into account whether this%a is allocated.