NoumanAmir657 updated this revision to Diff 554626.
NoumanAmir657 set the repository for this revision to rG LLVM Github Monorepo.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158540/new/

https://reviews.llvm.org/D158540

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
  clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
  clang/test/CXX/drs/dr13xx.cpp
  clang/test/CXX/drs/dr14xx.cpp
  clang/test/CXX/special/class.copy/p13-0x.cpp
  clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp

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 with virtual base classes}} expected-note {{see reference to function 'W' in 'W' class}}
 };
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 with virtual base classes}} expected-note {{see reference to function 'C' in 'C' class}}
     A a;
   };
 }
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 with virtual base classes}} expected-note@-2 {{see reference to function 'B' in 'B' class}}
 #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 with virtual base classes}} expected-note@-2 {{see reference to function 'E' in 'E' class}}
 #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 with virtual base classes}} expected-note@-2 {{see reference to function 'G' in 'G' class}}
 #endif
     struct H {
       union {
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 with virtual base classes}} expected-note {{see reference to function 'B' in 'B' class}} expected-note 2{{candidate}}
+  union C { constexpr C() = default; int a, b; }; // expected-error {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note {{see reference to function 'C' in 'C' class}} 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 with virtual base classes}} expected-note {{see reference to function 'Y' in 'Y' class}} expected-note 2{{candidate}}
 
   constexpr A a = A();
   constexpr B b = B(); // expected-error {{no matching}}
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 with virtual base classes}} expected-note {{see reference to function 'S1' in 'S1' class}}
   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 with virtual base classes}} expected-note {{see reference to function 'S2' in 'S2' class}}
+  constexpr S2(S2&&) = default; // expected-error {{move constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note {{see reference to function 'S2' in 'S2' class}}
   NoCopyMove ncm;
 };
 
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 with virtual base classes}} expected-note@-2{{see reference to function 'XU1' in 'XU1' class}}
 #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 with virtual base classes}} expected-note@-2{{see reference to function 'XU3' in 'XU3' class}}
 #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 with virtual base classes}} expected-note {{see reference to function 'B' in 'B' class}}
 
   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 with virtual base classes}} expected-note {{see reference to function 'C' in 'C' class}}
 }
 
 namespace PR14503 {
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 with virtual base classes}} \
+                                               // aftercxx14-note {{see reference to function 'operator=' in 'T' class}}
 };
 
 constexpr int T::OutOfLineVirtual() const { return 0; }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -7804,6 +7804,11 @@
                                 ? 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/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 with virtual base classes">;
+def note_incorrect_defaulted_constexpr : Note<
+  "see reference to function %1 in %0 class">;
 def err_incorrect_defaulted_consteval : Error<
   "defaulted declaration of %sub{select_special_member_kind}0 "
   "cannot be consteval because implicit definition is not constexpr">;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to