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: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Why is the destructor called multiple times after I declare an object? Date: Tue, 12 Jan 2016 10:33:48 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <293c58ac-4ebd-488a-abcc-b6e88811eec8@googlegroups.com> <871t9ogevj.fsf@theworld.com> NNTP-Posting-Host: bqgfK7NL3xTHnr0WRaLl4g.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:29099 Date: 2016-01-12T10:33:48+01:00 List-Id: On 12/01/2016 00:44, Randy Brukardt wrote: > "Dmitry A. Kazakov" wrote in message > news:n715oq$fae$1@gioia.aioe.org... >> On 2016-01-11 19:17, Bob Duff wrote: >>> Brian Drummond writes: >>> >>>> Somehow I expected "extended return" to allocate space and "build in >>>> place" during the execution of the return statement. >>> >>> Build-in-place is done for return of immutably-limited types, >>> whether or not the extended return syntax is used. >> >> But you can leave one return statement on an exception, catch the >> exception, and then return through another return statement, with other >> discriminants and even other type of the result (if it is class-wide). >> >> Therefore the result can be potentially allocated and reallocated any >> number of times. In which sense is this behavior 'in-place'? > > "Build-in-place" means simply that there is no temporary object, the object > is created directly in its final resting place (that is the memory where it > will live during its existence). > > Whatever amount of effort it takes to figure out that final resting place is > not part of the equation. Yes, but you said 'no temporary object' which is untrue because a return statement creates exactly such an object. You could even use this object in order to create another one: return Candidate_1 : T (Size => 1) do Size := Candidate_1.Get_Required_Size; raise Try_Again; end return; exception when Try_Again => return Candidate_2 : T (Size => Size) do ... end return; Since Ada lacks proper user-defined constructors one cannot claim that Candidate_1 was not fully constructed. Even its Initialize was through. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de