public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Steve Kargl <sgk@troutmask.apl.washington.edu>
To: Alberto Luaces <aluaces@udc.es>
Cc: fortran@gcc.gnu.org
Subject: Re: move_alloc for types holding allocatable members
Date: Thu, 08 Oct 2015 20:34:00 -0000	[thread overview]
Message-ID: <20151008203419.GA80864@troutmask.apl.washington.edu> (raw)
In-Reply-To: <87pp0pi3i5.fsf@eps142.cdf.udc.es>

On Thu, Oct 08, 2015 at 09:06:42PM +0200, Alberto Luaces wrote:
> Steve Kargl writes:
> 
> > On Thu, Oct 08, 2015 at 06:18:19PM +0200, Alberto Luaces wrote:
> >>
> >>   allocate(mytemp(20))
> >>   call move_alloc(mytemp, myarray)
> >>
> >
> > What are you expecting to happen here?
> 
> Hi, Steve.  I wanted to grow the array to 20 elements.  My real code
> works that way, since the length is not known beforehand, and it usually
> gets bigger.  Did I reverse the arguments?
> 

  13.7.82 MOVE_ALLOC (FROM, TO)

  Description. Moves an allocation from one allocatable object to another.

  FROM  may be of any type and rank. It shall be allocatable. It is an
        INTENT(INOUT) argument.


  TO    shall be type compatible (5.1.1.2) with FROM and have the same
        rank.  It shall be allocatable.  It shall be polymorphic if FROM 
        is polymorphic.  It is an INTENT(OUT) argument.  Each nondeferred
        parameter of the declared type of TO shall have the same value
        as the corresponding parameter of the declared type of FROM.

  The allocation status of TO becomes unallocated if FROM is unallocated
  on entry to MOVE_ALLOC.  Otherwise, TO becomes allocated with dynamic
  type, type parameters, array bounds, and value identical to those that
  FROM had on entry to MOVE ALLOC.

  If TO has the TARGET attribute, any pointer associated with FROM on
  entry to MOVE_ALLOC becomes correspondingly associated with TO.  If
  TO does not have the TARGET attribute, the pointer association status
  of any pointer associated with FROM on entry becomes undefined.

  The allocation status of FROM becomes unallocated.


Note that TO is INTENT(OUT).  So,

   The INTENT (OUT) attribute for a nonpointer dummy argument specifies
   that it shall be defined before a reference to the dummy argument is
   made within the procedure and any actual argument that becomes
   associated with such a dummy argument shall be definable.  On invocation
   of the procedure, such a dummy argument becomes undefined except for
   components of an object of derived type for which default initialization
   has been specified.

My interpretation, which may be incorrect, is that

(1) myarray becomes undefined on entry into MOVE_ALLOC.  I'm too
    lazy at the moment to see if undefineness means proper deallocation
    of an allocatable entity.

(2) mytemp is allocated to size 20, but the component 'i' of each entity
    has not been allocated and are undefined.  So, your call to MOVE_ALLOC
    is invalid code because it is going to (implicitly) involve un-
    allocated entities.

So, yes, I believe you have the arguments backwards.

-- 
Steve

  reply	other threads:[~2015-10-08 20:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-08 16:18 Alberto Luaces
2015-10-08 17:57 ` Steve Kargl
2015-10-08 19:06   ` Alberto Luaces
2015-10-08 20:34     ` Steve Kargl [this message]
2015-10-09  8:23       ` Alberto Luaces
2015-10-08 19:35 ` Anton Shterenlikht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151008203419.GA80864@troutmask.apl.washington.edu \
    --to=sgk@troutmask.apl.washington.edu \
    --cc=aluaces@udc.es \
    --cc=fortran@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).