Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Beginner
9 Views

Bug(?) in sourced allocation when type hierachy contains generic assignment

Hi,

the code:

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.

Cheers

0 Kudos
3 Replies
Highlighted
Valued Contributor III
9 Views

The standard specifies for

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.

0 Kudos
Highlighted
Beginner
9 Views

You mean that one would need

You mean that one would need something like:

if(allocated(this%a) then
  Allocate(other%a,source=this%a)
End if

!?

That also seems to solve the seg fault.

THANK YOU.

0 Kudos
Highlighted
Valued Contributor III
9 Views

Quote:may.ka wrote:

may.ka wrote:

You mean that one would need something like:

if(allocated(this%a) then
  Allocate(other%a,source=this%a)
End if

!? ..

Yep.  

0 Kudos