Boost C++ Libraries: Ticket #7114: Destructor not called when using emplace() https://svn.boost.org/trac10/ticket/7114 <p> Consider the following source code: </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;set&gt; #include &lt;boost/container/flat_set.hpp&gt; struct foo { int i_; foo(int i) : i_(i) { std::cout &lt;&lt; "foo() " &lt;&lt; this &lt;&lt; std::endl; } ~foo() { std::cout &lt;&lt; "~foo() " &lt;&lt; this &lt;&lt; std::endl; } foo(foo&amp;&amp; other) : i_(other.i_) { std::cout &lt;&lt; "foo(foo&amp;&amp;) " &lt;&lt; this &lt;&lt; std::endl; } foo&amp; operator=(foo&amp;&amp; other) { std::cout &lt;&lt; "foo&amp; operator=(foo&amp;&amp;)" &lt;&lt; this &lt;&lt; std::endl; i_ = other.i_; return *this; } bool operator==(const foo&amp; other) const { return i_ == other.i_; } bool operator&lt;(const foo&amp; other) const { return i_ &lt; other.i_; } }; int main() { boost::container::flat_set&lt;foo&gt; set; // std::set&lt;foo&gt; set; std::cout &lt;&lt; "*************" &lt;&lt; std::endl; set.emplace(42); std::cout &lt;&lt; "*************" &lt;&lt; std::endl; set.emplace(42); std::cout &lt;&lt; "*************" &lt;&lt; std::endl; return 0; } </pre><p> When compiled with clang 3.1 or gcc 4.8 and launched, it displays: </p> <pre class="wiki">************* foo() 0x7fff6bfb29f8 foo(foo&amp;&amp;) 0x10c400900 ************* foo() 0x7fff6bfb29f8 ************* ~foo() 0x10c400900 </pre><p> Three instances are created (two constructors and one move-contructor), but only one destructor is called. As a side note, when using an <code>std::set</code> (of the libc++) instead of a <code>boost::container::flat_set</code>, it displays: </p> <pre class="wiki">************* foo() 0x10490091c ************* foo() 0x10490093c ~foo() 0x10490093c ************* ~foo() 0x10490091c </pre><p> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7114 Trac 1.4.3 Ion Gaztañaga Wed, 11 Jul 2012 17:35:29 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/7114#comment:1 https://svn.boost.org/trac10/ticket/7114#comment:1 <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, fixed in trunk at revision: 79422 </p> Ticket