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!.POSTED!not-for-mail From: Bob Duff Newsgroups: comp.lang.ada Subject: Re: Why is the destructor called multiple times after I declare an object? Date: Mon, 11 Jan 2016 13:17:20 -0500 Organization: A noiseless patient Spider Message-ID: <871t9ogevj.fsf@theworld.com> References: <293c58ac-4ebd-488a-abcc-b6e88811eec8@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="10ea5687c17524528376e0d1ea632981"; logging-data="23346"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19z6btk4k8tIu2ydYZIyIuD" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:WpI3vIyyiOQl43WLB0xD+BXf024= sha1:6IF3vspno2mkZvcVHqVDoOoHsDM= Xref: news.eternal-september.org comp.lang.ada:29091 Date: 2016-01-11T13:17:20-05:00 List-Id: 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. 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. - Bob