Skip to content

Commit

Permalink
[clang][NFC] Fix expected directives in C++ DRs
Browse files Browse the repository at this point in the history
If directive is put inside `#if __cplusplus`, it should reflect the condition, instead of being generic `expected`.
  • Loading branch information
Endilll committed Jan 6, 2025
1 parent 2a593bb commit eff1265
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 172 deletions.
16 changes: 8 additions & 8 deletions clang/test/CXX/drs/cwg0xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,11 +709,11 @@ namespace cwg39 { // cwg39: no
// expected-error@#cwg39-sizeof {{unknown type name}}
#if __cplusplus >= 201103L
decltype(D::n) n;
/* expected-error@-1
/* since-cxx11-error@-1
{{non-static member 'n' found in multiple base-class subobjects of type 'A':
struct cwg39::PR5916::D -> B -> A
struct cwg39::PR5916::D -> C -> A}} */
// expected-note@#cwg39-A-n {{member found by ambiguous name lookup}}
// since-cxx11-note@#cwg39-A-n {{member found by ambiguous name lookup}}
#endif
}
} // namespace cwg39
Expand Down Expand Up @@ -1150,8 +1150,8 @@ namespace cwg73 { // cwg73: sup 1652
#if __cplusplus >= 201103L
int a, b;
static_assert(&a + 1 != &b, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{comparison against pointer '&a + 1' that points past the end of a complete object has unspecified value}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{comparison against pointer '&a + 1' that points past the end of a complete object has unspecified value}}
#endif
} // namespace cwg73

Expand Down Expand Up @@ -1255,14 +1255,14 @@ namespace cwg85 { // cwg85: 3.4
enum E1 : int;
enum E1 : int { e1 }; // #cwg85-E1-def
enum E1 : int;
// expected-error@-1 {{class member cannot be redeclared}}
// expected-note@#cwg85-E1-def {{previous declaration is here}}
// since-cxx11-error@-1 {{class member cannot be redeclared}}
// since-cxx11-note@#cwg85-E1-def {{previous declaration is here}}

enum class E2;
enum class E2 { e2 }; // #cwg85-E2-def
enum class E2;
// expected-error@-1 {{class member cannot be redeclared}}
// expected-note@#cwg85-E2-def {{previous declaration is here}}
// since-cxx11-error@-1 {{class member cannot be redeclared}}
// since-cxx11-note@#cwg85-E2-def {{previous declaration is here}}
#endif
};

Expand Down
98 changes: 49 additions & 49 deletions clang/test/CXX/drs/cwg14xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct A;
void f() {
constexpr A* a = nullptr;
constexpr int p = &*a;
// expected-error@-1 {{cannot initialize a variable of type 'const int' with an rvalue of type 'A *'}}
// since-cxx11-error@-1 {{cannot initialize a variable of type 'const int' with an rvalue of type 'A *'}}
constexpr A *p2 = &*a;
}

