https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98423
Bug ID: 98423 Summary: The defaulted default constructor defined as deleted when one of variant member has a default member initializer Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: xmh970252187 at gmail dot com Target Milestone: --- struct A{ A(){} }; union C{ A a; int b = 0; }; int main(){ C c; } GCC reports the default constructor for union `C` is defined as deleted. However, the relevant rule in the current c++ standard says that: > A defaulted default constructor for class X is defined as deleted if: >> X is a union that has a variant member with a non-trivial default >> constructor and no variant member of X has a default member initializer, >> X is a non-union class that has a variant member M with a non-trivial >> default constructor and no variant member of the anonymous union containing >> M has a default member initializer In simple, as long as one of these variant members has a default member initializer, then the default constructor for the containing class will not be defined as deleted. In this example, the variant member `b` has a default member initializer, hence `C::C()` should be defined rather than deleted. Is it a bug? GCC only agrees this code is supported: struct A{ A(){} }; union C{ A a{}; int b; }; int main(){ C c; } If it is the right behavior, then the relevant rule should be described as: > X is a union that has a variant member with a non-trivial default constructor > and no default member initializer is supplied for the variant member. However, the rule does not say this.