<p dir="ltr">On 22 Jun 2015 08:40, "Andrei Alexandrescu via Digitalmars-d" <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br>
><br>
> On 6/21/15 11:31 PM, Andrei Alexandrescu wrote:<br>
>><br>
>> On 6/21/15 10:25 PM, Walter Bright wrote:<br>
>>><br>
>>> The idea is that fun(5) would be lowered to:<br>
>>><br>
>>>     auto tmp = 5;<br>
>>>     fun(tmp);<br>
>><br>
>><br>
>> I don't think that lowering is recommended - it prolongs the lifetime of<br>
>> the temporary through the end of the caller. But that may be actually a<br>
>> good thing.<br>
><br>
><br>
> On second thought - Walter's lowering, which makes the rvalue last more than strictly necessary, may be the most flexible of all at the cost of more resource consumption (for types that define destructors). -- Andrei<br>
></p>
<p dir="ltr">I think keeping the lifetime of objects strictly in the call expression is the behaviour that will give least surprise.</p>
<p dir="ltr">int i = 42;<br>
struct S { ~this() { i++; } }</p>
<p dir="ltr">// auto __autoreftmp = S();<br>
foo(S());  // __autoreftmp<br>
// __dtor(__autoreftmp);<br>
assert(i == 43);<br></p>
<p dir="ltr">As for optimisations, I think it should be possible to assert that the reference never escapes, and use more aggressive optimisations based on that, something that is still not possible with 'scope ref' or 'in ref' parameters ... </p>
<p dir="ltr">Iain.<br>
</p>