title: Why does assigning the return value of boost::move() to a non-const reference fails in C++0x mode but works in C++03 mode
body: <p>Here is the source code that can be used to reproduce the issue:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/bind.hpp&gt;
  #include &lt;boost/move/move.hpp&gt;
  #include &lt;boost/ref.hpp&gt;
  
  std::ostream&amp; dump_to_stream(std::ostream&amp; os, int a, int b) {
    return os &lt;&lt; a &lt;&lt; '\n' &lt;&lt; b &lt;&lt; '\n';
  }
  
  template &lt;class R, class F&gt;
  R call_under_lock(F f) {
    // lock();
    R r = f();
    // unlock();
    return boost::move(r);
  }
  
  int main() {
    std::ostream&amp; os = call_under_lock&lt;std::ostream&amp;&gt;(
      boost::bind(&amp;dump_to_stream, boost::ref(std::cout), 1, 2));
  }
  </code></pre>
  
  <p>When using C++03 mode in GCC the code compiles without any problems. On the other hand the use of C++0x mode produces the following error:</p>
  
  <pre><code>$ g++ -I../../boost_latest -std=c++0x -O2 -Wall -Wextra   -c -o test.o test.cpp
  (...)
  test.cpp: In function ‘R call_under_lock(F) [with R = std::basic_ostream&lt;char&gt;&amp;, F = boost::_bi::bind_t&lt;std::basic_ostream&lt;char&gt;&amp;, std::basic_ostream&lt;char&gt;&amp; (*)(std::basic_ostream&lt;char&gt;&amp;, int, int), boost::_bi::list3&lt;boost::reference_wrapper&lt;std::basic_ostream&lt;char&gt; &gt;, boost::_bi::value&lt;int&gt;, boost::_bi::value&lt;int&gt; &gt; &gt;]’:
  test.cpp:20:62:   instantiated from here
  test.cpp:15:23: error: invalid initialization of non-const reference of type ‘std::basic_ostream&lt;char&gt;&amp;’ from an rvalue of type ‘boost::remove_reference&lt;std::basic_ostream&lt;char&gt;&amp;&gt;::type {aka std::basic_ostream&lt;char&gt;}’
  (...)
  </code></pre>
  
  <p>What is the reason of such a failure? Is there a way to workaround it in C++11 mode?</p>
  
  <p>The code presented above is a simplification of what I use in a generic code. Hence the need for such a combination (<code>boost::move</code> + non-const ref as a return value type).</p>
  
  <p>I use gcc v4.6.3, Boost 1.54.0 and Ubuntu 12.04 (i386).</p>
  
  <p>UPDATE 1: I made the test case a bit more realistic. The goal is to have a generic function that calls a functor under a lock and returns the value returned by the functor via boost::move() as the type of the return value might be movable but non-copyable (which is true in some of my invocations of <code>call_under_lock()</code>).</p>
  
  <p>UPDATE 2: It turns out that a similar problem can be observed when using <code>clang 3.5.1~(exp)</code> in C++11 mode:</p>
  
  <pre><code>$ clang test.cpp -I../../boost_latest/ -lstdc++ --std=c++11
  test.cpp:11:10: error: non-const lvalue reference to type 'basic_ostream&lt;[2 * ...]&gt;' cannot bind to a temporary of type 'basic_ostream&lt;[2 * ...]&gt;'
    return boost::move(r);
           ^~~~~~~~~~~~~~
  test.cpp:19:22: note: in instantiation of function template specialization 'call_under_lock&lt;std::basic_ostream&lt;char&gt; &amp;, boost::_bi::bind_t&lt;std::basic_ostream&lt;char&gt; &amp;, std::basic_ostream&lt;char&gt; &amp;(*)(std::basic_ostream&lt;char&gt; &amp;, int, int),
        boost::_bi::list3&lt;boost::reference_wrapper&lt;std::basic_ostream&lt;char&gt; &gt;, boost::_bi::value&lt;int&gt;, boost::_bi::value&lt;int&gt; &gt; &gt; &gt;' requested here
    std::ostream&amp; os = call_under_lock&lt;std::ostream&amp;&gt;(
  </code></pre>
  
  <p>UPDATE 3: This topic has also been discussed on boost-users mailing list [1].</p>
  
  <p>[1] <a href="http://boost.2283326.n4.nabble.com/move-differences-between-results-in-C-03-and-C-11-modes-td4659264.html" rel="nofollow">http://boost.2283326.n4.nabble.com/move-differences-between-results-in-C-03-and-C-11-modes-td4659264.html</a></p>