3
3
4
4
// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=expected,cxx20_23,cxx23 %s -fcxx-exceptions -fexceptions -Wunused-result
5
5
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx14_20,cxx20_23 %s -fcxx-exceptions -fexceptions -Wunused-result
6
+ // RUN: not %clang_cc1 -std=c++20 -fsyntax-only %s -fcxx-exceptions -fexceptions -Wunused-result 2>&1 | FileCheck %s
6
7
7
8
void no_coroutine_traits_bad_arg_await () {
8
9
co_await a; // expected-error {{include <coroutine>}}
@@ -209,6 +210,22 @@ void mixed_yield_invalid() {
209
210
return ; // expected-error {{return statement not allowed in coroutine}}
210
211
}
211
212
213
+ void mixed_yield_return_first (bool b) {
214
+ if (b) {
215
+ return ; // expected-error {{return statement not allowed in coroutine}}
216
+ }
217
+ co_yield 0 ; // expected-note {{function is a coroutine due to use of 'co_yield'}}
218
+ }
219
+
220
+ template <typename T>
221
+ void mixed_return_for_range (bool b, T t) {
222
+ if (b) {
223
+ return ; // expected-error {{return statement not allowed in coroutine}}
224
+ }
225
+ for co_await (auto i : t){}; // expected-warning {{'for co_await' belongs to CoroutineTS instead of C++20, which is deprecated}}
226
+ // expected-note@-1 {{function is a coroutine due to use of 'co_await'}}
227
+ }
228
+
212
229
template <class T >
213
230
void mixed_yield_template (T) {
214
231
co_yield blah; // expected-error {{use of undeclared identifier}}
@@ -267,6 +284,13 @@ void mixed_coreturn(void_tag, bool b) {
267
284
return ; // expected-error {{not allowed in coroutine}}
268
285
}
269
286
287
+ void mixed_coreturn_return_first (void_tag, bool b) {
288
+ if (b)
289
+ return ; // expected-error {{not allowed in coroutine}}
290
+ else
291
+ co_return ; // expected-note {{use of 'co_return'}}
292
+ }
293
+
270
294
void mixed_coreturn_invalid (bool b) {
271
295
if (b)
272
296
co_return ; // expected-note {{use of 'co_return'}}
@@ -296,8 +320,8 @@ void mixed_coreturn_template2(bool b, T) {
296
320
297
321
struct promise_handle ;
298
322
299
- struct Handle : std::coroutine_handle<promise_handle> { // expected-note 2{{candidate constructor (the implicit copy constructor) not viable}}
300
- // expected-note@-1 2{{candidate constructor (the implicit move constructor) not viable}}
323
+ struct Handle : std::coroutine_handle<promise_handle> { // expected-note 4{{ not viable}}
324
+ // expected-note@-1 4{{ not viable}}
301
325
using promise_type = promise_handle;
302
326
};
303
327
@@ -315,6 +339,9 @@ Handle mixed_return_value() {
315
339
co_await a; // expected-note {{function is a coroutine due to use of 'co_await' here}}
316
340
return 0 ; // expected-error {{return statement not allowed in coroutine}}
317
341
// expected-error@-1 {{no viable conversion from returned value of type}}
342
+ // CHECK-NOT: error: no viable conversion from returned value of type
343
+ // CHECK: error: return statement not allowed in coroutine
344
+ // CHECK: error: no viable conversion from returned value of type
318
345
}
319
346
320
347
Handle mixed_return_value_return_first (bool b) {
@@ -326,6 +353,15 @@ Handle mixed_return_value_return_first(bool b) {
326
353
co_return 0 ; // expected-error {{no member named 'return_value' in 'promise_handle'}}
327
354
}
328
355
356
+ Handle mixed_multiple_returns (bool b) {
357
+ if (b) {
358
+ return 0 ; // expected-error {{no viable conversion from returned value of type}}
359
+ // expected-error@-1 {{return statement not allowed in coroutine}}
360
+ }
361
+ co_await a; // expected-note {{function is a coroutine due to use of 'co_await' here}}
362
+ return 0 ; // expected-error {{no viable conversion from returned value of type}}
363
+ }
364
+
329
365
struct CtorDtor {
330
366
CtorDtor () {
331
367
co_yield 0 ; // expected-error {{'co_yield' cannot be used in a constructor}}
0 commit comments