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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a24:ed8c:: with SMTP id r134mr8422053ith.30.1545322947942; Thu, 20 Dec 2018 08:22:27 -0800 (PST) X-Received: by 2002:aca:5395:: with SMTP id h143mr116430oib.6.1545321747601; Thu, 20 Dec 2018 08:02:27 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!2.eu.feeder.erje.net!4.us.feeder.erje.net!feeder.erje.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!k10no41622itk.0!news-out.google.com!v71ni138ita.0!nntp.google.com!k10no41619itk.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 20 Dec 2018 08:02:27 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=98.118.241.43; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 98.118.241.43 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Potential Coextension Bug in GNAT From: Jere Injection-Date: Thu, 20 Dec 2018 16:22:27 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:55085 Date: 2018-12-20T08:02:27-08:00 List-Id: On Thursday, December 20, 2018 at 10:59:02 AM UTC-5, Jere wrote: > I was messing around and trying to learn coextensions and > I came across some counter intuitive functionality. If I > directly initialize one via an aggregate, it works fine. > However, if I initialize through a constructing function, > it seems to treat the access discriminant as a normal access > type and finalizes it at the end of the program instead of > when the object leaves scope. I don't fully understand them > yet and there isn't much on them listed in the RM but one > section (at least according to the index)[1]. That one > section does indicate that initialization via a function > should be valid however, so maybe I am back to I am doing it > wrong or potentially a GNAT bug. > > I'm using GNAT 7.1.1 > > Here is my test program > > **************************************************** > > with Ada.Text_IO; use Ada.Text_IO; > with Ada.Finalization; use Ada.Finalization; > > procedure Hello is > > type Thing_1 is new Limited_Controlled with null record; > > overriding > procedure Finalize(Self : in out Thing_1) is > begin > Put_Line("Finalize Thing_1"); > end Finalize; > > type Thing_2 > (Other : not null access Thing_1) > is limited null record; > > procedure Test_Coextension_1 is > The_Thing : Thing_2(new Thing_1); > begin > Put_Line("Coextenson directly initialized"); > end Test_Coextension_1; > > function Make_Thing_2 return Thing_2 is > begin > return (Other => new Thing_1); > end Make_Thing_2; > > procedure Test_Coextension_2 is > The_Thing : Thing_2 := Make_Thing_2; > begin > Put_Line("Coextension initialized through build in place"); > end Test_Coextension_2; > > begin > Test_Coextension_1; > Test_Coextension_2; > Put_Line("Test Finished"); > end Hello; > > **************************************************** > > Any thoughts? > > [1] Ada 2012 tc1 RM 3.10.2(14.4/3) - http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-3-10-2.html#I2301 Sorry, forgot to put the program output: ************************************************** $gnatmake -o hello *.adb gcc -c hello.adb gnatbind -x hello.ali gnatlink hello.ali -o hello $hello Coextenson directly initialized Finalize Thing_1 Coextension initialized through build in place Test Finished Finalize Thing_1