DIP 1016--ref T accepts r-values--Formal Assessment

Nicholas Wilson iamthewilsonator at hotmail.com
Thu Jan 24 22:42:18 UTC 2019


On Thursday, 24 January 2019 at 21:03:29 UTC, kinke wrote:
> Describing this stuff in detail (rewritten expression?!), isn't 
> trivial and requires knowledge about how calls and 
> construction/destruction of argument expressions works.
> E.g., the f() call in the code above is lowered to (-vcg-ast):
>
> (bool __gate = false;) , ((A __pfx = a();)) , ((B __pfy = 
> b();)) , __gate = true , f(__pfx, __pfy);
>
> Here, (only seemingly unused) temporary `__gate` is used to 
> control the destruction of temporaries with dtors (here just 
> the `__pfx` arg, as `__pfy` is a special case [no potentially 
> throwing later argument expressions...]) at the caller side 
> (false => destruct; true => skip destruction, as it has been 
> moved successfully to the callee, which destructed it). The 
> dtor expressions of these temporaries (e.g., `__gate || 
> __pfx.~this()` for `__pfx`) aren't visible with `-vg-ast`.
>
> With this DIP, *all* rvalues passed by ref must be lowered to 
> temporaries. In case they require destruction, the only 
> difference wrt. the by-value case is that they are *always* 
> destructed by the caller (after the call, or if an exception is 
> thrown while they are in scope), i.e., their destruction isn't 
> controlled by `__gate`.

Exactly, doing something that could result in a different outcome 
would be a disaster.



More information about the Digitalmars-d-announce mailing list