[J3] Self-assignment of allocatable component

Van Snyder van.snyder at sbcglobal.net
Tue Jul 27 00:37:07 UTC 2021


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> On Behalf Of Van Snyder
> via J3
> Sent: Tuesday, July 27, 2021 5:09 AM
> To: j3 at mailman.j3-fortran.org
> Cc: Van Snyder <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: 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 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/20210726/bf94cd54/attachment.htm>


More information about the J3 mailing list