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
+
7
+ // Run without -verify to check the order of errors we show.
6
8
// RUN: not %clang_cc1 -std=c++20 -fsyntax-only %s -fcxx-exceptions -fexceptions -Wunused-result 2>&1 | FileCheck %s
7
9
8
10
void no_coroutine_traits_bad_arg_await () {
@@ -339,18 +341,20 @@ Handle mixed_return_value() {
339
341
co_await a; // expected-note {{function is a coroutine due to use of 'co_await' here}}
340
342
return 0 ; // expected-error {{return statement not allowed in coroutine}}
341
343
// expected-error@-1 {{no viable conversion from returned value of type}}
344
+ // Check that we first show that return is not allowed in coroutine.
345
+ // The error about bad conversion is most likely spurious so we prefer to have it afterwards.
342
346
// CHECK-NOT: error: no viable conversion from returned value of type
343
347
// CHECK: error: return statement not allowed in coroutine
344
348
// CHECK: error: no viable conversion from returned value of type
345
349
}
346
350
347
351
Handle mixed_return_value_return_first (bool b) {
348
- if (b) {
349
- return 0 ; // expected-error {{no viable conversion from returned value of type}}
350
- // expected-error@-1 {{return statement not allowed in coroutine}}
351
- }
352
- co_await a; // expected-note {{function is a coroutine due to use of 'co_await' here}}
353
- co_return 0 ; // expected-error {{no member named 'return_value' in 'promise_handle'}}
352
+ if (b) {
353
+ return 0 ; // expected-error {{no viable conversion from returned value of type}}
354
+ // expected-error@-1 {{return statement not allowed in coroutine}}
355
+ }
356
+ co_await a; // expected-note {{function is a coroutine due to use of 'co_await' here}}
357
+ co_return 0 ; // expected-error {{no member named 'return_value' in 'promise_handle'}}
354
358
}
355
359
356
360
Handle mixed_multiple_returns (bool b) {
@@ -359,6 +363,7 @@ Handle mixed_multiple_returns(bool b) {
359
363
// expected-error@-1 {{return statement not allowed in coroutine}}
360
364
}
361
365
co_await a; // expected-note {{function is a coroutine due to use of 'co_await' here}}
366
+ // The error 'return statement not allowed in coroutine' should appear only once.
362
367
return 0 ; // expected-error {{no viable conversion from returned value of type}}
363
368
}
364
369
0 commit comments