Description
F2003 has introduced (re)allocation on assignment, but as mentioned on the Fortran Discourse it will work only on intrinsic assignment, not on defined assignment (overloaded assignment of a derived type).
type sometype
...
contains
procedure :: assign
generic :: assignment(=) => assign
end type
elemental subroutine assign(this,that)
class(type(sometype)), intent(out) :: this
type(type(sometype)), intent(in) :: that
...
end subroutine
.....................................
type(sometype) :: x
type(sometype), allocatable :: y
y = x ! illegal, as "=" is a defined assignment
For, the standard says "The interpretation of a defined assignment is provided by the subroutine that defines it", and in the example above the procedure assign
is called with an unallocated actual argument for a non allocatable and non optional dummy argument, which is illegal.
To me, it looks like a serious caveat... One could accept the limitation, but the compiler has no way to catch the problem, and the problem appears at runtime only (at best with a crash, at worst with a silent undefined behavior).
Is there any way to fix the problem in the standard? Is there a technical reason why the (re)allocation on assignment has not been extended to the defined assignment in the first place?