Modify

Ticket #7114 (closed Bugs: fixed)

Opened 22 months ago

Last modified 22 months ago

Destructor not called when using emplace()

Reported by: Alexandre Hamez <alexandre.hamez@…> Owned by: igaztanaga
Milestone: To Be Determined Component: container
Version: Boost 1.50.0 Severity: Problem
Keywords: Cc:

Description

Consider the following source code:

#include <iostream>
#include <set>

#include <boost/container/flat_set.hpp>

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<foo> set;
  // std::set<foo> 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

Attachments

Change History

comment:1 Changed 22 months ago by igaztanaga

  • Status changed from new to closed
  • Resolution set to fixed

Thanks for the report, fixed in trunk at revision: 79422

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.