(j3.2006) (SC22WG5.3966) question about deallocation
Robert Corbett
Robert.Corbett
Sat Mar 28 08:20:37 EDT 2009
Reinhold Bader wrote:
> Hello,
>
> Robert Corbett schrieb:
>
>>Consider the code fragment
>>
>> MODULE M
>> . . .
>> TYPE BASE
>> INTEGER I
>> CONTAINS
>> FINAL SUBR1
>> END TYPE
>> TYPE, EXTENDS(BASE) :: EXTENDED
>> CONTAINS
>> FINAL SUBR2
>> END TYPE
>> . . .
>> END MODULE
>>
>> PROGRAM MAIN
>> USE M
>> TYPE(EXTENDED), POINTER :: P
>> TYPE(BASE), POINTER :: Q
>> . . .
>> ALLOCATE(P)
>> Q => P%BASE
>> . . .
>> DEALLOCATE(Q)
>> . . .
>> END
>>
>>Is the DEALLOCATE statement standard conforming?
>
> I think it isn't. Clause 6.3.3.2 of the 2003 standard says that
>
> "If a pointer appears in a DEALLOCATE statement, it shall be associated
> with the whole of an object
> that was created by allocation."
>
> Surely this rule is also applicable for the case of type extension.
It is not clear to me what constitutes "the whole of an object." Even
before the addition of the object-oriented features, it was unclear.
I was surprised when I was told that the code
REAL, DIMENSION(:), POINTER :: P
REAL, POINTER :: Q
ALLOCATE(P(1))
Q => P(1)
DEALLOCATE(Q)
was standard conforming. The logic was that the storage referenced
by Q includes all of the storage allocated for P. In my example also,
the storage referenced by Q includes all of the storage allocated for P,
and so the same logic might apply. Or, it might not.
If my example code is not standard-conforming, it is harder to use
polymorphism to effectively implement discriminated unions than some
have claimed. If it is standard conforming, the rules for applying
finalizers are unclear at best and broken at worst.
Bob Corbett
> Regards
>
>> If so,
>>are both final subroutines invoked, or is only SUBR1
>>invoked? The implementation of deallocation in Sun
>>Fortran can easily be extended to support either
>>semantics.
>>
>>Bob Corbett
>>_______________________________________________
>>J3 mailing list
>>J3 at j3-fortran.org
>>http://j3-fortran.org/mailman/listinfo/j3
>>
>
>
> _______________________________________________
> J3 mailing list
> J3 at j3-fortran.org
> http://j3-fortran.org/mailman/listinfo/j3
More information about the J3
mailing list