Boost C++ Libraries: Ticket #13420: small_vector - invalid move constructor/move assignment for size < N https://svn.boost.org/trac10/ticket/13420 <p> When <strong>small_vector</strong> is move-constructed or move-assigned from another <strong>small_vector</strong>, the initial one has elements moved out, but vector size is left unchanged. This only happens if internal vector memory is used (vector size is less than in-place capacity N) </p> <pre class="wiki">small_vector&lt;int, 5&gt; a = {1,2,3}; small_vector&lt;int, 5&gt; b = std::move(a); // after the assignment, a.size() is 3 </pre><p> Detailed example is <a class="ext-link" href="https://wandbox.org/permlink/j8fRFEpWcj9Iaz6x"><span class="icon">​</span>here</a>. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13420 Trac 1.4.3 anonymous Thu, 25 Jan 2018 05:00:32 GMT version changed https://svn.boost.org/trac10/ticket/13420#comment:1 https://svn.boost.org/trac10/ticket/13420#comment:1 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.65.0</span> → <span class="trac-field-new">Boost 1.66.0</span> </li> </ul> Ticket Ion Gaztañaga Sat, 27 Jan 2018 21:23:16 GMT <link>https://svn.boost.org/trac10/ticket/13420#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13420#comment:2</guid> <description> <p> There is not requirement that a move constructor or assignment must empty the source. Source must be in a consistent but unspecified state. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antervis</dc:creator> <pubDate>Sat, 27 Jan 2018 22:42:04 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13420#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13420#comment:3</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/13420#comment:2" title="Comment 2">Ion Gaztañaga</a>: </p> <blockquote class="citation"> <p> There is not requirement that a move constructor or assignment must empty the source. Source must be in a consistent but unspecified state. </p> </blockquote> <p> even though current behavior is standard-conforming, it is certainly inconsistent both with standard containers (which are empty after being moved out) and with itself (moved out state depends on initial state). I personally don't see a reason for this behavior to be an intended design choice and I suggest it to be changed </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Sun, 28 Jan 2018 21:45:37 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/13420#comment:4 https://svn.boost.org/trac10/ticket/13420#comment:4 <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">invalid</span> </li> </ul> <p> I've reviewed some STL implementations, specifically operator=(vector&amp;&amp;source), the case when the allocator shall not be propagated allocator_traits::propagate_on_container_move_assignment or allocators don't compare equal. In those cases memory can't be stolen from the source container and elements are move constructed from source to destination. </p> <ul><li>libstdc++ clears the source vector </li><li>libc++ and msvc don't clear the source vector (size is unchanged) </li></ul><p> The standard says for operator=(vector&amp;&amp;) (the move constructor always transfers the allocator and does not support different storage types for source and destination like small_vector) that *this shall have the same value "source" had but no guarantee about the state of "source". </p> <p> So I'm reluctant to change the implementation to clear the source. If many users find this annoying then we will reopen the issue. Thanks for the report. </p> Ticket