<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 20 October 2016 at 20:16, Ethan Watson via Digitalmars-d <span dir="ltr"><<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Wednesday, 19 October 2016 at 21:19:03 UTC, Atila Neves wrote:<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
On Wednesday, 19 October 2016 at 15:58:23 UTC, Chris Wright wrote:<br>
</span><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
So it seems like the compiler could take care of this by only providing lvalue references but automatically creating those temporary variables for me. It's going to create an extra copy that might not be needed if there were a special rvalue reference type modifier, but why should I care? It's exactly as efficient as the code the compiler forces me to write.<br>
<br>
This is what Ethan Watson has suggested, too.<br>
</blockquote>
<br>
Interesting. Also, I must have missed that suggestion.<br>
</span></blockquote>
<br>
It actually went a bit further than my suggestion, if I'm reading the summary correctly.<br>
<br>
For example, right now we go:<br>
<br>
Vector3 vSomeTempName = v1 + v2;<br>
someVectorFunc( vSomeTempName );<br>
<br>
This will keep the vSomeTempName entirely in scope and living on the stack for as long as that code block is active. A simplification step would be to store rvalues on the stack without needing to name them, and only destroying them once the block's scope goes out of scope.<br>
<br>
It still provides an easy escape from a C++ function though. For example:<br>
<br>
D code:<br>
<br>
return someVectorFunc( v1 + v2 );<br>
<br>
C++ code:<br>
<br>
const Vector3& someVectorFunc( const Vector3& someVector )<br>
{<br>
  return someVector;<br>
}<br>
<br>
You'd still want to insert some sanity checking code in the code gen to throw an exception if the C++ function is returning a reference to the current stack and your D function is also returning by reference.<br>
</blockquote></div><br></div><div class="gmail_extra">DIP25 introduced return ref to address this issue. Just annotate it correctly?</div></div>