this patch improves diagnostic for invalid constexpr defaulted special members by adding notes explaining why the special member cannot be constexpr.
example
input:
01 struct B {}; 02 03 struct C : virtual B { 04 }; 05 06 struct D { 07 C c; 08 }; 09 10 struct A : D { 11 constexpr A() = default; 12 }; 13 14 union U { 15 A a; 16 int b; 17 constexpr U() = default; 18 }; 19 20 struct E { 21 ~E() {} 22 }; 23 24 struct F { 25 E e; 26 constexpr F& operator=(const F&) =default; 27 };
output with patch:
test.cpp:11:3: error: defaulted definition of default constructor is not constexpr because: constexpr A() = default; ^ test.cpp:10:12: note: base class 'D' of 'A' has a non-constexpr implicit default constructor struct A : D { ^ test.cpp:7:5: note: non-static data member 'c' of 'D' has a non-constexpr implicit default constructor C c; ^ test.cpp:3:12: note: 'C' inherits virtually from 'B' struct C : virtual B { ^ test.cpp:17:3: error: defaulted definition of default constructor is not constexpr because: constexpr U() = default; ^ note: unions require exactly one non-static data member initializer to have a constexpr default constructor test.cpp:26:3: error: defaulted definition of copy assignment operator is not constexpr because: constexpr F& operator=(const F&) =default; ^ note: 'F' is not a literal type 3 errors generated.
I didn't adapt exitsing tests yet because the diagnostics emitted are likely be adapted during review.