id summary reporter owner description type status milestone component version severity resolution keywords cc 7114 Destructor not called when using emplace() Alexandre Hamez Ion Gaztañaga "Consider the following source code: {{{ #include #include #include struct foo { int i_; foo(int i) : i_(i) { std::cout << ""foo() "" << this << std::endl; } ~foo() { std::cout << ""~foo() "" << this << std::endl; } foo(foo&& other) : i_(other.i_) { std::cout << ""foo(foo&&) "" << this << std::endl; } foo& operator=(foo&& other) { std::cout << ""foo& operator=(foo&&)"" << this << std::endl; i_ = other.i_; return *this; } bool operator==(const foo& other) const { return i_ == other.i_; } bool operator<(const foo& other) const { return i_ < other.i_; } }; int main() { boost::container::flat_set set; // std::set set; std::cout << ""*************"" << std::endl; set.emplace(42); std::cout << ""*************"" << std::endl; set.emplace(42); std::cout << ""*************"" << std::endl; return 0; } }}} When compiled with clang 3.1 or gcc 4.8 and launched, it displays: {{{ ************* foo() 0x7fff6bfb29f8 foo(foo&&) 0x10c400900 ************* foo() 0x7fff6bfb29f8 ************* ~foo() 0x10c400900 }}} Three instances are created (two constructors and one move-contructor), but only one destructor is called. As a side note, when using an {{{std::set}}} (of the libc++) instead of a {{{boost::container::flat_set}}}, it displays: {{{ ************* foo() 0x10490091c ************* foo() 0x10490093c ~foo() 0x10490093c ************* ~foo() 0x10490091c }}} " Bugs closed To Be Determined container Boost 1.50.0 Problem fixed