<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Feb 18, 2015 at 6:36 PM, Richard Trieu <span dir="ltr"><<a href="mailto:rtrieu@google.com" target="_blank">rtrieu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">So then something like this:<br>
<br>
  struct S{};<br>
  S test(bool cond) {<br>
    S s1, s2;<br>
    if (cond)<br>
      return std::move(s1);<br>
    return std::move(s2);<br>
  }<br>
<br>
would be better with the std::move's removed:<br>
<br>
  struct S{};<br>
  S test(bool cond) {<br>
    S s1, s2;<br>
    if (cond)<br>
      return s1;<br>
    return s2;<br>
  }<br>
<br>
even though NRVO would not be triggered since different local variables are used?</blockquote><div><br></div><div>Yes, even though *our implementation of* NRVO would not be triggered :-) A sufficiently smart compiler could notice that S's default constructor is trivial and rewrite the above to:</div><div><br></div><div>  S test(bool cond) {</div><div>    if (cond) {</div><div>      S s1;<br>      return s1;</div><div>    }</div><div>    S s2;<br>    return s2;<br>  }<br></div><div><br></div><div>That same sufficiently smart compiler could then perform NRVO for both variables and return statements (in fact, Clang can and should perform NRVO for the above case, but our NRVO is really dumb today.) The produced warnings shouldn't depend on how smart our NRVO happens to be.</div><div><br></div><div>Putting this into the initialization code (in SemaInit) also lets us catch other cases with largely the same codepaths, such as:</div><div><br></div><div>X f();</div><div>X x = std::move(f()); // another form of pessimizing move, disables copy-elision</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5">
<a href="http://reviews.llvm.org/D7633" target="_blank">http://reviews.llvm.org/D7633</a><br>
<br>
EMAIL PREFERENCES<br>
  <a href="http://reviews.llvm.org/settings/panel/emailpreferences/" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>
<br>
<br>
</div></div></blockquote></div><br></div></div>