[clang] [clang][NFC] Refactor expected directives in C++ DRs 1-99 (PR #73879)

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 29 16:27:49 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)

<details>
<summary>Changes</summary>

This patch converts (almost) every expected directive in `test/CXX/drs/dr0xx.cpp` into either `@-1` form (when directive immediately follow the line diagnostic is pointing out to), or `@#<marker>` form (when directive is placed away from the line diagnostic is pointing out to). It also converts directive to match exactly one diagnostic, as opposed to matching multiple. Error messages are expanded to exactly match compiler output. `#if __cplusplus` guarding directives are replaced with respective prefixes (e.g. `since-cxx17`).

All aforementioned changes serve a purpose of making it easier to reconstruct expected compiler output, which should also make it a bit easier to grasp the gist of those already non-trivial tests due to their nature of testing corner cases of the language.

---

Patch is 58.25 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/73879.diff


1 Files Affected:

- (modified) clang/test/CXX/drs/dr0xx.cpp (+496-290) 


``````````diff
diff --git a/clang/test/CXX/drs/dr0xx.cpp b/clang/test/CXX/drs/dr0xx.cpp
index 1210c7a834e5970..e79ce6daf2655c5 100644
--- a/clang/test/CXX/drs/dr0xx.cpp
+++ b/clang/test/CXX/drs/dr0xx.cpp
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -Wno-bind-to-temporary-copy
-// RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
-// RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
-// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
-// RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
-// RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
+// RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98,cxx98-14 -fexceptions -fcxx-exceptions -pedantic-errors -Wno-bind-to-temporary-copy
+// RUN: %clang_cc1 -std=c++11 %s -verify=expected,since-cxx11,cxx98-14,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
+// RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx11,cxx98-14,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
+// RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
+// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
+// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
 
 namespace dr1 { // dr1: no
   namespace X { extern "C" void dr1_f(int a = 1); }
@@ -26,9 +26,11 @@ namespace dr1 { // dr1: no
   namespace X {
     void z(int);
   }
-  void X::z(int = 1) {} // expected-note {{previous}}
+  void X::z(int = 1) {} // #dr1-z
   namespace X {
-    void z(int = 1); // expected-error {{redefinition of default argument}}
+    void z(int = 1);
+    // expected-error at -1 {{redefinition of default argument}}
+    // expected-note@#dr1-z {{previous definition is here}}
   }
 
   void i(int = 1);
@@ -50,17 +52,21 @@ namespace dr1 { // dr1: no
 
 namespace dr3 { // dr3: yes
   template<typename T> struct A {};
-  template<typename T> void f(T) { A<T> a; } // expected-note {{implicit instantiation}}
+  template<typename T> void f(T) { A<T> a; } // #dr3-f-T
   template void f(int);
-  template<> struct A<int> {}; // expected-error {{explicit specialization of 'dr3::A<int>' after instantiation}}
+  template<> struct A<int> {};
+  // expected-error at -1 {{explicit specialization of 'dr3::A<int>' after instantiation}}
+  // expected-note@#dr3-f-T {{implicit instantiation first required here}}
 }
 
 namespace dr4 { // dr4: yes
   extern "C" {
     static void dr4_f(int) {}
     static void dr4_f(float) {}
-    void dr4_g(int) {} // expected-note {{previous}}
-    void dr4_g(float) {} // expected-error {{conflicting types}}
+    void dr4_g(int) {} // #dr4-g-int
+    void dr4_g(float) {}
+    // expected-error at -1 {{conflicting types for 'dr4_g'}}
+    // expected-note@#dr4-g-int {{previous definition is here}}
   }
 }
 
@@ -80,14 +86,21 @@ namespace dr5 { // dr5: 3.1
 
 namespace dr7 { // dr7: 3.4
   class A { public: ~A(); };
-  class B : virtual private A {}; // expected-note 2 {{declared private here}}
-  class C : public B {} c; // expected-error 2 {{inherited virtual base class 'A' has private destructor}} \
-                           // expected-note {{implicit default constructor for 'dr7::C' first required here}} \
-                           // expected-note {{implicit destructor for 'dr7::C' first required here}}
+  class B : virtual private A {}; // #dr7-B
+  class C : public B {} c; // #dr7-C
+  // expected-error@#dr7-C {{inherited virtual base class 'A' has private destructor}}
+  // expected-note@#dr7-C {{in implicit default constructor for 'dr7::C' first required here}}
+  // expected-note@#dr7-B {{declared private here}}
+
+  // expected-error@#dr7-C {{inherited virtual base class 'A' has private destructor}}
+  // expected-note@#dr7-C {{in implicit destructor for 'dr7::C' first required here}}
+  // expected-note@#dr7-B {{declared private here}}
   class VeryDerivedC : public B, virtual public A {} vdc;
 
-  class X { ~X(); }; // expected-note {{here}}
-  class Y : X { ~Y() {} }; // expected-error {{private destructor}}
+  class X { ~X(); }; // #dr7-X
+  class Y : X { ~Y() {} };
+  // expected-error at -1 {{base class 'X' has private destructor}}
+  // expected-note@#dr7-X {{implicitly declared private here}}
 
   namespace PR16370 { // This regressed the first time DR7 was fixed.
     struct S1 { virtual ~S1(); };
@@ -117,13 +130,16 @@ namespace dr8 { // dr8: dup 45
 namespace dr9 { // dr9: 2.8
   struct B {
   protected:
-    int m; // expected-note {{here}}
+    int m; // #dr9-m
     friend int R1();
   };
-  struct N : protected B { // expected-note {{protected}}
+  struct N : protected B { // #dr9-N
     friend int R2();
   } n;
-  int R1() { return n.m; } // expected-error {{protected member}}
+  int R1() { return n.m; }
+  // expected-error at -1 {{'m' is a protected member of 'dr9::B'}}
+  // expected-note@#dr9-N {{constrained by protected inheritance here}}
+  // expected-note@#dr9-m {{member is declared here}}
   int R2() { return n.m; }
 }
 
@@ -142,7 +158,8 @@ namespace dr11 { // dr11: yes
   };
   template<typename T> struct B : T {
     using T::V;
-    V v; // expected-error {{unknown type name}}
+    V v;
+    // expected-error at -1 {{unknown type name 'V'}}
   };
   struct X { typedef int U; };
   A<X> ax;
@@ -190,27 +207,41 @@ namespace dr14 { // dr14: 3.4
     extern "C" int dr14_f() { return c.k; }
   }
 
-  namespace X { typedef int T; typedef int U; } // expected-note {{candidate}}
-  namespace Y { typedef int T; typedef long U; } // expected-note {{candidate}}
+  namespace X { typedef int T; typedef int U; } // #dr14-X-U
+  namespace Y { typedef int T; typedef long U; } // #dr14-Y-U
   T t; // ok, same type both times
-  U u; // expected-error {{ambiguous}}
+  U u;
+  // expected-error at -1 {{reference to 'U' is ambiguous}}
+  // expected-note@#dr14-X-U {{candidate found by name lookup is 'dr14::X::U'}}
+  // expected-note@#dr14-Y-U {{candidate found by name lookup is 'dr14::Y::U'}}
 }
 
 namespace dr15 { // dr15: yes
-  template<typename T> void f(int); // expected-note {{previous}}
-  template<typename T> void f(int = 0); // expected-error {{default arguments cannot be added}}
+  template<typename T> void f(int); // #dr15-f-decl-first
+  template<typename T> void f(int = 0);
+  // expected-error at -1 {{default arguments cannot be added to a function template that has already been declared}}
+  // expected-note@#dr15-f-decl-first {{previous template declaration is here}}
 }
 
 namespace dr16 { // dr16: 2.8
-  class A { // expected-note {{here}}
-    void f(); // expected-note {{here}}
+  class A { // #dr16-A
+    void f(); // #dr16-A-f-decl
     friend class C;
   };
-  class B : A {}; // expected-note 3{{here}}
+  class B : A {}; // #dr16-B
   class C : B {
     void g() {
-      f(); // expected-error {{private member}}
-      A::f(); // expected-error {{private member}} expected-error {{private base}}
+      f();
+      // expected-error at -1 {{'f' is a private member of 'dr16::A'}}
+      // expected-note@#dr16-B {{constrained by implicitly private inheritance here}}
+      // expected-note@#dr16-A-f-decl {{member is declared here}}
+      A::f(); // #dr16-A-f-call
+      // expected-error@#dr16-A-f-call {{'A' is a private member of 'dr16::A'}}
+      // expected-note@#dr16-B {{constrained by implicitly private inheritance here}}
+      // expected-note@#dr16-A {{member is declared here}}
+
+      // expected-error@#dr16-A-f-call {{cannot cast 'dr16::C' to its private base class 'dr16::A'}}
+      // expected-note@#dr16-B {{implicitly declared private here}}
     }
   };
 }
@@ -232,13 +263,16 @@ namespace dr17 { // dr17: yes
 
 namespace dr19 { // dr19: 3.1
   struct A {
-    int n; // expected-note {{here}}
+    int n; // #dr19-n
   };
-  struct B : protected A { // expected-note {{here}}
+  struct B : protected A { // #dr19-B
   };
   struct C : B {} c;
   struct D : B {
-    int get1() { return c.n; } // expected-error {{protected member}}
+    int get1() { return c.n; }
+    // expected-error at -1 {{'n' is a protected member of 'dr19::A'}}
+    // expected-note@#dr19-B {{constrained by protected inheritance here}}
+    // expected-note@#dr19-n {{member is declared here}}
     int get2() { return ((A&)c).n; } // ok, A is an accessible base of B from here
   };
 }
@@ -248,86 +282,94 @@ namespace dr20 { // dr20: 2.8
   public:
     X();
   private:
-    X(const X&); // expected-note {{here}}
+    X(const X&); // #dr20-X-ctor
   };
   X &f();
-  X x = f(); // expected-error {{private}}
+  X x = f();
+  // expected-error at -1 {{calling a private constructor of class 'dr20::X'}}
+  // expected-note@#dr20-X-ctor {{declared private here}}
 }
 
 namespace dr21 { // dr21: 3.4
   template<typename T> struct A;
   struct X {
-    template<typename T = int> friend struct A; // expected-error {{default template argument not permitted on a friend template}}
-    template<typename T = int> friend struct B; // expected-error {{default template argument not permitted on a friend template}}
+    template<typename T = int> friend struct A;
+    // expected-error at -1 {{default template argument not permitted on a friend template}}
+    template<typename T = int> friend struct B;
+    // expected-error at -1 {{default template argument not permitted on a friend template}}
   };
 }
 
 namespace dr22 { // dr22: sup 481
-  template<typename dr22_T = dr22_T> struct X; // expected-error {{unknown type name 'dr22_T'}}
+  template<typename dr22_T = dr22_T> struct X;
+  // expected-error at -1 {{unknown type name 'dr22_T'}}
   typedef int T;
   template<typename T = T> struct Y;
 }
 
 namespace dr23 { // dr23: yes
-  template<typename T> void f(T, T); // expected-note {{candidate}}
-  template<typename T> void f(T, int); // expected-note {{candidate}}
-  void g() { f(0, 0); } // expected-error {{ambiguous}}
+  template<typename T> void f(T, T); // #dr23-f-T-T
+  template<typename T> void f(T, int); // #dr23-f-T-int
+  void g() { f(0, 0); }
+  // expected-error at -1 {{call to 'f' is ambiguous}}
+  // expected-note@#dr23-f-T-T {{candidate function [with T = int]}}
+  // expected-note@#dr23-f-T-int {{candidate function [with T = int]}}
 }
 
 // dr24: na
 
 namespace dr25 { // dr25: yes
   struct A {
-    void f() throw(int); // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
+    void f() throw(int);
+    // since-cxx17-error at -1 {{ISO C++17 does not allow dynamic exception specifications}}
+    // since-cxx17-note at -2 {{use 'noexcept(false)' instead}}
   };
-  void (A::*f)() throw (int); // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
+  void (A::*f)() throw (int);
+  // since-cxx17-error at -1 {{ISO C++17 does not allow dynamic exception specifications}}
+  // since-cxx17-note at -2 {{use 'noexcept(false)' instead}}
   void (A::*g)() throw () = f;
-#if __cplusplus <= 201402L
-  // expected-error at -2 {{is not superset of source}}
-#else
-  // expected-error at -4 {{different exception specifications}}
-#endif
+  // cxx98-14-error at -1 {{target exception specification is not superset of source}}
+  // since-cxx17-error at -2 {{different exception specifications}}
   void (A::*g2)() throw () = 0;
-  void (A::*h)() throw (int, char) = f; // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
+  void (A::*h)() throw (int, char) = f;
+  // since-cxx17-error at -1 {{ISO C++17 does not allow dynamic exception specifications}}
+  // since-cxx17-note at -2 {{use 'noexcept(false)' instead}}
   void (A::*i)() throw () = &A::f;
-#if __cplusplus <= 201402L
-  // expected-error at -2 {{is not superset of source}}
-#else
-  // expected-error at -4 {{different exception specifications}}
-#endif
+  // cxx98-14-error at -1 {{target exception specification is not superset of source}}
+  // since-cxx17-error at -2 {{different exception specifications}}
   void (A::*i2)() throw () = 0;
-  void (A::*j)() throw (int, char) = &A::f; // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
+  void (A::*j)() throw (int, char) = &A::f;
+  // since-cxx17-error at -1 {{ISO C++17 does not allow dynamic exception specifications}}
+  // since-cxx17-note at -2 {{use 'noexcept(false)' instead}}
   void x() {
     g2 = f;
-#if __cplusplus <= 201402L
-  // expected-error at -2 {{is not superset of source}}
-#else
-  // expected-error at -4 {{different exception specifications}}
-#endif
+    // cxx98-14-error at -1 {{target exception specification is not superset of source}}
+    // since-cxx17-error at -2 {{different exception specifications}}
     h = f;
     i2 = &A::f;
-#if __cplusplus <= 201402L
-  // expected-error at -2 {{is not superset of source}}
-#else
-  // expected-error at -4 {{different exception specifications}}
-#endif
+    // cxx98-14-error at -1 {{target exception specification is not superset of source}}
+    // since-cxx17-error at -2 {{different exception specifications}}
     j = &A::f;
   }
 }
 
 namespace dr26 { // dr26: yes
-  struct A { A(A, const A & = A()); }; // expected-error {{must pass its first argument by reference}}
+  struct A { A(A, const A & = A()); };
+  // expected-error at -1 {{copy constructor must pass its first argument by reference}}
   struct B {
     B();
     // FIXME: In C++98, we diagnose this twice.
     B(const B &, B = B());
-#if __cplusplus <= 201402L
-    // expected-error at -2 1+{{recursive evaluation of default argument}} expected-note at -2 1+{{used here}}
-#endif
+    // cxx98-14-error at -1 {{recursive evaluation of default argument}}
+    // cxx98-14-note at -2 {{default argument used here}}
+    // cxx98-error at -3 {{recursive evaluation of default argument}}
+    // cxx98-note at -4 {{default argument used here}}
   };
   struct C {
     static C &f();
-    C(const C &, C = f()); // expected-error {{recursive evaluation of default argument}} expected-note {{used here}}
+    C(const C &, C = f());
+    // expected-error at -1 {{recursive evaluation of default argument}}
+    // expected-note at -2 {{default argument used here}}
   };
 }
 
@@ -339,24 +381,34 @@ namespace dr27 { // dr27: yes
 // dr28: na lib
 
 namespace dr29 { // dr29: 3.4
-  void dr29_f0(); // expected-note {{here}}
+  void dr29_f0(); // #dr29-f0
   void g0() { void dr29_f0(); }
   extern "C++" void g0_cxx() { void dr29_f0(); }
-  extern "C" void g0_c() { void dr29_f0(); } // expected-error {{different language linkage}}
+  extern "C" void g0_c() { void dr29_f0(); }
+  // expected-error at -1 {{declaration of 'dr29_f0' has a different language linkage}}
+  // expected-note@#dr29-f0 {{previous declaration is here}}
 
-  extern "C" void dr29_f1(); // expected-note {{here}}
+  extern "C" void dr29_f1(); // #dr29-f1
   void g1() { void dr29_f1(); }
   extern "C" void g1_c() { void dr29_f1(); }
-  extern "C++" void g1_cxx() { void dr29_f1(); } // expected-error {{different language linkage}}
+  extern "C++" void g1_cxx() { void dr29_f1(); }
+  // expected-error at -1 {{declaration of 'dr29_f1' has a different language linkage}}
+  // expected-note@#dr29-f1 {{previous declaration is here}}
 
-  void g2() { void dr29_f2(); } // expected-note {{here}}
-  extern "C" void dr29_f2(); // expected-error {{different language linkage}}
+  void g2() { void dr29_f2(); } // #dr29-f2
+  extern "C" void dr29_f2();
+  // expected-error at -1 {{declaration of 'dr29_f2' has a different language linkage}}
+  // expected-note@#dr29-f2 {{previous declaration is here}}
 
-  extern "C" void g3() { void dr29_f3(); } // expected-note {{here}}
-  extern "C++" void dr29_f3(); // expected-error {{different language linkage}}
+  extern "C" void g3() { void dr29_f3(); } // #dr29-f3
+  extern "C++" void dr29_f3();
+  // expected-error at -1 {{declaration of 'dr29_f3' has a different language linkage}}
+  // expected-note@#dr29-f3 {{previous declaration is here}}
 
-  extern "C++" void g4() { void dr29_f4(); } // expected-note {{here}}
-  extern "C" void dr29_f4(); // expected-error {{different language linkage}}
+  extern "C++" void g4() { void dr29_f4(); } // #dr29-f4
+  extern "C" void dr29_f4();
+  // expected-error at -1 {{declaration of 'dr29_f4' has a different language linkage}}
+  // expected-note@#dr29-f4 {{previous declaration is here}}
 
   extern "C" void g5();
   extern "C++" void dr29_f5();
@@ -371,15 +423,19 @@ namespace dr29 { // dr29: 3.4
   }
 
   extern "C" void g7();
-  extern "C++" void dr29_f7(); // expected-note {{here}}
+  extern "C++" void dr29_f7(); // #dr29-f7
   extern "C" void g7() {
-    void dr29_f7(); // expected-error {{different language linkage}}
+    void dr29_f7();
+    // expected-error at -1 {{declaration of 'dr29_f7' has a different language linkage}}
+    // expected-note@#dr29-f7 {{previous declaration is here}}
   }
 
   extern "C++" void g8();
-  extern "C" void dr29_f8(); // expected-note {{here}}
+  extern "C" void dr29_f8(); // #dr29-f8
   extern "C++" void g8() {
-    void dr29_f8(); // expected-error {{different language linkage}}
+    void dr29_f8();
+    // expected-error at -1 {{declaration of 'dr29_f8' has a different language linkage}}
+    // expected-note@#dr29-f8 {{previous declaration is here}}
   }
 }
 
@@ -387,38 +443,42 @@ namespace dr30 { // dr30: sup 468 c++11
   struct A {
     template<int> static int f();
   } a, *p = &a;
+  // FIXME: It's not clear whether DR468 applies to C++98 too.
   int x = A::template f<0>();
+  // cxx98-error at -1 {{'template' keyword outside of a template}}
   int y = a.template f<0>();
+  // cxx98-error at -1 {{'template' keyword outside of a template}}
   int z = p->template f<0>();
-#if __cplusplus < 201103L
-  // FIXME: It's not clear whether DR468 applies to C++98 too.
-  // expected-error at -5 {{'template' keyword outside of a template}}
-  // expected-error at -5 {{'template' keyword outside of a template}}
-  // expected-error at -5 {{'template' keyword outside of a template}}
-#endif
+  // cxx98-error at -1 {{'template' keyword outside of a template}}
 }
 
 namespace dr31 { // dr31: 2.8
   class X {
   private:
-    void operator delete(void*); // expected-note {{here}}
+    void operator delete(void*); // #dr31-delete
   };
   // We would call X::operator delete if X() threw (even though it can't,
   // and even though we allocated the X using ::operator delete).
-  X *p = new X; // expected-error {{private}}
+  X *p = new X;
+  // expected-error at -1 {{'operator delete' is a private member of 'dr31::X'}}
+  // expected-note@#dr31-delete {{declared private here}}
 }
 
 // dr32: na
 
 namespace dr33 { // dr33: 9
-  namespace X { struct S; void f(void (*)(S)); } // expected-note {{candidate}}
-  namespace Y { struct T; void f(void (*)(T)); } // expected-note {{candidate}}
+  namespace X { struct S; void f(void (*)(S)); } // #dr33-f-S
+  namespace Y { struct T; void f(void (*)(T)); } // #dr33-f-T
   void g(X::S);
   template<typename Z> Z g(Y::T);
-  void h() { f(&g); } // expected-error {{ambiguous}}
+  void h() { f(&g); }
+  // expected-error at -1 {{call to 'f' is ambiguous}}
+  // expected-note@#dr33-f-S {{candidate function}}
+  // expected-note@#dr33-f-T {{candidate function}}
 
   template<typename T> void t(X::S);
-  template<typename T, typename U = void> void u(X::S); // expected-error 0-1{{default template argument}}
+  template<typename T, typename U = void> void u(X::S);
+  // expected-error at -1 0-1 {{default template arguments for a function template are a C++11 extension}}
   void templ() { f(t<int>); f(u<int>); }
 
   // Even though v<int> cannot select the first overload, ADL considers it
@@ -436,7 +496,8 @@ namespace dr33 { // dr33: 9
     };
 
     template<typename T> void f(Y<T>);
-    int use = X() + f<int>; // expected-error {{invalid operands}}
+    int use = X() + f<int>;
+    // expected-error at -1 {{invalid operands to binary expression ('X' and 'void (Y<int>)')}}
   }
 
   namespace member {
@@ -481,17 +542,25 @@ namespace example2 {
 
   struct D : virtual B, virtual C
   {
-    using B::i; // expected-note {{previous using decla...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/73879


More information about the cfe-commits mailing list