title: When is explicit move needed for a return statement?
body: <p>In a <a href="https://stackoverflow.com/q/17473753/321013">comment to another question</a> Jonathan Wakely responds to my statement:</p>
  
  <blockquote>
    <p>You never need explicit move for a local variable function return
    value. It's implicit move there</p>
  </blockquote>
  
  <p>-></p>
  
  <blockquote>
    <p>... never say never ... You need an explicit move if the local variable
    is not the same type as the return type, e.g. <code>std::unique_ptr&lt;base&gt;
    f() { auto p = std::make_unique&lt;derived&gt;(); p-&gt;foo(); return p; }</code>, but
    if the types are the same it will move if possible ...</p>
  </blockquote>
  
  <p>So it seems sometimes we may <em>have to</em> move a local variable on return.</p>
  
  <p>The example</p>
  
  <pre><code>std::unique_ptr&lt;base&gt; f() { 
    auto p = std::make_unique&lt;derived&gt;();
    p-&gt;foo(); 
    return p; 
  }
  </code></pre>
  
  <p>is nice in that it gives a <a href="http://ideone.com/jKFClD" rel="nofollow noreferrer">compilation error</a></p>
  
  <pre><code>&gt; prog.cpp:10:14: error: cannot convert ‘p’ from type
  &gt; ‘std::unique_ptr&lt;derived&gt;’ to type ‘std::unique_ptr&lt;derived&gt;&amp;&amp;’
  </code></pre>
  
  <p>but I'm wondering whether there is a good chance to detect this in general -- and <strong>is this here a limit of the language rules or of <code>unique_ptr</code></strong>??</p>