https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86849
Bug ID: 86849 Summary: g++ applies guaranteed copy elision to delegating construction, resulting in miscompiles Product: gcc Version: unknown 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: --- Live testcase: https://godbolt.org/g/AKn7j7 For posterity: #include <cstring> struct A { A() {} A(int); ~A() {} int n; char k; }; A f(); A::A(int) : A(f()) {} A f() { A result; std::memset(&result, 0, sizeof(A)); return result; // (nrvo) } struct B { char x, y, z; }; struct X : A, virtual B { // B is in A's tail padding X() : B{1, 2, 3}, A(4) {} }; char test() { X x; return x.x; // should return 1 } Here, GCC uses f() to directly construct the A base class of the X object, and that tramples over A's tail padding (which contains the B virtual base class of X, which has already been initialized). It's not correct to apply guaranteed copy elision to a delegating construction, just like it's not correct to apply it to a base class construction -- not even in the C1 constructor variant, due to [[no_unique_address]].