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

            Bug ID: 96876
           Summary: missing check for destructibility of base classes in
                    aggregate initialization
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: richard-gccbugzilla at metafoo dot co.uk
  Target Milestone: ---

GCC accepts this invalid code (which is ill-formed because [dcl.init.aggr]/8
says it potentially-invokes the destructor for B, which [class.dtor]/15 says
requires the destructor to be accessible):

struct B {
protected:
    ~B() {}
};

struct C : B { int n; };

int f();

void g() {
    C c{{}, f()};
}

... and generates wrong code for this similar example:

#include <stdio.h>

struct B {
public:
    ~B() { puts("destroyed"); }
};

struct C : B { int n; };

int f() { throw "hello"; }

int main() {
    try {
    C c{{}, f()};
    } catch (const char*) {
    }
}

... which is required to print "destroyed" (when the B base class subobject is
destroyed during stack unwinding), but with GCC does not.

Reply via email to