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: Thu, 14 Jan 2016 10:47:11 +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: 8bit 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:29124 Date: 2016-01-14T10:47:11+01:00 List-Id: On 14/01/2016 10:04, J-P. Rosen wrote: > Le 13/01/2016 21:09, Dmitry A. Kazakov a écrit : >>> OK, let's state it differently. The called function builds its result >>> "somewhere". That "somewhere" is what will be used by the caller as the >>> variable being initialized. >> >> A non-limited result is built "somewhere", just the same. I think >> in-place must be a definite place, not just "somewhere". > In the non-limited case, copying is allowed (although not required), so > there is no issue. What I mean is that it can work the other way round > from your mental model: you think of the caller allocating the result > space, and the function using that space; but it can be the function > that choses where to build the result, and then the caller using that > space for the object. It may not be the usual stack model, but that's > irrelevant (we already know that a secondary stack may be used in some > cases). For many (most, actually) important cases this is relevant, e.g. for an initialized limited component of a container object or a parent of. There is no way to do this without exposing all innards and even with exposing them chances are very high it won't work anyway. >>> It is perfectly OK if the function starts building the result in >>> "somewhere_1", then decides to switch to "somewhere_2", as long as the >>> eventual "somewhere" is what is used by the caller, /without copy/. >> >> "Without copy" requires a definition too. IMO, it must mean that no type >> operations are called otherwise than on the final result (function >> arguments do not count). For example, Initialize must be called strictly >> once. > "Without copy" means that the value constructed and returned by the > function should not be moved to a different memory location. > What else? You mean "object constructed" (the object refers to a value). I think that "copy" should be stated in terms of operations defined on the object. If the client cannot tell difference through legal operation then it is OK. Therefore the requirement that Initialize and other elaboration stuff must be performed once. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de