[Bug c++/96876] New: missing check for destructibility of base classes in aggregate initialization
richard-gccbugzilla at metafoo dot co.uk
gcc-bugzilla@gcc.gnu.org
Mon Aug 31 20:53:08 GMT 2020
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.
More information about the Gcc-bugs
mailing list