The following prints
with gfortran and
with crayftn. Thus, gfortran does not use defined assignment - but it should.
Note: If "right%foo" is not allocated, the code segfaults with crayftn.
integer :: i = 42
procedure :: assign0
generic :: assignment(=) => assign0
type(component), allocatable :: foo
elemental subroutine assign0(lhs,rhs)
class(component), intent(INout) :: lhs
class(component), intent(in) :: rhs
lhs%i = 20
type(parent) :: left, right
print *, right%foo
left = right
print *, left%foo
From Fortran 2008, "220.127.116.11 Interpretation of intrinsic assignments", paragraph 13 (excerpt):
"For a noncoarray allocatable component the following sequence of operations is applied.
(1) If the component of the variable is allocated, it is deallocated.
(2) If the component of the value of expr is allocated, the corresponding
component of the variable is allocated with the same dynamic type and type
parameters as the component of the value of expr. If it is an array, it is
allocated with the same bounds. The value of the component of the value of
expr is then assigned to the corresponding component of the variable using
defined assignment if the declared type of the component has a type-bound
defined assignment consistent with the component, and intrinsic assignment
for the dynamic type of that component otherwise."
Related to PR 46897, I guess. The difference is that we are dealing with ALLOCATABLE components here.
See also PR 57697; the a similar needs to be also addressed when fixing this bug, namely the case that for:
"foo" is NULL/unallocated while "bar" appears in the defined assignment.
See also PR46897 for another missing feature.