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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,66f9ac28e8d63f60 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!inka.de!rz.uni-karlsruhe.de!news.belwue.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Enforcing initialization protocol for protected type Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1fcccc80-0142-4f07-8852-8d151ea96ee2@c37g2000yqi.googlegroups.com> <4aa53c59$0$30237$9b4e6d93@newsspool1.arcor-online.net> <73fb1051-edf9-43f8-be50-5a2faa866040@s31g2000yqs.googlegroups.com> <7z37lspxbvu5.xk9ag8zcslry$.dlg@40tude.net> <61284459-5a02-410a-8ffc-76ad4256f138@a7g2000yqo.googlegroups.com> Date: Fri, 11 Sep 2009 18:27:38 +0200 Message-ID: <1rusjydws2ko.rpfwzoyv4bzj$.dlg@40tude.net> NNTP-Posting-Date: 11 Sep 2009 18:27:38 CEST NNTP-Posting-Host: 312c3dc2.newsspool2.arcor-online.net X-Trace: DXC=mRTeK4E3k^[1`E>oC;JXEZA9EHlD;3YcR4Fo<]lROoRQ^YC2XCjHcbYPE31VF^PL]RDNcfSJ;bb[UIRnRBaCd On Fri, 11 Sep 2009 08:25:56 -0700 (PDT), AdaMagica wrote: > On 11 Sep., 11:03, "Dmitry A. Kazakov" > wrote: >> On Thu, 10 Sep 2009 22:01:17 -0700 (PDT), AdaMagica wrote: >>> On 7 Sep., 22:19, Maciej Sobczak wrote: >>>> This, however, opens another question: controlled finalization of >>>> protected types to release the state object, if it was allocated >>>> dynamically. Oops. >> >>> Use an access discriminant of an anonymous type and you will get a >>> coextension that is reclaimed automatically when the object goes out >>> of scope, see RM 3.10(14.3/2,14.4/2) [or in the newest draft of the >>> Amendment 2, (14.1/3,14.4/3), which is a bit clearer]. >> >>> See also RM 3.7(1.c/2..1.e/2). >> >> Hmm, what do you mean by that? When the discriminant's type is an anonymous >> access it is still declared at the declaration point of the type. It is not >> the declaration point of an object. So if the discriminant is obtained by >> the allocator new it will not be destroyed when the object leaves the >> scope. It will when the type does. If these scopes are different, the >> compiler will complain that the type in the allocator has a deeper level. > > type Disc is ... > > type Rec (D: access Disc) is record ... > > Obj: Rec (new Disc); > > The discriminant (a coextension of the object) will be deallocated > when Obj goes out of scope. OK I see. Anyway I would not use this design pattern because it would be a source of countless errors very difficult to track down. P.S. It looks like a language design bug. If allowed then at least it should have been like: Obj: subtype Rec (new Disc); -- An anonymous subtype is declared for Obj -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de