https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71786

            Bug ID: 71786
           Summary: Constructor never called
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: guille at cal dot berkeley.edu
  Target Milestone: ---

The following two assertions fail:

#include <set>
#include <cassert>
#include <experimental/optional>

std::set<std::uintptr_t> all;

struct A
{
    A()
    {
        all.insert((std::uintptr_t)this);
    }
    ~A()
    {
        assert(!all.empty());                                       // FAILS
        assert(all.find((std::uintptr_t)this) != all.end());        // FAILS
        all.erase((std::uintptr_t)this);
    }
};

static std::experimental::optional<A> f()
{
    A a;
    return a;
}

int main()
{
    auto a = f();
    return 0;
}

I'm using 'gcc version 7.0.0 20160605', A's constructor seems to never be
called, since the first assertion fails. 
I don't get this error when 'f' is declared 'static A f()' instead.

Reply via email to