[J3] [EXTERNAL] Self-assignment of allocatable component
Clune, Thomas L. (GSFC-6101)
thomas.l.clune at nasa.gov
Mon Jul 26 19:41:06 UTC 2021
I certainly hope that the intent is for the assignment to be standard conforming and that p%i is allocated after the assignment.
The cited text indicates otherwise, and I believe it should be repaired.
* Tom
From: J3 <j3-bounces at mailman.j3-fortran.org> on behalf of j3 <j3 at mailman.j3-fortran.org>
Reply-To: j3 <j3 at mailman.j3-fortran.org>
Date: Monday, July 26, 2021 at 3:17 PM
To: j3 <j3 at mailman.j3-fortran.org>
Cc: Daniel C Chen <cdchen at ca.ibm.com>
Subject: [EXTERNAL] [J3] Self-assignment of allocatable component
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/055896fd/attachment-0001.htm>
More information about the J3
mailing list