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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a05:620a:705:: with SMTP id 5mr7322917qkc.330.1567043115273; Wed, 28 Aug 2019 18:45:15 -0700 (PDT) X-Received: by 2002:aca:5c3:: with SMTP id 186mr4610626oif.37.1567043114886; Wed, 28 Aug 2019 18:45:14 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!a13no4447594qtd.0!news-out.google.com!d29ni3353qtg.1!nntp.google.com!a13no4447583qtd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 28 Aug 2019 18:45:14 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=50.66.161.135; posting-account=lzqe5AoAAADHhp_gregSufVhvwu22fBS NNTP-Posting-Host: 50.66.161.135 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Question about finalization of local object returned from the function From: Brad Moore Injection-Date: Thu, 29 Aug 2019 01:45:15 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:57091 Date: 2019-08-28T18:45:14-07:00 List-Id: On Wednesday, August 28, 2019 at 4:36:38 PM UTC-6, darkestkhan wrote: > Given a function returning controlled type: >=20 > function Bar return T is > Foo : T; > begin > ... > return Foo; > end Bar; >=20 > would Foo be finalized upon end of the function? >=20 > As far as I can understand from the standard - yes, Foo would get finaliz= ed. Also if Foo was just a normal record type with controlled components th= ose components would be finalized as well. >=20 > But I am not fully confident that my understanding of this is correct... >=20 > Thanks, > darkestkhan Yes Foo is finalized upon end of the function, but not before copying the object to a temporary result object which is returned to the caller. The te= mporary is finalized also after being assigned to the result object. In other words, the expected result is returned to the caller, and the Foo = object on the stack is also properly finalized. Note if the object is a Limited_Controlled type, and the extended return sy= ntax is used, then the result object is said to be "built-in-place" directl= y into the result variable. The object is not finalized until the result va= riable is finalized. This allows a function returning a limited type to, fo= r example, initialize a variable of a limited type. Brad