Scope of temporaries as function arguments

Maxim Fomin maxim at maxim-fomin.ru
Fri Jun 28 09:50:05 PDT 2013


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).

> Basically, it would mean creating a "argument scope" into which 
> each arg is constructed. If something throws, then the "up to 
> now built args" are deconstruted just like with standard scope. 
> If you reach the end of the scope, then call is made, but 
> passing the resposability of destruction to foo.

This is another option but suffers from the same problem (in 
posted examples exception is always thrown, but in reality it 
need not to).



More information about the Digitalmars-d-learn mailing list