From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2866100c9a2b8ce7 X-Google-Attributes: gid103376,public From: Jonas Nygren Subject: Re: Free'ing extended types Date: 1996/04/28 Message-ID: <318369E6.17EE@ehs.ericsson.se>#1/1 X-Deja-AN: 151873662 references: <3180F084.7285@ehs.ericsson.se> <4xpw8uirui.fsf@leibniz.enst-bretagne.fr> to: Laurent Guerby content-type: text/plain; charset=us-ascii organization: Ericsson Hewlett-Packard Telecommunications AB mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 2.01Gold (WinNT; I) Date: 1996-04-28T00:00:00+00:00 List-Id: Laurent Guerby wrote: > > Jonas Nygren writes > : I read the following in the RM on unchecked_deallocation: > : > : 13.11.2(16) > : .... The execution of a call to an instance of > : Unchecked_Deallocation is erroneous if the object > : was created other than by an allocator for an > : access type whose pool is Name'Storage_Pool. > : > : I don't quite understand what is written but have a > : vague feeling that the code example below could be > : labeled 'erroneous execution' by the above paragraph. > : > : Perhaps somebody can answer - is the following code legal: > : > : type a is tagged with .........; > : type ap is access all a'class; > : > : procedure free is new unchecked_deallocation(a, ap); > : > : tybe b is new a with .........; -- a is extended > : > : p : ap := new b; > : > : free(p); > : > : Are 'a' and 'b' belonging to the same Name'Storage_Pool? > : > : /jonas > > You should ask your favorite compiler ;-). In this case I don't Sorry, I got my example code wrong, it should have been: procedure free is new unchecked_deallocation(a'Class, ap); 13.11.2(16) talks about 'erroneous execution', i.e. an error which the compiler can/need not detect. In the example 'p' is a pointer to a'class and when the call to free is made it actually points to an instance of type 'b'. So the question is, could this be considered an erroneous execution? Laurent's compilable example: with Ada.Unchecked_Deallocation; procedure St is type a is tagged record X : Integer; end record; type ap is access all a'class; procedure free is new Ada.unchecked_deallocation(a'class, ap); -- ^ changed to compile type b is new a with record Y : Integer; end record; -- a is extended p : ap := new b; begin free(p); end St; > -- > -- Laurent Guerby, student at Telecom Bretagne (France), Team Ada. /jonas