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

            Bug ID: 70431
           Summary: [C++11] Out of line defaulted copy constructor of a
                    union does not compile.
           Product: gcc
           Version: 5.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vmpstr at chromium dot org
  Target Milestone: ---

Given:

union Foo {
  Foo() = default;
  Foo(const Foo& other);

  int a;
  float b;
};

Foo::Foo(const Foo& other) = default;

I get the following compilation error:

$ g++ -std=c++11 -c foo.cpp
foo.cpp: In copy constructor ‘Foo::Foo(const Foo&)’:
foo.cpp:1:7: error: initializations for multiple members of ‘Foo’
 union Foo {
       ^
foo.cpp: At global scope:
foo.cpp:9:30: note: synthesized method ‘Foo::Foo(const Foo&)’ first required
here 
 Foo::Foo(const Foo& other) = default;
                              ^

$ g++ --version
g++ (GCC) 5.3.0

The expected behavior is that this would compile. Note that if the constructor
is inline, then it compiles as expected.

Reply via email to