Skip to content

Commit 6ed9a81

Browse files
authored
[clang][NFC] Refactor expected directives in C++ DRs 2000-2799 (#74921)
This patch continues the work started with ea5b1ef. See that commit and its corresponding PR for details.
1 parent 312cb34 commit 6ed9a81

File tree

10 files changed

+499
-298
lines changed

10 files changed

+499
-298
lines changed

clang/test/CXX/drs/dr20xx.cpp

Lines changed: 139 additions & 80 deletions
Large diffs are not rendered by default.

clang/test/CXX/drs/dr21xx.cpp

Lines changed: 92 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
2-
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
3-
// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
4-
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
5-
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
6-
// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
7-
8-
#if __cplusplus < 201103L
9-
// expected-error@+1 {{variadic macro}}
1+
// 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
2+
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,cxx98-14,since-cxx11 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
3+
// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,cxx98-14,since-cxx11 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
4+
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
5+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
6+
// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
7+
// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
8+
9+
#if __cplusplus == 199711L
1010
#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
11+
// cxx98-error@-1 {{variadic macros are a C99 feature}}
1112
#endif
1213

1314
namespace dr2100 { // dr2100: 12
@@ -18,15 +19,14 @@ namespace dr2100 { // dr2100: 12
1819
return X<&n>::n; // ok, value-dependent
1920
}
2021
int g() {
21-
static const int n = 2;
22+
static const int n = 2; // #dr2100-n
2223
return X<&n>::n; // ok, value-dependent
23-
#if __cplusplus < 201702L
24-
// expected-error@-2 {{does not have linkage}} expected-note@-3 {{here}}
25-
#endif
24+
// cxx98-14-error@-1 {{non-type template argument refers to object 'n' that does not have linkage}}
25+
// cxx98-14-note@#dr2100-n {{non-type template argument refers to object here}}
2626
}
2727
};
2828
template<const int *P> struct X<P> {
29-
#if __cplusplus < 201103L
29+
#if __cplusplus == 199711L
3030
static const int n = 0;
3131
#else
3232
static const int n = *P;
@@ -40,11 +40,13 @@ namespace dr2100 { // dr2100: 12
4040
template<typename T> struct B {
4141
static const int n = 1;
4242
int f() {
43-
return Y<n>::declared_later; // expected-error {{no member named 'declared_later'}}
43+
return Y<n>::declared_later;
44+
// expected-error@-1 {{no member named 'declared_later' in 'dr2100::Y<1>'}}
4445
}
4546
int g() {
4647
static const int n = 2;
47-
return Y<n>::declared_later; // expected-error {{no member named 'declared_later'}}
48+
return Y<n>::declared_later;
49+
// expected-error@-1 {{no member named 'declared_later' in 'dr2100::Y<2>'}}
4850
}
4951
};
5052
template<int N> struct Y<N> {
@@ -55,10 +57,12 @@ namespace dr2100 { // dr2100: 12
5557
namespace dr2103 { // dr2103: yes
5658
void f() {
5759
int a;
58-
int &r = a; // expected-note {{here}}
60+
int &r = a; // #dr2103-r
5961
struct Inner {
6062
void f() {
61-
int &s = r; // expected-error {{enclosing function}}
63+
int &s = r;
64+
// expected-error@-1 {{reference to local variable 'r' declared in enclosing function 'dr2103::f'}}
65+
// expected-note@#dr2103-r {{'r' declared here}}
6266
(void)s;
6367
}
6468
};
@@ -84,28 +88,46 @@ namespace dr2126 { // dr2126: 12
8488
A &b = (A &)(const A &)A{1}; // const temporary
8589
A &&c = (A &&)(const A &)A{1}; // const temporary
8690

87-
A &&d = {1}; // non-const temporary expected-note {{here}}
88-
const A &e = (A &)(A &&) A{1}; // non-const temporary expected-note {{here}}
89-
A &&f = (A &&)(A &&) A{1}; // non-const temporary expected-note {{here}}
91+
A &&d = {1}; // non-const temporary #dr21260-d
92+
const A &e = (A &)(A &&) A{1}; // non-const temporary #dr21260-e
93+
A &&f = (A &&)(A &&) A{1}; // non-const temporary #dr21260-f
9094

9195
constexpr const A &g = {1}; // const temporary
92-
constexpr A &&h = {1}; // non-const temporary expected-note {{here}}
96+
constexpr A &&h = {1}; // non-const temporary #dr21260-h
9397

9498
struct B { const A &a; };
95-
B i = {{1}}; // extending decl not usable in constant expr expected-note {{here}}
96-
const B j = {{1}}; // extending decl not usable in constant expr expected-note {{here}}
99+
B i = {{1}}; // extending decl not usable in constant expr #dr21260-i
100+
const B j = {{1}}; // extending decl not usable in constant expr #dr21260-j
97101
constexpr B k = {{1}}; // extending decl usable in constant expr
98102

99103
static_assert(a.n == 1, "");
100104
static_assert(b.n == 1, "");
101105
static_assert(c.n == 1, "");
102-
static_assert(d.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
103-
static_assert(e.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
104-
static_assert(f.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
106+
static_assert(d.n == 1, "");
107+
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
108+
// since-cxx11-note@-2 {{read of temporary is not allowed in a constant expression outside the expression that created the temporary}}
109+
// since-cxx11-note@#dr21260-d {{temporary created here}}
110+
static_assert(e.n == 1, "");
111+
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
112+
// since-cxx11-note@-2 {{read of temporary is not allowed in a constant expression outside the expression that created the temporary}}
113+
// since-cxx11-note@#dr21260-e {{temporary created here}}
114+
static_assert(f.n == 1, "");
115+
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
116+
// since-cxx11-note@-2 {{read of temporary is not allowed in a constant expression outside the expression that created the temporary}}
117+
// since-cxx11-note@#dr21260-f {{temporary created here}}
105118
static_assert(g.n == 1, "");
106-
static_assert(h.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
107-
static_assert(i.a.n == 1, ""); // expected-error {{constant}} expected-note {{read of non-constexpr variable}}
108-
static_assert(j.a.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
119+
static_assert(h.n == 1, "");
120+
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
121+
// since-cxx11-note@-2 {{read of temporary is not allowed in a constant expression outside the expression that created the temporary}}
122+
// since-cxx11-note@#dr21260-h {{temporary created here}}
123+
static_assert(i.a.n == 1, "");
124+
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
125+
// since-cxx11-note@-2 {{read of non-constexpr variable 'i' is not allowed in a constant expression}}
126+
// since-cxx11-note@#dr21260-i {{declared here}}
127+
static_assert(j.a.n == 1, "");
128+
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
129+
// since-cxx11-note@-2 {{read of temporary is not allowed in a constant expression outside the expression that created the temporary}}
130+
// since-cxx11-note@#dr21260-j {{temporary created here}}
109131
static_assert(k.a.n == 1, "");
110132
#endif
111133
}
@@ -128,19 +150,27 @@ struct B{};
128150

129151
void foo() {
130152
struct A *b = (1 == 1) ? new struct A : new struct A;
131-
struct S *a = (1 == 1) ? new struct S : new struct S; // expected-error 2{{allocation of incomplete type}} // expected-note 2{{forward}}
153+
struct S *a = (1 == 1) ? new struct S : new struct S;
154+
// expected-error@-1 {{allocation of incomplete type 'struct S'}}
155+
// expected-note@-2 {{forward declaration of 'S'}}
156+
// expected-error@-3 {{allocation of incomplete type 'struct S'}}
157+
// expected-note@-4 {{forward declaration of 'S'}}
132158

133159
#if __cplusplus >= 201103L
134160
A *aa = new struct A{};
135161
B<int> *bb = new struct B<int>{};
136-
(void)new struct C{}; // expected-error {{allocation of incomplete type }} // expected-note {{forward}}
162+
(void)new struct C{};
163+
// since-cxx11-error@-1 {{allocation of incomplete type 'struct C'}}
164+
// since-cxx11-note@-2 {{forward declaration of 'C'}}
137165

138166
struct A *c = (1 == 1) ? new struct A {} : new struct A {};
139167

140-
alignof(struct D{}); // expected-error {{cannot be defined in a type specifier}}
168+
alignof(struct D{});
169+
// since-cxx11-error@-1 {{'D' cannot be defined in a type specifier}}
141170
#endif
142171

143-
sizeof(struct E{}); // expected-error {{cannot be defined in a type specifier}}
172+
sizeof(struct E{});
173+
// expected-error@-1 {{'E' cannot be defined in a type specifier}}
144174

145175
}
146176
}
@@ -149,7 +179,8 @@ namespace dr2157 { // dr2157: 11
149179
#if __cplusplus >= 201103L
150180
enum E : int;
151181
struct X {
152-
enum dr2157::E : int(); // expected-error {{only allows ':' in member enumeration declaration to introduce a fixed underlying type}}
182+
enum dr2157::E : int();
183+
// since-cxx11-error@-1 {{ISO C++ only allows ':' in member enumeration declaration to introduce a fixed underlying type, not an anonymous bit-field}}
153184
};
154185
#endif
155186
}
@@ -159,11 +190,13 @@ namespace dr2157 { // dr2157: 11
159190
namespace dr2170 { // dr2170: 9
160191
#if __cplusplus >= 201103L
161192
void f() {
162-
constexpr int arr[3] = {1, 2, 3}; // expected-note {{here}}
193+
constexpr int arr[3] = {1, 2, 3}; // #dr2170-arr
163194
struct S {
164195
int get(int n) { return arr[n]; }
165-
const int &get_ref(int n) { return arr[n]; } // expected-error {{enclosing function}}
166-
// FIXME: expected-warning@-1 {{reference to stack}}
196+
const int &get_ref(int n) { return arr[n]; }
197+
// since-cxx11-warning@-1 {{reference to stack memory associated with local variable 'arr' returned}} FIXME
198+
// since-cxx11-error@-2 {{reference to local variable 'arr' declared in enclosing function 'dr2170::f'}}
199+
// since-cxx11-note@#dr2170-arr {{'arr' declared here}}
167200
};
168201
}
169202
#endif
@@ -198,22 +231,32 @@ static_assert(!__is_trivially_assignable(NonConstCopy &&, NonConstCopy &&), "");
198231

199232
namespace dr2180 { // dr2180: yes
200233
class A {
201-
A &operator=(const A &); // expected-note 0-2{{here}}
202-
A &operator=(A &&); // expected-note 0-2{{here}} expected-error 0-1{{extension}}
234+
A &operator=(const A &); // #dr2180-A-copy
235+
A &operator=(A &&); // #dr2180-A-move
236+
// cxx98-error@-1 {{rvalue references are a C++11 extension}}
203237
};
204238

205-
struct B : virtual A {
239+
struct B : virtual A { // #dr2180-B
206240
B &operator=(const B &);
207-
B &operator=(B &&); // expected-error 0-1{{extension}}
241+
B &operator=(B &&);
242+
// cxx98-error@-1 {{rvalue references are a C++11 extension}}
208243
virtual void foo() = 0;
209244
};
210-
#if __cplusplus < 201103L
211-
B &B::operator=(const B&) = default; // expected-error {{private member}} expected-error {{extension}} expected-note {{here}}
212-
B &B::operator=(B&&) = default; // expected-error {{private member}} expected-error 2{{extension}} expected-note {{here}}
213-
#else
214-
B &B::operator=(const B&) = default; // expected-error {{would delete}} expected-note@-9{{inaccessible copy assignment}}
215-
B &B::operator=(B&&) = default; // expected-error {{would delete}} expected-note@-10{{inaccessible move assignment}}
216-
#endif
245+
B &B::operator=(const B&) = default; // #dr2180-B-copy
246+
// cxx98-error@-1 {{defaulted function definitions are a C++11 extension}}
247+
// cxx98-error@-2 {{'operator=' is a private member of 'dr2180::A'}}
248+
// cxx98-note@-3 {{in defaulted copy assignment operator for 'dr2180::B' first required here}}
249+
// cxx98-note@#dr2180-A-copy {{implicitly declared private here}}
250+
// since-cxx11-error@#dr2180-B-copy {{defaulting this copy assignment operator would delete it after its first declaration}}
251+
// since-cxx11-note@#dr2180-B {{copy assignment operator of 'B' is implicitly deleted because base class 'A' has an inaccessible copy assignment operator}}
252+
B &B::operator=(B&&) = default; // #dr2180-B-move
253+
// cxx98-error@-1 {{rvalue references are a C++11 extension}}
254+
// cxx98-error@-2 {{defaulted function definitions are a C++11 extension}}
255+
// cxx98-error@-3 {{'operator=' is a private member of 'dr2180::A'}}
256+
// cxx98-note@-4 {{in defaulted move assignment operator for 'dr2180::B' first required here}}
257+
// cxx98-note@#dr2180-A-move {{implicitly declared private here}}
258+
// since-cxx11-error@#dr2180-B-move {{defaulting this move assignment operator would delete it after its first declaration}}
259+
// since-cxx11-note@#dr2180-B {{move assignment operator of 'B' is implicitly deleted because base class 'A' has an inaccessible move assignment operator}}
217260
}
218261

219262
namespace dr2199 { // dr2199: 3.8

clang/test/CXX/drs/dr22xx.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2-
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3-
// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4-
// RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
1+
// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
2+
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
3+
// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
4+
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
5+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
6+
// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
7+
// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
8+
59

610
#if __cplusplus >= 201103L
711
namespace dr2211 { // dr2211: 8
812
void f() {
913
int a;
10-
auto f = [a](int a) { (void)a; }; // expected-error {{a lambda parameter cannot shadow an explicitly captured entity}}
11-
// expected-note@-1{{variable 'a' is explicitly captured here}}
14+
auto f = [a](int a) { (void)a; };
15+
// since-cxx11-error@-1 {{a lambda parameter cannot shadow an explicitly captured entity}}
16+
// since-cxx11-note@-2 {{variable 'a' is explicitly captured here}}
1217
auto g = [=](int a) { (void)a; };
1318
}
1419
}
@@ -24,9 +29,12 @@ struct A<int, U>;
2429

2530
namespace dr2229 { // dr2229: 7
2631
struct AnonBitfieldQualifiers {
27-
const unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}}
28-
volatile unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}}
29-
const volatile unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}}
32+
const unsigned : 1;
33+
// expected-error@-1 {{anonymous bit-field cannot have qualifiers}}
34+
volatile unsigned : 1;
35+
// expected-error@-1 {{anonymous bit-field cannot have qualifiers}}
36+
const volatile unsigned : 1;
37+
// expected-error@-1 {{anonymous bit-field cannot have qualifiers}}
3038

3139
unsigned : 1;
3240
const unsigned i1 : 1;
@@ -98,7 +106,8 @@ namespace MultilevelSpecialization {
98106
template <T... V> void f(int i = 0, int (&... arr)[V]);
99107
};
100108
template<> template<int a, int b>
101-
void B<int, int>::f(int i, int (&arr1)[a], int (&arr2)[b]) {} // expected-error {{does not match}}
109+
void B<int, int>::f(int i, int (&arr1)[a], int (&arr2)[b]) {}
110+
// since-cxx11-error@-1 {{out-of-line definition of 'f' does not match any declaration in 'dr2233::MultilevelSpecialization::B<int, int>'}}
102111
template<> template<>
103112
void B<int, int>::f<1, 1>(int i, int (&arr1a)[1], int (&arr2a)[1]) {}
104113
}
@@ -134,10 +143,10 @@ struct C { explicit operator D(); } c;
134143
B b1(a);
135144
const B &b2{a}; // FIXME ill-formed
136145
const B &b3(a);
137-
// expected-error@-1 {{no viable conversion from 'struct A' to 'const B'}}
138-
// expected-note@#dr2267-struct-B {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'struct A' to 'const B &' for 1st argument}}
139-
// expected-note@#dr2267-struct-B {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'struct A' to 'B &&' for 1st argument}}
140-
// expected-note@#dr2267-struct-B {{explicit constructor is not a candidate}}
146+
// since-cxx11-error@-1 {{no viable conversion from 'struct A' to 'const B'}}
147+
// since-cxx11-note@#dr2267-struct-B {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'struct A' to 'const B &' for 1st argument}}
148+
// since-cxx11-note@#dr2267-struct-B {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'struct A' to 'B &&' for 1st argument}}
149+
// since-cxx11-note@#dr2267-struct-B {{explicit constructor is not a candidate}}
141150

142151
D d1(c);
143152
const D &d2{c}; // FIXME ill-formed

clang/test/CXX/drs/dr2354.cpp

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)