Boost C++ Libraries: Ticket #11627: small_vector<T,n>::swap( ) appears to be broken https://svn.boost.org/trac10/ticket/11627 <p> The small_vector class seems like it could be really useful! However, it seems to have a broken implementation of the swap( ) member function. </p> <p> The first test case creates a small_vector&lt;int,10&gt; of size 2. Swapping fails to clear the vector that is swapped from. </p> <p> bredelings@transposon:~/Devel/bali-phy/master$ g++ test.C -I boost/include/ -std=c++14 bredelings@transposon:~/Devel/bali-phy/master$ ./a.out v.size() = 2 w.size() = 0 </p> <blockquote> <p> swapping v and w ... </p> </blockquote> <p> v.size() = 2 w.size() = 2 </p> <p> The second test case creates a small_vector&lt;int,10&gt; of size 11. Swapping seems to work, but apparently corrupts the heap: </p> <p> bredelings@transposon:~/Devel/bali-phy/master$ g++ test2.C -I boost/include/ -std=c++14 bredelings@transposon:~/Devel/bali-phy/master$ ./a.out v.size() = 11 w.size() = 0 </p> <blockquote> <p> swapping v and w ... </p> </blockquote> <p> v.size() = 0 w.size() = 11 <strong>* Error in `./a.out': munmap_chunk(): invalid pointer: 0x00007ffd88feb978 </strong>* Aborted </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11627 Trac 1.4.3 anonymous Tue, 08 Sep 2015 22:06:22 GMT attachment set https://svn.boost.org/trac10/ticket/11627 https://svn.boost.org/trac10/ticket/11627 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test.C</span> </li> </ul> Ticket benjamin.redelings@… Tue, 08 Sep 2015 22:06:45 GMT attachment set https://svn.boost.org/trac10/ticket/11627 https://svn.boost.org/trac10/ticket/11627 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test2.C</span> </li> </ul> <p> second test case </p> Ticket benjamin.redelings@… Tue, 08 Sep 2015 22:31:42 GMT <link>https://svn.boost.org/trac10/ticket/11627#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11627#comment:1</guid> <description> <p> It seems that when executing test2.C, the small_vector w is correctly destroyed, but v is incorrectly destroyed. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Wed, 09 Sep 2015 07:53:32 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/11627#comment:2 https://svn.boost.org/trac10/ticket/11627#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">fixed</span> </li> </ul> <p> Thanks for the report. The swap code handling the non-usual pointer swap idiom was not deleting the final elements. Also, an argument passed to test is the storage is propagable had a copy-paste error. </p> <p> Fixed in: </p> <p> <a class="ext-link" href="https://github.com/boostorg/container/commit/f1f97518d338c7f7351308aa1785ebae5f2ddde7"><span class="icon">​</span>https://github.com/boostorg/container/commit/f1f97518d338c7f7351308aa1785ebae5f2ddde7</a> </p> Ticket