comp.lang.ada
 help / color / mirror / Atom feed
From: Brad Moore <bmoore.ada@gmail.com>
Subject: Re: Question about finalization of local object returned from the function
Date: Wed, 28 Aug 2019 18:45:14 -0700 (PDT)
Date: 2019-08-28T18:45:14-07:00	[thread overview]
Message-ID: <a2264c91-67b6-4846-a415-e4428dcdfaa2@googlegroups.com> (raw)
In-Reply-To: <f5528641-7f77-4754-8f2a-ac5f66e53a36@googlegroups.com>

On Wednesday, August 28, 2019 at 4:36:38 PM UTC-6, darkestkhan wrote:
> Given a function returning controlled type:
> 
> function Bar return T is
>   Foo : T;
> begin
>   ...
>   return Foo;
> end Bar;
> 
> would Foo be finalized upon end of the function?
> 
> As far as I can understand from the standard - yes, Foo would get finalized. Also if Foo was just a normal record type with controlled components those components would be finalized as well.
> 
> But I am not fully confident that my understanding of this is correct...
> 
> 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 temporary 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 syntax is used, then the result object is said to be "built-in-place" directly into the result variable. The object is not finalized until the result variable is finalized. This allows a function returning a limited type to, for example, initialize a variable of a limited type.

Brad


  reply	other threads:[~2019-08-29  1:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-28 22:36 Question about finalization of local object returned from the function darkestkhan
2019-08-29  1:45 ` Brad Moore [this message]
2019-09-01 18:34   ` Stephen Leake
2019-09-01 22:12     ` darkestkhan
2019-09-02 17:14       ` Jeffrey R. Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox