Boost C++ Libraries: Ticket #9003: Compiler error when trying to return and assign a vector of non-copyables but movables from a function in C++03 https://svn.boost.org/trac10/ticket/9003 <p> I get a compiler error when when trying to return and assign a vector of non-copyables but movables from a function in C++03: </p> <pre class="wiki">g++ -I/home/A.Romanek/tmp/boost/boost_1_54_0 -O3 main.cpp -o main In file included from /home/A.Romanek/tmp/boost/boost_1_54_0/boost/container/allocator_traits.hpp:388:0, from /home/A.Romanek/tmp/boost/boost_1_54_0/boost/container/detail/utilities.hpp:28, from /home/A.Romanek/tmp/boost/boost_1_54_0/boost/container/vector.hpp:37, from main.cpp:1: /home/A.Romanek/tmp/boost/boost_1_54_0/boost/preprocessor/iteration/detail/local.hpp: In static member function ‘static void boost::container::allocator_traits&lt;Alloc&gt;::priv_construct_dispatch2(boost::false_type, Alloc&amp;, T*, const P0&amp;) [with T = non_copyable, P0 = non_copyable, Alloc = std::allocator&lt;non_copyable&gt;, boost::false_type = boost::integral_constant&lt;bool, false&gt;]’: /home/A.Romanek/tmp/boost/boost_1_54_0/boost/preprocessor/iteration/detail/local.hpp:37:1: instantiated from ‘static void boost::container::allocator_traits&lt;Alloc&gt;::priv_construct(boost::true_type, Alloc&amp;, T*, const P0&amp;) [with T = non_copyable, P0 = non_copyable, Alloc = std::allocator&lt;non_copyable&gt;, boost::true_type = boost::integral_constant&lt;bool, true&gt;]’ /home/A.Romanek/tmp/boost/boost_1_54_0/boost/preprocessor/iteration/detail/local.hpp:37:1: instantiated from ‘static void boost::container::allocator_traits&lt;Alloc&gt;::construct(Alloc&amp;, T*, const P0&amp;) [with T = non_copyable, P0 = non_copyable, Alloc = std::allocator&lt;non_copyable&gt;]’ /home/A.Romanek/tmp/boost/boost_1_54_0/boost/container/detail/utilities.hpp:555:10: instantiated from ‘typename boost::container::container_detail::disable_if_memcpy_copy_constructible&lt;I, F, F&gt;::type boost::container::uninitialized_copy_alloc_n(A&amp;, I, typename std::iterator_traits&lt;_II&gt;::difference_type, F) [with A = std::allocator&lt;non_copyable&gt;, I = non_copyable*, F = non_copyable*, typename boost::container::container_detail::disable_if_memcpy_copy_constructible&lt;I, F, F&gt;::type = non_copyable*, typename std::iterator_traits&lt;_II&gt;::difference_type = int]’ /home/A.Romanek/tmp/boost/boost_1_54_0/boost/container/vector.hpp:734:7: instantiated from ‘boost::container::vector&lt;T, Allocator&gt;::vector(const boost::container::vector&lt;T, Allocator&gt;&amp;) [with T = non_copyable, Allocator = std::allocator&lt;non_copyable&gt;, boost::container::vector&lt;T, Allocator&gt; = boost::container::vector&lt;non_copyable&gt;]’ main.cpp:14:49: instantiated from here /home/A.Romanek/tmp/boost/boost_1_54_0/boost/preprocessor/iteration/detail/local.hpp:37:1: error: passing ‘const non_copyable’ as ‘this’ argument of ‘non_copyable::operator boost::rv&lt;non_copyable&gt;&amp;()’ discards qualifiers [-fpermissive] </pre><p> The problem was discussed on Boost-users list: <a class="ext-link" href="http://lists.boost.org/boost-users/2013/08/79697.php"><span class="icon">​</span>http://lists.boost.org/boost-users/2013/08/79697.php</a> </p> <p> See the attachment for a code example. </p> <p> The problem can be reproduced on gcc 4.6.3. </p> <p> NOTE: using -std=c++0x makes the code example compile without any problems. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9003 Trac 1.4.3 Adam Romanek <romanek.adam@…> Fri, 16 Aug 2013 09:09:20 GMT attachment set https://svn.boost.org/trac10/ticket/9003 https://svn.boost.org/trac10/ticket/9003 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test.cpp</span> </li> </ul> Ticket Adam Romanek <romanek.adam@…> Fri, 16 Aug 2013 09:09:57 GMT component changed; owner set https://svn.boost.org/trac10/ticket/9003#comment:1 https://svn.boost.org/trac10/ticket/9003#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Ion Gaztañaga</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">container</span> </li> </ul> Ticket Ion Gaztañaga Thu, 11 Aug 2016 09:44:19 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9003#comment:2 https://svn.boost.org/trac10/ticket/9003#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> Reviewing old bugs sorry for the huge delay. Replying to document the existing workaround to future bug readers. The problem is related to move emulation as explained in: </p> <p> <a href="http://www.boost.org/doc/libs/1_61_0/doc/html/move/move_return.html">http://www.boost.org/doc/libs/1_61_0/doc/html/move/move_return.html</a> </p> <p> Changing the generation function to: </p> <pre class="wiki"> nc_vector create() { nc_vector nc_temp; return BOOST_MOVE_RET(nc_vector, nc_temp); } </pre><p> workarounds the problem. </p> Ticket