This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/71786] Constructor never called


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

--- Comment #4 from Guille <guille at cal dot berkeley.edu> ---
Hi Marc, 

Thank you for your clarification. 

I realized my initial problem arose in a slightly more complicated case
(below).

In this case a copy/move ctor of A is used, but this default-generated ctor
does not construct the base case B. Shouldn't default ctors automatically
construct base classes?

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

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

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

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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]