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

            Bug ID: 71804
           Summary: Default-generated constructor does not construct base
                    class
           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 code (below) fails. 

The output of the program is:
B() -> INSERT: 0x7fff570c8b2f
~B() -> ERASE: 0x7fff570c8b2f
~B() -> ERASE: 0x7fff570c8b40
Assertion failed: (!all.empty()), function ~B, file gcc_bug.c, line 20.

Two default-generated constructors are generated for A, one has no arguments,
and another is a copy/move ctor. As you can see, the former default-generated
constructor constructs the base class B, but the latter doesn't. 

This is a refinement of a previous report, which was not presented correctly. 

*****************************************
#include <set>
#include <iostream>
#include <cstdint>
#include <cassert>
#include <experimental/optional>


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

struct B
{
    B()
    {
        std::cerr << "B() -> INSERT: " << this << "\n";
        all.insert((std::uintptr_t)this);
    }
    ~B()
    {
        std::cerr << "~B() -> ERASE: " << this << "\n";
        assert(!all.empty());                                       // FAILS
        assert(all.find((std::uintptr_t)this) != all.end());        // FAILS
        all.erase((std::uintptr_t)this);
    }
};
struct A : B {};

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

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

Reply via email to