Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -9393,8 +9393,9 @@ "the parameter for an explicitly-defaulted copy assignment operator must be an " "lvalue reference type">; def err_incorrect_defaulted_constexpr : Error< - "defaulted definition of %sub{select_special_member_kind}0 " - "is not constexpr">; + "%sub{select_special_member_kind}0 cannot be 'constexpr' in a class or struct with virtual base classes">; +def note_incorrect_defaulted_constexpr: Note< + "see reference to function %1 in %0 class or struct">; def err_incorrect_defaulted_consteval : Error< "defaulted declaration of %sub{select_special_member_kind}0 " "cannot be consteval because implicit definition is not constexpr">; Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -7804,6 +7804,12 @@ ? diag::err_incorrect_defaulted_consteval : diag::err_incorrect_defaulted_constexpr) << CSM; + + if (!MD->isConsteval()) { + Diag(MD->getBeginLoc(), diag::note_incorrect_defaulted_constexpr) + << RD << MD; + } + // FIXME: Explain why the special member can't be constexpr. HadError = true; } Index: clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp =================================================================== --- clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp +++ clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp @@ -66,7 +66,8 @@ // constexpr since they can't be const. constexpr T &operator=(const T &) = default; // beforecxx14-error {{an explicitly-defaulted copy assignment operator may not have 'const', 'constexpr' or 'volatile' qualifiers}} \ // beforecxx14-warning {{C++14}} \ - // aftercxx14-error{{defaulted definition of copy assignment operator is not constexpr}} + // aftercxx14-error{{copy assignment operator cannot be 'constexpr' in a class or struct with virtual base classes}} \ + // aftercxx14-note {{see reference to function 'operator=' in 'T' class or struct}} }; constexpr int T::OutOfLineVirtual() const { return 0; } Index: clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp =================================================================== --- clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp +++ clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp @@ -272,7 +272,7 @@ union XU1 { int a; constexpr XU1() = default; }; #ifndef CXX2A -// expected-error@-2{{not constexpr}} +// expected-error@-2{{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note@-2{{see reference to function 'XU1' in 'XU1' class or struct}} #endif union XU2 { int a = 1; constexpr XU2() = default; }; @@ -282,7 +282,7 @@ }; constexpr XU3() = default; #ifndef CXX2A - // expected-error@-2{{not constexpr}} + // expected-error@-2{{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note@-2{{see reference to function 'XU3' in 'XU3' class or struct}} #endif }; struct XU4 { @@ -333,7 +333,7 @@ constexpr B(B&); }; constexpr B::B(const B&) = default; - constexpr B::B(B&) = default; // expected-error {{not constexpr}} + constexpr B::B(B&) = default; // expected-error {{copy constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'B' in 'B' class or struct}} struct C { A a; @@ -342,7 +342,7 @@ constexpr C(C&); }; constexpr C::C(const C&) = default; - constexpr C::C(C&) = default; // expected-error {{not constexpr}} + constexpr C::C(C&) = default; // expected-error {{copy constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'C' in 'C' class or struct}} } namespace PR14503 { Index: clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp =================================================================== --- clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp +++ clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp @@ -3,7 +3,7 @@ // An explicitly-defaulted function may be declared constexpr only if it would // have been implicitly declared as constexpr. struct S1 { - constexpr S1() = default; // expected-error {{defaulted definition of default constructor is not constexpr}} + constexpr S1() = default; // expected-error {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'S1' in 'S1' class or struct}} constexpr S1(const S1&) = default; constexpr S1(S1&&) = default; constexpr S1 &operator=(const S1&) const = default; // expected-error {{explicitly-defaulted copy assignment operator may not have}} @@ -18,8 +18,8 @@ }; struct S2 { constexpr S2() = default; - constexpr S2(const S2&) = default; // expected-error {{defaulted definition of copy constructor is not constexpr}} - constexpr S2(S2&&) = default; // expected-error {{defaulted definition of move constructor is not constexpr}} + constexpr S2(const S2&) = default; // expected-error {{copy constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'S2' in 'S2' class or struct}} + constexpr S2(S2&&) = default; // expected-error {{move constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'S2' in 'S2' class or struct}} NoCopyMove ncm; }; Index: clang/test/CXX/drs/dr13xx.cpp =================================================================== --- clang/test/CXX/drs/dr13xx.cpp +++ clang/test/CXX/drs/dr13xx.cpp @@ -328,10 +328,10 @@ namespace dr1359 { // dr1359: 3.5 #if __cplusplus >= 201103L union A { constexpr A() = default; }; - union B { constexpr B() = default; int a; }; // expected-error {{not constexpr}} expected-note 2{{candidate}} - union C { constexpr C() = default; int a, b; }; // expected-error {{not constexpr}} expected-note 2{{candidate}} + union B { constexpr B() = default; int a; }; // expected-error {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'B' in 'B' class or struct}} expected-note 2{{candidate}} + union C { constexpr C() = default; int a, b; }; // expected-error {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'C' in 'C' class or struct}} expected-note 2{{candidate}} struct X { constexpr X() = default; union {}; }; // expected-error {{does not declare anything}} - struct Y { constexpr Y() = default; union { int a; }; }; // expected-error {{not constexpr}} expected-note 2{{candidate}} + struct Y { constexpr Y() = default; union { int a; }; }; // expected-error {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'Y' in 'Y' class or struct}} expected-note 2{{candidate}} constexpr A a = A(); constexpr B b = B(); // expected-error {{no matching}} Index: clang/test/CXX/drs/dr14xx.cpp =================================================================== --- clang/test/CXX/drs/dr14xx.cpp +++ clang/test/CXX/drs/dr14xx.cpp @@ -129,19 +129,19 @@ union A { constexpr A() = default; }; union B { int n; constexpr B() = default; }; #if __cplusplus <= 201703L - // expected-error@-2 {{not constexpr}} + // expected-error@-2 {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note@-2 {{see reference to function 'B' in 'B' class or struct}} #endif union C { int n = 0; constexpr C() = default; }; struct D { union {}; constexpr D() = default; }; // expected-error {{does not declare anything}} struct E { union { int n; }; constexpr E() = default; }; #if __cplusplus <= 201703L - // expected-error@-2 {{not constexpr}} + // expected-error@-2 {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note@-2 {{see reference to function 'E' in 'E' class or struct}} #endif struct F { union { int n = 0; }; constexpr F() = default; }; struct G { union { int n = 0; }; union { int m; }; constexpr G() = default; }; #if __cplusplus <= 201703L - // expected-error@-2 {{not constexpr}} + // expected-error@-2 {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note@-2 {{see reference to function 'G' in 'G' class or struct}} #endif struct H { union { Index: clang/test/CXX/special/class.copy/p13-0x.cpp =================================================================== --- clang/test/CXX/special/class.copy/p13-0x.cpp +++ clang/test/CXX/special/class.copy/p13-0x.cpp @@ -125,7 +125,7 @@ mutable A a; }; struct C { - constexpr C(const C &) = default; // expected-error {{not constexpr}} + constexpr C(const C &) = default; // expected-error {{copy constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'C' in 'C' class or struct}} A a; }; } Index: clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp =================================================================== --- clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp +++ clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp @@ -54,5 +54,5 @@ struct W { int w; - constexpr W() __constant = default; // expected-error {{defaulted definition of default constructor is not constexpr}} + constexpr W() __constant = default; // expected-error {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'W' in 'W' class or struct}} };