(j3.2006) question about deallocation

Robert Corbett Robert.Corbett
Sat Mar 28 09:18:08 EDT 2009


Bill Long wrote:
> 
> Robert Corbett wrote:
> 
>>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?  
> 
> 
> The extended type does not add any components, so it looks OK to me.

Your answer is consistent with what I have heard from members of the
committee regarding similar cases, as I noted in my response to
Reinhold Bader.

>>If so,
>>are both final subroutines invoked, or is only SUBR1
>>invoked? 
> 
> 
> The type of the object being deallocated is BASE, and a final routine is 
> bound to the type, so I would say SUBR1 (only) is executed.

Your answer here is what I think a literal reading of the standard
would yield.  I fear that interpretation will prove troublesome for
users.

Bob Corbett



More information about the J3 mailing list