Skip to content

Commit 1819222

Browse files
committed
[clang] tests: cleanup, update and add some new ones
This reworks a small set of tests, as preparatory work for implementing P2266. * Run for more standard versions, including c++2b. * Normalize file names and run commands. * Adds some extra tests. New Coroutine tests taken from Aaron Puchert's D68845. Signed-off-by: Matheus Izvekov <[email protected]> Reviewed By: thakis Differential Revision: https://reviews.llvm.org/D99225
1 parent d8bc4de commit 1819222

File tree

16 files changed

+563
-186
lines changed

16 files changed

+563
-186
lines changed

clang/test/CXX/class/class.init/class.copy.elision/p3.cpp

Lines changed: 103 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected,cxx20 %s
2-
// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify=expected,cxx11_14_17 %s
3-
// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify=expected,cxx11_14_17 %s
4-
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify=expected,cxx11_14_17 %s
1+
// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fcxx-exceptions -verify=expected,cxx20_2b %s
2+
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected,cxx20_2b %s
3+
// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify=expected,cxx11_17 %s
4+
// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify=expected,cxx11_17 %s
5+
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify=expected,cxx11_17 %s
56

67
namespace test_delete_function {
78
struct A1 {
@@ -54,38 +55,38 @@ B2 test4() {
5455
namespace test_implicitly_movable_rvalue_ref {
5556
struct A1 {
5657
A1(A1 &&);
57-
A1(const A1 &) = delete; // cxx11_14_17-note {{'A1' has been explicitly marked deleted here}}
58+
A1(const A1 &) = delete; // cxx11_17-note {{'A1' has been explicitly marked deleted here}}
5859
};
5960
A1 test1(A1 &&a) {
60-
return a; // cxx11_14_17-error {{call to deleted constructor of 'test_implicitly_movable_rvalue_ref::A1'}}
61+
return a; // cxx11_17-error {{call to deleted constructor of 'test_implicitly_movable_rvalue_ref::A1'}}
6162
}
6263

6364
struct A2 {
6465
A2(A2 &&);
6566

6667
private:
67-
A2(const A2 &); // cxx11_14_17-note {{declared private here}}
68+
A2(const A2 &); // cxx11_17-note {{declared private here}}
6869
};
6970
A2 test2(A2 &&a) {
70-
return a; // cxx11_14_17-error {{calling a private constructor of class 'test_implicitly_movable_rvalue_ref::A2'}}
71+
return a; // cxx11_17-error {{calling a private constructor of class 'test_implicitly_movable_rvalue_ref::A2'}}
7172
}
7273

7374
struct B1 {
7475
B1(const B1 &);
75-
B1(B1 &&) = delete; // cxx20-note {{'B1' has been explicitly marked deleted here}}
76+
B1(B1 &&) = delete; // cxx20_2b-note {{'B1' has been explicitly marked deleted here}}
7677
};
7778
B1 test3(B1 &&b) {
78-
return b; // cxx20-error {{call to deleted constructor of 'test_implicitly_movable_rvalue_ref::B1'}}
79+
return b; // cxx20_2b-error {{call to deleted constructor of 'test_implicitly_movable_rvalue_ref::B1'}}
7980
}
8081

8182
struct B2 {
8283
B2(const B2 &);
8384

8485
private:
85-
B2(B2 &&); // cxx20-note {{declared private here}}
86+
B2(B2 &&); // cxx20_2b-note {{declared private here}}
8687
};
8788
B2 test4(B2 &&b) {
88-
return b; // cxx20-error {{calling a private constructor of class 'test_implicitly_movable_rvalue_ref::B2'}}
89+
return b; // cxx20_2b-error {{calling a private constructor of class 'test_implicitly_movable_rvalue_ref::B2'}}
8990
}
9091
} // namespace test_implicitly_movable_rvalue_ref
9192

@@ -96,29 +97,36 @@ void func();
9697

9798
struct A1 {
9899
A1(const A1 &);
99-
A1(A1 &&) = delete; // cxx20-note {{'A1' has been explicitly marked deleted here}}
100+
A1(A1 &&) = delete; // cxx20_2b-note {{'A1' has been explicitly marked deleted here}}
101+
// expected-note@-1 {{'A1' has been explicitly marked deleted here}}
100102
};
101103
void test1() {
102104
try {
103105
func();
104106
} catch (A1 a) {
105-
throw a; // cxx20-error {{call to deleted constructor of 'test_throw_parameter::A1'}}
107+
throw a; // cxx20_2b-error {{call to deleted constructor of 'test_throw_parameter::A1'}}
106108
}
107109
}
108110

109111
struct A2 {
110112
A2(const A2 &);
111113

112114
private:
113-
A2(A2 &&); // cxx20-note {{declared private here}}
115+
A2(A2 &&); // cxx20_2b-note {{declared private here}}
114116
};
115117
void test2() {
116118
try {
117119
func();
118120
} catch (A2 a) {
119-
throw a; // cxx20-error {{calling a private constructor of class 'test_throw_parameter::A2'}}
121+
throw a; // cxx20_2b-error {{calling a private constructor of class 'test_throw_parameter::A2'}}
120122
}
121123
}
124+
125+
void test3(A1 a) try {
126+
func();
127+
} catch (...) {
128+
throw a; // expected-error {{call to deleted constructor of 'test_throw_parameter::A1'}}
129+
}
122130
} // namespace test_throw_parameter
123131

124132
// In C++20, during the first overload resolution, the selected function no
@@ -128,42 +136,42 @@ class C {};
128136

129137
struct A1 {
130138
operator C() &&;
131-
operator C() const & = delete; // cxx11_14_17-note {{'operator C' has been explicitly marked deleted here}}
139+
operator C() const & = delete; // cxx11_17-note {{'operator C' has been explicitly marked deleted here}}
132140
};
133141
C test1() {
134142
A1 a;
135-
return a; // cxx11_14_17-error {{conversion function from 'test_non_ctor_conversion::A1' to 'test_non_ctor_conversion::C' invokes a deleted function}}
143+
return a; // cxx11_17-error {{conversion function from 'test_non_ctor_conversion::A1' to 'test_non_ctor_conversion::C' invokes a deleted function}}
136144
}
137145

138146
struct A2 {
139147
operator C() &&;
140148

141149
private:
142-
operator C() const &; // cxx11_14_17-note {{declared private here}}
150+
operator C() const &; // cxx11_17-note {{declared private here}}
143151
};
144152
C test2() {
145153
A2 a;
146-
return a; // cxx11_14_17-error {{'operator C' is a private member of 'test_non_ctor_conversion::A2'}}
154+
return a; // cxx11_17-error {{'operator C' is a private member of 'test_non_ctor_conversion::A2'}}
147155
}
148156

149157
struct B1 {
150158
operator C() const &;
151-
operator C() && = delete; // cxx20-note {{'operator C' has been explicitly marked deleted here}}
159+
operator C() && = delete; // cxx20_2b-note {{'operator C' has been explicitly marked deleted here}}
152160
};
153161
C test3() {
154162
B1 b;
155-
return b; // cxx20-error {{conversion function from 'test_non_ctor_conversion::B1' to 'test_non_ctor_conversion::C' invokes a deleted function}}
163+
return b; // cxx20_2b-error {{conversion function from 'test_non_ctor_conversion::B1' to 'test_non_ctor_conversion::C' invokes a deleted function}}
156164
}
157165

158166
struct B2 {
159167
operator C() const &;
160168

161169
private:
162-
operator C() &&; // cxx20-note {{declared private here}}
170+
operator C() &&; // cxx20_2b-note {{declared private here}}
163171
};
164172
C test4() {
165173
B2 b;
166-
return b; // cxx20-error {{'operator C' is a private member of 'test_non_ctor_conversion::B2'}}
174+
return b; // cxx20_2b-error {{'operator C' is a private member of 'test_non_ctor_conversion::B2'}}
167175
}
168176
} // namespace test_non_ctor_conversion
169177

@@ -182,114 +190,114 @@ struct NeedRvalueRef {
182190
NeedRvalueRef(B2 &&);
183191
};
184192
struct NeedValue {
185-
NeedValue(A1); // cxx11_14_17-note 2 {{passing argument to parameter here}}
193+
NeedValue(A1); // cxx11_17-note 2 {{passing argument to parameter here}}
186194
NeedValue(A2);
187-
NeedValue(B1); // cxx20-note 2 {{passing argument to parameter here}}
195+
NeedValue(B1); // cxx20_2b-note 2 {{passing argument to parameter here}}
188196
NeedValue(B2);
189197
};
190198

191199
struct A1 {
192200
A1();
193201
A1(A1 &&);
194-
A1(const A1 &) = delete; // cxx11_14_17-note 3 {{'A1' has been explicitly marked deleted here}}
202+
A1(const A1 &) = delete; // cxx11_17-note 3 {{'A1' has been explicitly marked deleted here}}
195203
};
196204
NeedValue test_1_1() {
197205
// not rvalue reference
198206
// same type
199207
A1 a;
200-
return a; // cxx11_14_17-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::A1'}}
208+
return a; // cxx11_17-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::A1'}}
201209
}
202210
class DerivedA1 : public A1 {};
203211
A1 test_1_2() {
204212
// rvalue reference
205213
// not same type
206214
DerivedA1 a;
207-
return a; // cxx11_14_17-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::A1'}}
215+
return a; // cxx11_17-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::A1'}}
208216
}
209217
NeedValue test_1_3() {
210218
// not rvalue reference
211219
// not same type
212220
DerivedA1 a;
213-
return a; // cxx11_14_17-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::A1'}}
221+
return a; // cxx11_17-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::A1'}}
214222
}
215223

216224
struct A2 {
217225
A2();
218226
A2(A2 &&);
219227

220228
private:
221-
A2(const A2 &); // cxx11_14_17-note 3 {{declared private here}}
229+
A2(const A2 &); // cxx11_17-note 3 {{declared private here}}
222230
};
223231
NeedValue test_2_1() {
224232
// not rvalue reference
225233
// same type
226234
A2 a;
227-
return a; // cxx11_14_17-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::A2'}}
235+
return a; // cxx11_17-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::A2'}}
228236
}
229237
class DerivedA2 : public A2 {};
230238
A2 test_2_2() {
231239
// rvalue reference
232240
// not same type
233241
DerivedA2 a;
234-
return a; // cxx11_14_17-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::A2'}}
242+
return a; // cxx11_17-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::A2'}}
235243
}
236244
NeedValue test_2_3() {
237245
// not rvalue reference
238246
// not same type
239247
DerivedA2 a;
240-
return a; // cxx11_14_17-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::A2'}}
248+
return a; // cxx11_17-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::A2'}}
241249
}
242250

243251
struct B1 {
244252
B1();
245253
B1(const B1 &);
246-
B1(B1 &&) = delete; // cxx20-note 3 {{'B1' has been explicitly marked deleted here}}
254+
B1(B1 &&) = delete; // cxx20_2b-note 3 {{'B1' has been explicitly marked deleted here}}
247255
};
248256
NeedValue test_3_1() {
249257
// not rvalue reference
250258
// same type
251259
B1 b;
252-
return b; // cxx20-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::B1'}}
260+
return b; // cxx20_2b-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::B1'}}
253261
}
254262
class DerivedB1 : public B1 {};
255263
B1 test_3_2() {
256264
// rvalue reference
257265
// not same type
258266
DerivedB1 b;
259-
return b; // cxx20-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::B1'}}
267+
return b; // cxx20_2b-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::B1'}}
260268
}
261269
NeedValue test_3_3() {
262270
// not rvalue reference
263271
// not same type
264272
DerivedB1 b;
265-
return b; // cxx20-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::B1'}}
273+
return b; // cxx20_2b-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::B1'}}
266274
}
267275

268276
struct B2 {
269277
B2();
270278
B2(const B2 &);
271279

272280
private:
273-
B2(B2 &&); // cxx20-note 3 {{declared private here}}
281+
B2(B2 &&); // cxx20_2b-note 3 {{declared private here}}
274282
};
275283
NeedValue test_4_1() {
276284
// not rvalue reference
277285
// same type
278286
B2 b;
279-
return b; // cxx20-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::B2'}}
287+
return b; // cxx20_2b-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::B2'}}
280288
}
281289
class DerivedB2 : public B2 {};
282290
B2 test_4_2() {
283291
// rvalue reference
284292
// not same type
285293
DerivedB2 b;
286-
return b; // cxx20-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::B2'}}
294+
return b; // cxx20_2b-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::B2'}}
287295
}
288296
NeedValue test_4_3() {
289297
// not rvalue reference
290298
// not same type
291299
DerivedB2 b;
292-
return b; // cxx20-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::B2'}}
300+
return b; // cxx20_2b-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::B2'}}
293301
}
294302
} // namespace test_ctor_param_rvalue_ref
295303

