Rvalue references - The resolution

deadalnix deadalnix at gmail.com
Mon May 6 08:34:40 PDT 2013


On Monday, 6 May 2013 at 13:43:38 UTC, Andrei Alexandrescu wrote:
> I think we can technically make the overloading work while also 
> allowing binding rvalues to ref. But that wouldn't help any. 
> Consider:
>
> ref int min(ref int a, ref int b) { return b < a ? b : a; }
> ...
> int x;
> fun(min(x, 100));
>
> Here the result of min may be bound to an lvalue or an rvalue 
> depending on a condition. In the latter case, combined with D's 
> propensity to destroy temporaries too early (immediately after 
> function calls), the behavior is silently undefined; the code 
> may pass unittests.
>

Now that you mention that, is the proposal for ref safety is 
really safe ?


More information about the Digitalmars-d mailing list