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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: Trying to understand Ada.Finalization.Controlled assignment mechanics. Date: Mon, 22 Sep 2014 18:17:13 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <024b1649-e056-4b7a-9072-7c7ef0c53f0b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Injection-Date: Tue, 23 Sep 2014 01:17:16 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="ff2e5d21b9fb0a12a9871c15f1d89f02"; logging-data="28012"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BmOV+FKXmiCn519eDD47eFay4JBw3jGc=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.0 In-Reply-To: <024b1649-e056-4b7a-9072-7c7ef0c53f0b@googlegroups.com> Cancel-Lock: sha1:hHhYNkdPDpzyc9kD9/x1B9lYPOM= Xref: number.nntp.dca.giganews.com comp.lang.ada:189095 Date: 2014-09-22T18:17:13-07:00 List-Id: On 09/22/2014 05:43 PM, Jeremiah wrote: > My understanding of assignment of a child of Ada.Finalization.Controlled is that if you do the following: > > A := B; -- A and B are derived from Ada.Finalization.Controlled > > That the following occurs: > Finalize(A); > Copy B into A; > Adjust(B); > > Is this correct? Not necessarily. This is an assignment statement. ARM 7.6(17) says 'For an assignment_statement, after the name and expression have been evaluated, and any conversion (including constraint checking) has been done, an anonymous object is created, and the value is assigned into it; that is, the assignment operation is applied. (Assignment includes value adjustment.) The target of the assignment_statement is then finalized. The value of the anonymous object is then assigned into the target of the assignment_statement. Finally, the anonymous object is finalized. As explained below, the implementation may eliminate the intermediate anonymous object, so this description subsumes the one given in 5.2, “Assignment Statements”.' So it could be Create C (the anonymous object); Copy B into C; Adjust (C); Finalize (A); Copy C into A; Adjust (A); Finalize (C); If the anonymous object is optimized away, then it becomes your sequence. > tester : test_class2.test := test_class2.Make(new Integer'(45)); > > The output I am seeing doesn't make sense to me: > Adjusting > Finalizing (FREED) > Adjusting > Finalizing > Hello World > Finalizing Your test example is complicated by the use of the function and the aggregate inside it. Someone with a better understanding of GNAT's handling of controlled objects should probably comment on this. But it might be a good idea to start with a simpler test case, involving no initialization, functions, aggregates, or access types, and then complicate it step by step. ARM 7.6(17.1/3) says 'When a function call or aggregate is used to initialize an object, the result of the function call or aggregate is an anonymous object, which is assigned into the newly-created object.' My guess is that there are both an aggregate object and function return object. The aggregate object is copied into the function return object (FRO), the FRO is adjusted, and the aggregate object is finalized. The the FRO is copied into Tester, Tester is adjusted, and the FRO is finalized. The body of the main procedure is then executed, and Tester is finalized. But I could be way off. http://www.adaic.org/resources/add_content/standards/12rm/html/RM-7-6.html -- Jeff Carter "Blessed are they who convert their neighbors' oxen, for they shall inhibit their girth." Monty Python's Life of Brian 83