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=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,57f8540942f8e060 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!x10g2000prk.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Initialization and Finalization of limited object "returned" by a function Date: Thu, 11 Feb 2010 13:51:04 -0800 (PST) Organization: http://groups.google.com Message-ID: <75a9f860-ad3c-49a0-b2a1-a8f1386e6ff6@x10g2000prk.googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1265925064 28257 127.0.0.1 (11 Feb 2010 21:51:04 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 11 Feb 2010 21:51:04 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: x10g2000prk.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:9117 Date: 2010-02-11T13:51:04-08:00 List-Id: On Feb 11, 11:10=A0am, Robert A Duff wrote: > Adam Beneschan writes: > > But more simply, as I understand it: (1) When you have an extended > > return, the return object is used as the anonymous object that holds > > the function result at the point of the function call, so it's not > > finalized until the caller is done with the anonymous object; and (2) > > when the object is built in place, the anonymous object "mutates into" > > the new object and is not finalized (7.6(17.7/3)). =A0So yes, no > > finalization should be done until X goes out of scope. > > Just to be clear: There's nothing particularly special about > extended return statements, other than the fact that they > provide a name for the result. =A0 That last is an important distinction, however. A function call involves (conceptually) an anonymous object. For a normal return (for a non-limited type): return Some_Expression; Some_Expression is computed and then assigned into the anonymous object. This assignment involves an Adjust. Then, at some point, whatever objects went into creating Some_Expression will get finalized when the function exits. If Some_Expression is a local variable, for instance, that variable will get finalized. If some other temporary needs to be created in order to hold the value of Some_Expression, that temporary will be finalized. For an extended return, return R : T; R is not a local variable, and it isn't "assigned" into the anonymous object; thus, there's no Adjust, and R is not finalized when the function returns (but the anonymous object will be finalized later, except when it mutates into some other object). I think that's the point of the nasty language in 3.10.2(10.1). Which is another way of saying that R is a name for the result (as you said), not a distinct object that gets copied to the result. I thought it would be helpful to point it out---not to you, but to other readers. It's hardly a trivial difference, and it's an important one to understand when adjusts and finalizations are involved. Anyway, I hope this helps someone. -- Adam