[J3] Self-assignment of allocatable component
Daniel C Chen
cdchen at ca.ibm.com
Mon Jul 26 19:15:25 UTC 2021
Is the following code standard conforming?
type dt
integer, allocatable :: i
end type
type(dt), pointer :: p
type(dt), target :: t
allocate(t%i)
t%i = 4
p => t
p = p !! self-assignment
end
>From 21-007r1 [p172: 23-30]
"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.
"
It seems it is invalid because according to "(1)", the allocatable
component "i" is deallocated. However, Note 8 seems suggest it is still a
conforming code as:
"NOTE 8
If an allocatable component of expr is unallocated, the corresponding
component of the variable has an
allocation status of unallocated after execution of the assignment."
Apprently p%i is unallocated after the self-assignment. Is this code still
standard conforming?
Thanks,
Daniel Chen
XL Fortran Development, Fortran Standard Representative
IBM Toronto Software Lab
Phone: 905-413-3056
Tie: 969-3056
Email: cdchen at ca.ibm.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210726/0180f1d9/attachment.htm>
More information about the J3
mailing list