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!au2pb.net!weretis.net!feeder6.news.weretis.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!.POSTED!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Why is the destructor called multiple times after I declare an object? Date: Wed, 13 Jan 2016 20:31:53 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <293c58ac-4ebd-488a-abcc-b6e88811eec8@googlegroups.com> <871t9ogevj.fsf@theworld.com> <87pox544ij.fsf@adaheads.sparre-andersen.dk> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls7.std.com 1452735080 28462 192.74.137.71 (14 Jan 2016 01:31:20 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 14 Jan 2016 01:31:20 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:kPiTfg789R4MBZioFKBxjbz8G+8= Xref: news.eternal-september.org comp.lang.ada:29122 Date: 2016-01-13T20:31:53-05:00 List-Id: Jacob Sparre Andersen writes: > Bob Duff writes: >> Brian Drummond writes: > >> For nonlimited types, the compiler is free to use build-in-place if it >> can prove that it's equivalent to return-by-copy. It's often not >> equivalent. For example: >> >> X := Init; >> >> What if Init raises an exception after partly modifying the result? >> In that case X should not be modified, so the result object of Init >> and X had better not be at the same address. > > But if: > > a) There is no exception handler between the assignment and leaving the > scope of X, build-in-place is okay (but impractical)? Yes, I think that's OK. I think it's also practical in some cases. You also have to worry about the case where Init can see X. X isn't supposed to (appear to be) changed until return from Init. > b) The compiler can prove that no exceptions can occur after the first > modification of the result inside Init, build-in-place is okay? Yes. But it might be hard to prove that Storage_Error won't happen, for example. - Bob