Modify

Opened 5 years ago

Closed 5 years ago

#7114 closed Bugs (fixed)

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 (0)

Change History (1)

comment:1 Changed 5 years ago by igaztanaga

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

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

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain igaztanaga.
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.