Rvalue references - The resolution
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon May 6 10:28:54 PDT 2013
On 5/6/13 12:20 PM, Steven Schveighoffer wrote:
> On Mon, 06 May 2013 09:43:38 -0400, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>
>> 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.
>
> Focusing back on this, I think any rvalues should be treated as though
> they survive through the end of the statement. If the compiler can prove
> they are not in use after partially executing a statement, they can be
> destroyed early.
>
> Is there any reason this shouldn't be the case?
That should probably be a prerequisite of any working solution.
Andrei
More information about the Digitalmars-d
mailing list