Expand All @@ -108,27 +108,27 @@ namespace cwg1460 { // cwg1460: 3.5
namespace DRExample {
union A {
union {};
// expected-error@-1 {{declaration does not declare anything}}
// since-cxx11-error@-1 {{declaration does not declare anything}}
union {};
// expected-error@-1 {{declaration does not declare anything}}
// since-cxx11-error@-1 {{declaration does not declare anything}}
constexpr A() {}
};
constexpr A a = A();

union B {
union {};
// expected-error@-1 {{declaration does not declare anything}}
// since-cxx11-error@-1 {{declaration does not declare anything}}
union {};
// expected-error@-1 {{declaration does not declare anything}}
// since-cxx11-error@-1 {{declaration does not declare anything}}
constexpr B() = default;
};
constexpr B b = B();

union C {
union {};
// expected-error@-1 {{declaration does not declare anything}}
// since-cxx11-error@-1 {{declaration does not declare anything}}
union {};
// expected-error@-1 {{declaration does not declare anything}}
// since-cxx11-error@-1 {{declaration does not declare anything}}
};
constexpr C c = C();
#if __cplusplus >= 201403L
Expand All @@ -141,7 +141,7 @@ namespace cwg1460 { // cwg1460: 3.5
union B { int n; }; // #cwg1460-B
union C { int n = 0; };
struct D { union {}; };
// expected-error@-1 {{declaration does not declare anything}}
// since-cxx11-error@-1 {{declaration does not declare anything}}
struct E { union { int n; }; }; // #cwg1460-E
struct F { union { int n = 0; }; };

Expand Down Expand Up @@ -173,7 +173,7 @@ namespace cwg1460 { // cwg1460: 3.5
// cxx11-17-error@-1 {{defaulted definition of default constructor cannot be marked constexpr}}
union C { int n = 0; constexpr C() = default; };
struct D { union {}; constexpr D() = default; };
// expected-error@-1 {{declaration does not declare anything}}
// since-cxx11-error@-1 {{declaration does not declare anything}}
struct E { union { int n; }; constexpr E() = default; };
// cxx11-17-error@-1 {{defaulted definition of default constructor cannot be marked constexpr}}
struct F { union { int n = 0; }; constexpr F() = default; };
Expand Down Expand Up @@ -222,25 +222,25 @@ namespace cwg1460 { // cwg1460: 3.5
union G {
int a = 0; // #cwg1460-G-a
int b = 0;
// expected-error@-1 {{initializing multiple members of union}}
// expected-note@#cwg1460-G-a {{previous initialization is here}}
// since-cxx11-error@-1 {{initializing multiple members of union}}
// since-cxx11-note@#cwg1460-G-a {{previous initialization is here}}
};
union H {
union {
int a = 0; // #cwg1460-H-a
};
union {
int b = 0;
// expected-error@-1 {{initializing multiple members of union}}
// expected-note@#cwg1460-H-a {{previous initialization is here}}
// since-cxx11-error@-1 {{initializing multiple members of union}}
// since-cxx11-note@#cwg1460-H-a {{previous initialization is here}}
};
};
struct I {
union {
int a = 0; // #cwg1460-I-a
int b = 0;
// expected-error@-1 {{initializing multiple members of union}}
// expected-note@#cwg1460-I-a {{previous initialization is here}}
// since-cxx11-error@-1 {{initializing multiple members of union}}
// since-cxx11-note@#cwg1460-I-a {{previous initialization is here}}
};
};
struct J {
Expand All @@ -264,23 +264,23 @@ namespace cwg1460 { // cwg1460: 3.5
};
static_assert(B().a == 1, "");
static_assert(B().b == 2, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{read of member 'b' of union with active member 'a' is not allowed in a constant expression}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of member 'b' of union with active member 'a' is not allowed in a constant expression}}
static_assert(B('x').a == 0, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{read of member 'a' of union with active member 'b' is not allowed in a constant expression}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of member 'a' of union with active member 'b' is not allowed in a constant expression}}
static_assert(B('x').b == 4, "");
static_assert(B(123).b == 2, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{read of member 'b' of union with active member 'c' is not allowed in a constant expression}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of member 'b' of union with active member 'c' is not allowed in a constant expression}}
static_assert(B(123).c == 3, "");
static_assert(B("").a == 1, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{read of member 'a' of union with active member 'b' is not allowed in a constant expression}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of member 'a' of union with active member 'b' is not allowed in a constant expression}}
static_assert(B("").b == 2, "");
static_assert(B("").c == 3, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{read of member 'c' of union with active member 'b' is not allowed in a constant expression}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of member 'c' of union with active member 'b' is not allowed in a constant expression}}

struct C {
union { int a, b = 2, c; };
Expand All @@ -294,54 +294,54 @@ namespace cwg1460 { // cwg1460: 3.5

static_assert(C().a == 1, "");
static_assert(C().b == 2, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{read of member 'b' of union with active member 'a' is not allowed in a constant expression}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of member 'b' of union with active member 'a' is not allowed in a constant expression}}
static_assert(C().d == 4, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{read of member 'd' of union with active member 'e' is not allowed in a constant expression}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of member 'd' of union with active member 'e' is not allowed in a constant expression}}
static_assert(C().e == 5, "");

static_assert(C('x').b == 2, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{read of member 'b' of union with active member 'c' is not allowed in a constant expression}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of member 'b' of union with active member 'c' is not allowed in a constant expression}}
static_assert(C('x').c == 3, "");
static_assert(C('x').d == 4, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{read of member 'd' of union with active member 'e' is not allowed in a constant expression}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of member 'd' of union with active member 'e' is not allowed in a constant expression}}
static_assert(C('x').e == 5, "");

static_assert(C(1).b == 2, "");
static_assert(C(1).c == 3, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{read of member 'c' of union with active member 'b' is not allowed in a constant expression}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of member 'c' of union with active member 'b' is not allowed in a constant expression}}
static_assert(C(1).d == 4, "");
static_assert(C(1).e == 5, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{read of member 'e' of union with active member 'd' is not allowed in a constant expression}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of member 'e' of union with active member 'd' is not allowed in a constant expression}}

