(j3.2006) deallocating pointer function results
Bill Long
longb
Tue Nov 3 09:17:47 EST 2015
On Nov 3, 2015, at 4:34 AM, Robert Corbett <robert.corbett at oracle.com> wrote:
> The following message is based on a thread on comp.lang.fortran.
> All references are with respect to Fortran 2008.
>
> Consider the following program:
>
> !-----------------------------------------------------------------
>
> program main
>
> deallocate( new_int() ) ! (1)
> call my_deallocate( new_int() ) ! (2)
> call hmm_deallocate( new_int() ) ! (3)
>
> contains
> function new_int()
> integer, pointer :: new_int
> allocate(new_int)
> new_int = 3
> end function
>
> subroutine my_deallocate(p)
> integer, pointer :: p
> deallocate( p )
> end subroutine
>
> subroutine hmm_deallocate(p)
> integer, pointer :: p, q
> q => p
> deallocate( q )
> end subroutine
> end
>
> !-----------------------------------------------------------------
>
> The statement marked (1) is clearly not permitted, because it
> violates syntax rule R632.
Agreed. I had to comment out this line to get the program to compile and run.
>
> The statement marked (2) leads to prohibited behavior.
> Subclause 5.3.10, paragraph 5, states
>
> If no INTENT attribute is specified for a dummy argument,
> its use is subject to the limitations of its effective
> argument (12.5.2).
>
> Because a function reference is not allowed as an
> /allocate-object/ in a DEALLOCATE statement, a dummy argument
> corresponding to an actual argument that is a function reference
> is not allowed as an /allocate-object/ in a DEALLOCATE statement.
> (I doubt that any existing implementation catches this error.)
I don?t agree with this. The actual argument is a function reference that returns a data pointer, which by our definitions, is a ?variable? (R602). The actual argument looks like any other associated data pointer for the purposes of argument association.
Cheers,
Bill
>
> I think that the behavior that results from the statement
> marked (3) is intended not to be permitted. I base my
> conclusion on a somewhat strained reading of Subclause 12.5.2.13,
> paragraph 1, which states
>
> While an entity is associated with a dummy argument,
> the following restrictions hold.
>
> (1) Action that affects the allocation status of
> the entity or a subobject thereof shall be
> taken through the dummy argument.
>
> One issue concerns the meaning of the phrase "the allocation
> status". I am assuming that it means "the allocation status or
> pointer association status". In all other cases where both the
> allocation status and the pointer allocation status are meant,
> they are both mentioned. A reason to believe that both are
> intended here is that the text in the Fortran 90 standard
> (Subclause 12.5.2.9 of the Fortran 90 standard) from which the
> quoted text was derived was described in a way that included
> both cases.
>
> The dummy argument is not used in the DEALLOCATE statement; a
> local pointer variable is used in its place. I assume that the
> deallocation is therefore not done "through" the dummy argument.
> An argument can be made against my assumption based on
> Subclause 5.3.10, paragraph 2. It states
>
> The INTENT(IN) attribute for a pointer dummy argument
> specifies that during the invocation and execution of
> the procedure its association shall not be changed
> except that it may become undefined if the target is
> deallocated other than through the pointer (16.5.2.5).
>
> If the "allocation status" of the pointer may be changed only
> through the dummy argument, then the last part of that clause
> is unnecessary.
>
> I would like to know if anyone disagrees with my conclusions.
>
> Robert Corbett
>
> _______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3
Bill Long longb at cray.com
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101
More information about the J3
mailing list