Scope of temporaries as function arguments

monarch_dodra monarchdodra at gmail.com
Fri Jun 28 09:57:28 PDT 2013


On Friday, 28 June 2013 at 16:50:07 UTC, Maxim Fomin wrote:
> On Friday, 28 June 2013 at 16:01:05 UTC, monarch_dodra wrote:
>>
>> I thought that was where you were getting to. Couldn't this 
>> simply be solved by having the *caller*, destroy the object 
>> that was postblitted into foo? Since foo ends up not being 
>> called (because of the exception), then I see no problem 
>> having the caller destroy the "to-be-passed-but-ends-up-not" 
>> object?
>
> In case when there is no exception, struct argument is passed 
> and is modified in callee, destructor in caller would have 
> unchanged version (because structs are passed by value).

I'm saying the "callee" destroys whatever is passed to it, all 
the time, but that means "callee" needs to actually be called.

If "caller" constructs objects, but then fails to actually call 
"callee", then caller *has* to be responsible for destroying the 
objects it has built, but not passed to anyone. But this is only 
if an exception is thrown:

No exception:
   Caller constructs objects into foo.
   foo is called, foo becomes owner of objects.
   foo finishes.
   foo destroys object.

Exception:
   Caller starts construction.
   Exception is thrown.
   Caller destroys objects as exception is propagating.
   All objects are destroyed, exception goes up.




More information about the Digitalmars-d-learn mailing list