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

            Bug ID: 106150
           Summary: Incorrect error for defaulted anonymous union member
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jens.maurer at gmx dot net
  Target Milestone: ---

The following is valid, but yields an error with gcc 12.1:

struct A {
   A() { }
};

struct V {
   V() { };
   ~V() { }
};


struct S {
   S();
   ~S() {}

   union {
     A a = {};
     V v;
   };
};

S::S() = default;


x.cc:22:1: note: ‘S::S()’ is implicitly deleted because the default definition
would be ill-formed:
   22 | S::S() = default;
      | ^
x.cc:18:8: error: union member ‘S::<unnamed union>::v’ with non-trivial
‘V::V()’
   18 |      V v;
      |        ^


Replacing "= default" with "{}" makes the error go away.

None of the items in [class.default.ctor] p2 applies, in particular p2.2 does
not apply because S::a has a default member initializer.

Reply via email to