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 10.43.85.198 with SMTP id ap6mr2510123icc.29.1411488518031; Tue, 23 Sep 2014 09:08:38 -0700 (PDT) X-Received: by 10.140.33.161 with SMTP id j30mr9523qgj.4.1411488517996; Tue, 23 Sep 2014 09:08:37 -0700 (PDT) Path: border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!h15no4847370igd.0!news-out.google.com!i10ni26qaf.0!nntp.google.com!w8no91588qac.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 23 Sep 2014 09:08:37 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=108.44.225.195; posting-account=vk6_JwoAAABkMyHO1YfdP69Hm3CpbdGR NNTP-Posting-Host: 108.44.225.195 References: <024b1649-e056-4b7a-9072-7c7ef0c53f0b@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Trying to understand Ada.Finalization.Controlled assignment mechanics. From: Jeremiah Injection-Date: Tue, 23 Sep 2014 16:08:38 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: number.nntp.dca.giganews.com comp.lang.ada:189105 Date: 2014-09-23T09:08:37-07:00 List-Id: On Monday, September 22, 2014 9:17:18 PM UTC-4, Jeffrey Carter wrote: > On 09/22/2014 05:43 PM, Jeremiah wrote: >=20 > > tester : test_class2.test :=3D test_class2.Make(new Integer'(45)); >=20 > > >=20 > > The output I am seeing doesn't make sense to me: >=20 > > Adjusting >=20 > > Finalizing (FREED) >=20 > > Adjusting >=20 > > Finalizing >=20 > > Hello World >=20 > > Finalizing >=20 >=20 >=20 > Your test example is complicated by the use of the function and the aggre= gate >=20 > inside it. Someone with a better understanding of GNAT's handling of con= trolled >=20 > objects should probably comment on this. But it might be a good idea to s= tart >=20 > with a simpler test case, involving no initialization, functions, aggrega= tes, or >=20 > access types, and then complicate it step by step. >=20 >=20 >=20 > ARM 7.6(17.1/3) says >=20 >=20 >=20 > 'When a function call or aggregate is used to initialize an object, the r= esult >=20 > of the function call or aggregate is an anonymous object, which is assign= ed into >=20 > the newly-created object.' >=20 >=20 >=20 > My guess is that there are both an aggregate object and function return o= bject. >=20 > The aggregate object is copied into the function return object (FRO), the= FRO is >=20 > adjusted, and the aggregate object is finalized. The the FRO is copied in= to >=20 > Tester, Tester is adjusted, and the FRO is finalized. The body of the mai= n >=20 > procedure is then executed, and Tester is finalized. But I could be way o= ff. >=20 >=20 >=20 > http://www.adaic.org/resources/add_content/standards/12rm/html/RM-7-6.htm= l >=20 It does complicate things, and in the simpler case (using a Set procedure),= it does highlight a misunderstanding of mine. I incorrectly assumed Adjus= t would occur on B, when based on your response and rereading the RM sectio= n a few times, Adjust occurs on A instead. =20 Am I understanding that correctly? If so, then this would explain what I a= m seeing as I am setting the target to null and not nulling the previous ob= ject (which is the reverse of what I previously understood). TLDR version (barring the actual complexities you noted above): I previously thought: A :=3D B Finalize(A) copying B into A Adjust(B) But in reality it is closer to: Finalize(A) copying B into A Adjust(A) Again, not taking into account the complexities of FRO's and Anonymous Obje= cts.