From owner-sc22wg5@open-std.org  Mon Mar 30 02:30:58 2009
Return-Path: <owner-sc22wg5@open-std.org>
X-Original-To: sc22wg5-dom7
Delivered-To: sc22wg5-dom7@www2.open-std.org
Received: by www2.open-std.org (Postfix, from userid 521)
	id F16D3C178DA; Mon, 30 Mar 2009 02:30:57 +0200 (CET DST)
X-Original-To: sc22wg5@open-std.org
Delivered-To: sc22wg5@open-std.org
Received: from ns.nag-j.co.jp (218-42-159-107.cust.bit-drive.ne.jp [218.42.159.107])
	by www2.open-std.org (Postfix) with ESMTP id A7561C178D9
	for <sc22wg5@open-std.org>; Mon, 30 Mar 2009 02:30:43 +0200 (CET DST)
Received: from 218-42-159-108.cust.bit-drive.ne.jp ([218.42.159.108] helo=[127.0.0.1])
	by ns.nag-j.co.jp with esmtp (Exim 4.50)
	id 1Lo5NK-0003ea-3j
	for sc22wg5@open-std.org; Mon, 30 Mar 2009 09:29:14 +0900
Message-ID: <49D012B0.1020104@nag-j.co.jp>
Date: Mon, 30 Mar 2009 09:30:40 +0900
From: Malcolm Cohen <malcolm@nag-j.co.jp>
User-Agent: Thunderbird 3.0a1pre (Windows/2008022014)
MIME-Version: 1.0
To: WG5 <sc22wg5@open-std.org>
Subject: Re: (j3.2006) question about deallocation
References: <49CACA36.5070104@nag-j.co.jp> <49CDEC08.8040403@sun.com>
In-Reply-To: <49CDEC08.8040403@sun.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Sender: owner-sc22wg5@open-std.org
Precedence: bulk



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?
No.

Q is not associated with the whole of the object allocated by P, but 
only the "base" component thereof.

The answers that indicate otherwise are mistaken.  Whether EXTENDED 
takes up more memory than BASE in some/most/all implementations is not 
relevant to the question.  BASE is a part of EXTENDED, not the whole.  
It is certainly not prohibited for some implementation to actually have 
EXTENDED objects taking up more space than BASE (whether it is sensible 
is another matter).

>       ALLOCATE(P(1))
>       Q => P(1)
>       DEALLOCATE(Q) 

Did we *really* say that in an official interpretation?  Which one?  
Assuming we did, I share your disquiet about the overly simplistic reply 
to this other question, but they can be separated - if one accepts that 
arrays are just collections of elements.  It's not clear to me that 
that's a good thing to do (rather the opposite in fact), but it is not 
quite the same question.

Bill Long wrote (that it should be allowed and):
> 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.
>   
That answer is not consistent with the design of final subroutines, and 
not consistent with types.  An object of type EXTENDED was allocated.  
To deallocate an object of type EXTENDED one must deallocate an object 
of type EXTENDED - this must be fundamental to the whole idea of derived 
types.  As far as I am concerned there is no question - the program is 
not, and cannot reasonably be considered to be, standard conforming.

Cheers,
-- 
.......................Malcolm Cohen, Nihon NAG, Tokyo.