static_assert(C(1.f).b == 2, "");
static_assert(C(1.f).c == 3, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{read of member 'c' of union with active member 'b' is not allowed in a constant expression}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of member 'c' of union with active member 'b' is not allowed in a constant expression}}
static_assert(C(1.f).e == 5, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{read of member 'e' of union with active member 'f' is not allowed in a constant expression}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of member 'e' of union with active member 'f' is not allowed in a constant expression}}
static_assert(C(1.f).f == 6, "");

static_assert(C("").a == 1, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{read of member 'a' of union with active member 'b' is not allowed in a constant expression}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of member 'a' of union with active member 'b' is not allowed in a constant expression}}
static_assert(C("").b == 2, "");
static_assert(C("").c == 3, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{read of member 'c' of union with active member 'b' is not allowed in a constant expression}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of member 'c' of union with active member 'b' is not allowed in a constant expression}}
static_assert(C("").d == 4, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{read of member 'd' of union with active member 'e' is not allowed in a constant expression}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of member 'd' of union with active member 'e' is not allowed in a constant expression}}
static_assert(C("").e == 5, "");
static_assert(C("").f == 6, "");
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{read of member 'f' of union with active member 'e' is not allowed in a constant expression}}
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of member 'f' of union with active member 'e' is not allowed in a constant expression}}

struct D;
extern const D d;
Expand Down
27 changes: 12 additions & 15 deletions clang/test/CXX/drs/cwg18xx.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected,cxx98-14,cxx98 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,cxx98-14,cxx11-17,since-cxx11 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx14,cxx98-14,cxx11-17,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx14,since-cxx17,cxx11-17,since-cxx11,since-cxx14,cxx17 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx14,since-cxx17,since-cxx20,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-20,cxx98-14,cxx11-17,since-cxx11 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-20,since-cxx14,cxx98-14,cxx11-17,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-20,since-cxx14,since-cxx17,cxx11-17,since-cxx11,since-cxx14,cxx17 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-20,since-cxx14,since-cxx17,since-cxx20,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx14,since-cxx17,since-cxx20,since-cxx23,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx14,since-cxx17,since-cxx20,since-cxx23,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors

Expand Down Expand Up @@ -274,8 +274,8 @@ void d2() {
#if __cplusplus >= 201103L
auto e = [] {
typedef int cwg1820::A;
// expected-error@-1 {{definition or redeclaration of 'A' not allowed inside a function}}
// expected-error@-2 {{typedef declarator cannot be qualified}}
// since-cxx11-error@-1 {{definition or redeclaration of 'A' not allowed inside a function}}
// since-cxx11-error@-2 {{typedef declarator cannot be qualified}}
};
#endif
} // namespace cwg1820
Expand Down Expand Up @@ -325,9 +325,9 @@ enum E { // #cwg1832-E

#if __cplusplus >= 201103L
enum E2: decltype(static_cast<E2>(0), 0) {};
// expected-error@-1 {{unknown type name 'E2'}}
// since-cxx11-error@-1 {{unknown type name 'E2'}}
enum class E3: decltype(static_cast<E3>(0), 0) {};
// expected-error@-1 {{unknown type name 'E3'}}
// since-cxx11-error@-1 {{unknown type name 'E3'}}
#endif
} // namespace cwg1832

Expand Down Expand Up @@ -488,15 +488,12 @@ namespace cwg1872 { // cwg1872: 9
// cxx11-17-error@-1 {{constexpr variable 'y2' must be initialized by a constant expression}}
// cxx11-17-note@-2 {{cannot evaluate call to virtual function in a constant expression in C++ standards before C++20}}
#if __cplusplus >= 202002L
static_assert(y == 0);
static_assert(y2 == 0);
#endif
constexpr int z = A<Z>().f();
// since-cxx11-error@-1 {{constexpr variable 'z' must be initialized by a constant expression}}a
#if __cplusplus < 202302L
// since-cxx11-note@-3 {{non-literal type 'A<Z>' cannot be used in a constant expression}}
#else
// since-cxx23-note@-5 {{cannot construct object of type 'A<cwg1872::Z>' with virtual base class in a constant expression}}
#endif
// since-cxx11-error@-1 {{constexpr variable 'z' must be initialized by a constant expression}}
// cxx11-20-note@-2 {{non-literal type 'A<Z>' cannot be used in a constant expression}}
// since-cxx23-note@-3 {{cannot construct object of type 'A<cwg1872::Z>' with virtual base class in a constant expression}}
#endif
} // namespace cwg1872

Expand Down
Loading

0 comments on commit eff1265

Please sign in to comment.