@@ -298,21 +306,21 @@ namespace test_lvalue_ref_is_not_moved_from {
298306
struct Target {};
299307
// expected-note@-1 {{candidate constructor (the implicit copy constructor) not viable}}
300308
// expected-note@-2 {{candidate constructor (the implicit move constructor) not viable}}
301-
// cxx11_14_17-note@-3 {{candidate constructor (the implicit copy constructor) not viable}}
302-
// cxx11_14_17-note@-4 {{candidate constructor (the implicit move constructor) not viable}}
309+
// cxx11_17-note@-3 {{candidate constructor (the implicit copy constructor) not viable}}
310+
// cxx11_17-note@-4 {{candidate constructor (the implicit move constructor) not viable}}
303311

304312
struct CopyOnly {
305-
CopyOnly(CopyOnly&&) = delete; // cxx20-note {{has been explicitly marked deleted here}}
313+
CopyOnly(CopyOnly&&) = delete; // cxx20_2b-note {{has been explicitly marked deleted here}}
306314
CopyOnly(CopyOnly&);
307-
operator Target() && = delete; // cxx20-note {{has been explicitly marked deleted here}}
315+
operator Target() && = delete; // cxx20_2b-note {{has been explicitly marked deleted here}}
308316
operator Target() &;
309317
};
310318

311319
struct MoveOnly {
312320
MoveOnly(MoveOnly&&); // expected-note {{copy constructor is implicitly deleted because}}
313-
// cxx11_14_17-note@-1 {{copy constructor is implicitly deleted because}}
321+
// cxx11_17-note@-1 {{copy constructor is implicitly deleted because}}
314322
operator Target() &&; // expected-note {{candidate function not viable}}
315-
// cxx11_14_17-note@-1 {{candidate function not viable}}
323+
// cxx11_17-note@-1 {{candidate function not viable}}
316324
};
317325

318326
extern CopyOnly copyonly;
@@ -325,7 +333,7 @@ CopyOnly t1() {
325333

326334
CopyOnly t2() {
327335
CopyOnly&& r = static_cast<CopyOnly&&>(copyonly);
328-
return r; // cxx20-error {{call to deleted constructor}}
336+
return r; // cxx20_2b-error {{call to deleted constructor}}
329337
}
330338

331339
MoveOnly t3() {
@@ -335,7 +343,7 @@ MoveOnly t3() {
335343

336344
MoveOnly t4() {
337345
MoveOnly&& r = static_cast<MoveOnly&&>(moveonly);
338-
return r; // cxx11_14_17-error {{call to implicitly-deleted copy constructor}}
346+
return r; // cxx11_17-error {{call to implicitly-deleted copy constructor}}
339347
}
340348

341349
Target t5() {
@@ -345,7 +353,7 @@ Target t5() {
345353

346354
Target t6() {
347355
CopyOnly&& r = static_cast<CopyOnly&&>(copyonly);
348-
return r; // cxx20-error {{invokes a deleted function}}
356+
return r; // cxx20_2b-error {{invokes a deleted function}}
349357
}
350358

351359
Target t7() {
@@ -355,7 +363,7 @@ Target t7() {
355363

356364
Target t8() {
357365
MoveOnly&& r = static_cast<MoveOnly&&>(moveonly);
358-
return r; // cxx11_14_17-error {{no viable conversion}}
366+
return r; // cxx11_17-error {{no viable conversion}}
359367
}
360368

361369
} // namespace test_lvalue_ref_is_not_moved_from
@@ -397,3 +405,46 @@ Target t4() {
397405
}
398406

399407
} // namespace test_rvalue_ref_to_nonobject
408+
409+
namespace test_simpler_implicit_move {
410+
411+
struct CopyOnly {
412+
CopyOnly();
413+
CopyOnly(CopyOnly &);
414+
};
415+
struct MoveOnly {
416+
MoveOnly();
417+
MoveOnly(MoveOnly &&);
418+
};
419+
MoveOnly &&rref();
420+
421+
MoveOnly &&test1(MoveOnly &&w) {
422+
return w; // expected-error {{cannot bind to lvalue of type}}
423+
}
424+
425+
CopyOnly test2(bool b) {
426+
static CopyOnly w1;
427+
CopyOnly w2;
428+
if (b) {
429+
return w1;
430+
} else {
431+
return w2;
432+
}
433+
}
434+
435+
template <class T> T &&test3(T &&x) { return x; } // expected-error {{cannot bind to lvalue of type}}
436+
template MoveOnly& test3<MoveOnly&>(MoveOnly&);
437+
template MoveOnly&& test3<MoveOnly>(MoveOnly&&); // expected-note {{in instantiation of function template specialization}}
438+
439+
MoveOnly &&test4() {
440+
MoveOnly &&x = rref();
441+
return x; // expected-error {{cannot bind to lvalue of type}}
442+
}
443+
444+
void test5() try {
445+
CopyOnly x;
446+
throw x;
447+
} catch (...) {
448+
}
449+
450+
} // namespace test_simpler_implicit_move

0 commit comments

Comments
 (0)