[J3] Self-assignment of allocatable component
Malcolm Cohen
malcolm at nag-j.co.jp
Tue Jul 27 02:07:16 UTC 2021
Hi Van,
It is not a syntactic distinction, but a semantic one. MOVE_ALLOC changes the allocation state of both arguments, unlike an assignment statement where the expression is not a variable and not treated like a variable but treated like a value (after evaluation).
BTW, there was no interp concerning move_alloc. 16-130r1 spelled out the sequence more obviously, and this was for semantics of procedure invocation; literally, that INTENT(OUT) actions happen on invocation, and the allocation moving happens within the called procedure.
So this is just a red herring. There is no procedure being invoked here, the expression in an assignment is not associated with an INTENT(INOUT) argument, and so argument INTENT(OUT) semantics are not relevant. MOVE_ALLOC(X,Y) does not do anything like what X=Y does, so I cannot fathom why anyone would expect MOVE_ALLOC(X,X) to shine light on X=X.
(Maybe it ought to have been an interp, and maybe we ought to have forbidden move_alloc(x,x) on the grounds that it is both useless and confusing, but that water has long since passed into the sea... perhaps it’s now falling as rain.)
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Van Snyder via J3
Sent: Tuesday, July 27, 2021 9:37 AM
To: j3 at mailman.j3-fortran.org
Cc: Van Snyder <van.snyder at sbcglobal.net>
Subject: Re: [J3] Self-assignment of allocatable component
On Tue, 2021-07-27 at 08:27 +0900, Malcolm Cohen via J3 wrote:
No, the answer does not need to be consistent with a completely different situation. Assignment is assignment, procedure references are procedure references, and the assignment *cannot* look like this procedure reference.
The important point about the interp concerning move_alloc(a,a) was whether A would or would not remain allocated.
It had nothing to do with the syntactic distinction between an assignment statement and a subroutine call.
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
From: J3 <j3-bounces at mailman.j3-fortran.org <mailto:j3-bounces at mailman.j3-fortran.org> > On Behalf Of Van Snyder via J3
Sent: Tuesday, July 27, 2021 5:09 AM
To: j3 at mailman.j3-fortran.org <mailto:j3 at mailman.j3-fortran.org>
Cc: Van Snyder <van.snyder at sbcglobal.net <mailto:van.snyder at sbcglobal.net> >
Subject: Re: [J3] Self-assignment of allocatable component
The answer to this question needs to be consistent with the answer to what happens with
call move_alloc ( a, a )
There was an interp about this.
On Mon, 2021-07-26 at 15:15 -0400, Daniel C Chen via J3 wrote:
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: <mailto:cdchen at ca.ibm.com> cdchen at ca.ibm.com
Disclaimer
The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: 30 St. Giles, Oxford, OX1 3LE, United Kingdom. Please see our <https://www.nag.co.uk/content/privacy-notice> Privacy Notice for information on how we process personal data and for details of how to stop or limit communications from us.
This e-mail has been scanned for all viruses and malware, and may have been automatically archived by Mimecast Ltd, an innovator in Software as a Service (SaaS) for business.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210727/7cd0e4ad/attachment.htm>
More information about the J3
mailing list