title: Why give a C++ compiler warning when returning an rvalue reference?
body: <p>I've been studying rvalue references (a new concept for me), and am puzzled by a warning I receive in the following class function...</p>
  
  <pre><code>string&amp;&amp; Sampler::Serial() const {
      stringstream ss;
      .
      . [assemble a string value using data members]
      .
      return ss.str();
  }
  </code></pre>
  
  <p>This compiles successfully, but with the following warning...</p>
  
  <pre><code>..\Metrics\Sampler.cpp:71:16: warning: returning reference to temporary [-Wreturn-local-addr]
    return ss.str();
                  ^
  </code></pre>
  
  <p>I'm fully aware that I'm returning a temporary, as evidenced by the fact that I'm using an rvalue reference as my return type.  The code seems to run fine upon execution, so why should this warrant a compiler warning?</p>
  
  <p>The standard answer to <a href="https://stackoverflow.com/questions/1116641/is-returning-by-rvalue-reference-more-efficient">similar questions</a> seems to be to copy the return value instead of using a reference, but why should I copy potentially massive amounts of temporary data when I can move it with an rvalue reference?  Isn't that why it was invented?  </p>