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
5
6
6
7
namespace test_delete_function {
7
8
struct A1 {
@@ -54,38 +55,38 @@ B2 test4() {
54
55
namespace test_implicitly_movable_rvalue_ref {
55
56
struct A1 {
56
57
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}}
58
59
};
59
60
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'}}
61
62
}
62
63
63
64
struct A2 {
64
65
A2 (A2 &&);
65
66
66
67
private:
67
- A2 (const A2 &); // cxx11_14_17 -note {{declared private here}}
68
+ A2 (const A2 &); // cxx11_17 -note {{declared private here}}
68
69
};
69
70
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'}}
71
72
}
72
73
73
74
struct B1 {
74
75
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}}
76
77
};
77
78
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'}}
79
80
}
80
81
81
82
struct B2 {
82
83
B2 (const B2 &);
83
84
84
85
private:
85
- B2 (B2 &&); // cxx20 -note {{declared private here}}
86
+ B2 (B2 &&); // cxx20_2b -note {{declared private here}}
86
87
};
87
88
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'}}
89
90
}
90
91
} // namespace test_implicitly_movable_rvalue_ref
91
92
@@ -96,29 +97,36 @@ void func();
96
97
97
98
struct A1 {
98
99
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}}
100
102
};
101
103
void test1 () {
102
104
try {
103
105
func ();
104
106
} 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'}}
106
108
}
107
109
}
108
110
109
111
struct A2 {
110
112
A2 (const A2 &);
111
113
112
114
private:
113
- A2 (A2 &&); // cxx20 -note {{declared private here}}
115
+ A2 (A2 &&); // cxx20_2b -note {{declared private here}}
114
116
};
115
117
void test2 () {
116
118
try {
117
119
func ();
118
120
} 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'}}
120
122
}
121
123
}
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
+ }
122
130
} // namespace test_throw_parameter
123
131
124
132
// In C++20, during the first overload resolution, the selected function no
@@ -128,42 +136,42 @@ class C {};
128
136
129
137
struct A1 {
130
138
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}}
132
140
};
133
141
C test1 () {
134
142
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}}
136
144
}
137
145
138
146
struct A2 {
139
147
operator C () &&;
140
148
141
149
private:
142
- operator C () const &; // cxx11_14_17 -note {{declared private here}}
150
+ operator C () const &; // cxx11_17 -note {{declared private here}}
143
151
};
144
152
C test2 () {
145
153
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'}}
147
155
}
148
156
149
157
struct B1 {
150
158
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}}
152
160
};
153
161
C test3 () {
154
162
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}}
156
164
}
157
165
158
166
struct B2 {
159
167
operator C () const &;
160
168
161
169
private:
162
- operator C () &&; // cxx20 -note {{declared private here}}
170
+ operator C () &&; // cxx20_2b -note {{declared private here}}
163
171
};
164
172
C test4 () {
165
173
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'}}
167
175
}
168
176
} // namespace test_non_ctor_conversion
169
177
@@ -182,114 +190,114 @@ struct NeedRvalueRef {
182
190
NeedRvalueRef (B2 &&);
183
191
};
184
192
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}}
186
194
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}}
188
196
NeedValue (B2);
189
197
};
190
198
191
199
struct A1 {
192
200
A1 ();
193
201
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}}
195
203
};
196
204
NeedValue test_1_1 () {
197
205
// not rvalue reference
198
206
// same type
199
207
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'}}
201
209
}
202
210
class DerivedA1 : public A1 {};
203
211
A1 test_1_2 () {
204
212
// rvalue reference
205
213
// not same type
206
214
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'}}
208
216
}
209
217
NeedValue test_1_3 () {
210
218
// not rvalue reference
211
219
// not same type
212
220
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'}}
214
222
}
215
223
216
224
struct A2 {
217
225
A2 ();
218
226
A2 (A2 &&);
219
227
220
228
private:
221
- A2 (const A2 &); // cxx11_14_17 -note 3 {{declared private here}}
229
+ A2 (const A2 &); // cxx11_17 -note 3 {{declared private here}}
222
230
};
223
231
NeedValue test_2_1 () {
224
232
// not rvalue reference
225
233
// same type
226
234
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'}}
228
236
}
229
237
class DerivedA2 : public A2 {};
230
238
A2 test_2_2 () {
231
239
// rvalue reference
232
240
// not same type
233
241
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'}}
235
243
}
236
244
NeedValue test_2_3 () {
237
245
// not rvalue reference
238
246
// not same type
239
247
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'}}
241
249
}
242
250
243
251
struct B1 {
244
252
B1 ();
245
253
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}}
247
255
};
248
256
NeedValue test_3_1 () {
249
257
// not rvalue reference
250
258
// same type
251
259
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'}}
253
261
}
254
262
class DerivedB1 : public B1 {};
255
263
B1 test_3_2 () {
256
264
// rvalue reference
257
265
// not same type
258
266
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'}}
260
268
}
261
269
NeedValue test_3_3 () {
262
270
// not rvalue reference
263
271
// not same type
264
272
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'}}
266
274
}
267
275
268
276
struct B2 {
269
277
B2 ();
270
278
B2 (const B2 &);
271
279
272
280
private:
273
- B2 (B2 &&); // cxx20 -note 3 {{declared private here}}
281
+ B2 (B2 &&); // cxx20_2b -note 3 {{declared private here}}
274
282
};
275
283
NeedValue test_4_1 () {
276
284
// not rvalue reference
277
285
// same type
278
286
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'}}
280
288
}
281
289
class DerivedB2 : public B2 {};
282
290
B2 test_4_2 () {
283
291
// rvalue reference
284
292
// not same type
285
293
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'}}
287
295
}
288
296
NeedValue test_4_3 () {
289
297
// not rvalue reference
290
298
// not same type
291
299
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'}}
293
301
}
294
302
} // namespace test_ctor_param_rvalue_ref
295
303
@@ -298,21 +306,21 @@ namespace test_lvalue_ref_is_not_moved_from {
298
306
struct Target {};
299
307
// expected-note@-1 {{candidate constructor (the implicit copy constructor) not viable}}
300
308
// 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}}
303
311
304
312
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}}
306
314
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}}
308
316
operator Target () &;
309
317
};
310
318
311
319
struct MoveOnly {
312
320
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}}
314
322
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}}
316
324
};
317
325
318
326
extern CopyOnly copyonly;
@@ -325,7 +333,7 @@ CopyOnly t1() {
325
333
326
334
CopyOnly t2 () {
327
335
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}}
329
337
}
330
338
331
339
MoveOnly t3 () {
@@ -335,7 +343,7 @@ MoveOnly t3() {
335
343
336
344
MoveOnly t4 () {
337
345
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}}
339
347
}
340
348
341
349
Target t5 () {
@@ -345,7 +353,7 @@ Target t5() {
345
353
346
354
Target t6 () {
347
355
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}}
349
357
}
350
358
351
359
Target t7 () {
@@ -355,7 +363,7 @@ Target t7() {
355
363
356
364
Target t8 () {
357
365
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}}
359
367
}
360
368
361
369
} // namespace test_lvalue_ref_is_not_moved_from
@@ -397,3 +405,46 @@ Target t4() {
397
405
}
398
406
399
407
} // 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