From f55ae7e819566bd5922566132299021e1a9e6677 Mon Sep 17 00:00:00 2001 From: Mohit Mishra Date: Tue, 17 Nov 2026 20:17:21 +0530 Subject: [PATCH 1/4] Keep needed parentheses around co_await and co_yield in generated C++. [GH #546] --- src/cp_gen_be.c | 20 +++++- .../gh-546-coroutine-parens.txt | 13 ++++ tests/expectations/edg_x86_32_cp/imported.log | 1 - tests/expectations/edg_x86_64_cp/imported.log | 1 - .../tests/changes/.GH546.rto/default.1.1.txt | 1 + tests/tests/changes/GH546.sft.cpp | 72 +++++++++++++++++++ .../edg_x86_32_cp.1.1.txt | 6 -- .../edg_x86_64_cp.1.1.txt | 6 -- 8 files changed, 103 insertions(+), 17 deletions(-) create mode 100644 src/pending_changes/gh-546-coroutine-parens.txt create mode 100644 tests/tests/changes/.GH546.rto/default.1.1.txt create mode 100644 tests/tests/changes/GH546.sft.cpp delete mode 100644 tests/tests/imported/clang/cpp/SemaCXX/.warn-unsequenced-coro.rto/edg_x86_32_cp.1.1.txt delete mode 100644 tests/tests/imported/clang/cpp/SemaCXX/.warn-unsequenced-coro.rto/edg_x86_64_cp.1.1.txt diff --git a/src/cp_gen_be.c b/src/cp_gen_be.c index fdc3911326..16c3d988c3 100644 --- a/src/cp_gen_be.c +++ b/src/cp_gen_be.c @@ -986,7 +986,7 @@ static constexpr a_byte generated_precedence[(int)eok_last+1] = { PREC_POSTFIX, /* eok_va_start_single_operand */ PREC_LOWEST, /* eok_lvalue */ PREC_PREFIX, /* eok_await */ - PREC_PREFIX, /* eok_yield */ + PREC_ASSIGNMENT, /* eok_yield */ PREC_PRIMARY, /* eok_splice */ PREC_LOWEST, /* eok_error */ PREC_LOWEST /* eok_last */ @@ -19959,6 +19959,7 @@ gen_expr that might end up generating this expr as a temporary. #endif /* BUILTIN_FUNCTIONS_ENABLED */ case enk_yield: /* yield expression: generate "co_yield ". */ + if (need_parens) write_tok_ch('('); write_tok_str("co_yield "); expr = expr->variant.await_info.operand; /* Skip nodes implementing the binding of the operand to the call. */ @@ -19989,13 +19990,26 @@ gen_expr that might end up generating this expr as a temporary. operand (which corresponds to the actual operand of the yield statement). */ expr = expr->next->next; - gen_expression(expr); + /* The operand of co_yield is an assignment-expression, so it needs + parentheses only if it is a comma operation, e.g., + "co_yield (f(), g())". */ + gen_expr(expr, parens_may_be_needed(PREC_COMMA, expr), + /*obj_expr_of_mfunc_operator=*/FALSE); + if (need_parens) write_tok_ch(')'); break; case enk_await: + if (need_parens) write_tok_ch('('); write_tok_str((msvc_is_generated_code_target && msvc_target_version_number < 1900) ? "__await " : "co_await "); - gen_expression(expr->variant.await_info.operand); + /* The operand of co_await is a cast-expression, like the operand of + a unary operator, so it may need parentheses, e.g., + "co_await (c ? x : y)". */ + gen_expr(expr->variant.await_info.operand, + parens_may_be_needed(PREC_PREFIX, + expr->variant.await_info.operand), + /*obj_expr_of_mfunc_operator=*/FALSE); + if (need_parens) write_tok_ch(')'); break; case enk_fold: gen_fold_expression(expr); diff --git a/src/pending_changes/gh-546-coroutine-parens.txt b/src/pending_changes/gh-546-coroutine-parens.txt new file mode 100644 index 0000000000..892012438a --- /dev/null +++ b/src/pending_changes/gh-546-coroutine-parens.txt @@ -0,0 +1,13 @@ +[GH #546] +Parentheses around co_await and co_yield in generated C++ + +The C++-generating back end could drop parentheses that are needed to keep +the meaning of co_await and co_yield expressions, so the generated code was +rejected or had a different meaning. For example: + + int i = (co_await a).m; // Was generated as "co_await a.m". + co_await (c ? x : y); // Was generated as "co_await c ? x : y". + co_yield (first(), second()); // Was generated as + // "co_yield first(), second()". + +Parentheses are now added where they are needed. diff --git a/tests/expectations/edg_x86_32_cp/imported.log b/tests/expectations/edg_x86_32_cp/imported.log index 80dd7714e7..68a94244ff 100644 --- a/tests/expectations/edg_x86_32_cp/imported.log +++ b/tests/expectations/edg_x86_32_cp/imported.log @@ -332,7 +332,6 @@ clang/cpp/SemaCXX/warn-new-overaligned-3.sft.cpp:fp:-DTEST_NUMBER=1:FAIL: clang/cpp/SemaCXX/warn-new-overaligned.sft.cpp:fp:-DTEST_NUMBER=1 --c++03:FAIL: clang/cpp/SemaCXX/warn-overaligned-type-thrown.sft.cpp:fp:-DTEST_NUMBER=18 --c++11 --exceptions --exceptions -DNODIAG --target linux_aarch64:REQUIREMENTS NOT MET: clang/cpp/SemaCXX/warn-reorder-ctor-initialization.sft.cpp:fp:-DTEST_NUMBER=1:FAIL: -clang/cpp/SemaCXX/warn-unsequenced-coro.sft.cpp:fp:-DTEST_NUMBER=1 --c++20:FAIL: clang/cpp/SemaCXX/windows-arm-valist.sft.cpp:fp:-DTEST_NUMBER=1 -w --c++11:PASS: clang/cpp/SemaTemplate/atomics.sft.cpp:fp:-DTEST_NUMBER=1:PASS: clang/cpp/SemaTemplate/dependent-expr.sft.cpp:fn:-DTEST_NUMBER=1 --c++20:ABORT: diff --git a/tests/expectations/edg_x86_64_cp/imported.log b/tests/expectations/edg_x86_64_cp/imported.log index f6dd23f368..ff1491cf6a 100644 --- a/tests/expectations/edg_x86_64_cp/imported.log +++ b/tests/expectations/edg_x86_64_cp/imported.log @@ -60,7 +60,6 @@ clang/cpp/SemaCXX/ms-exception-spec.sft.cpp:fn:-DTEST_NUMBER=1 --c++11 --ms_comp clang/cpp/SemaCXX/pr61460.sft.cpp:fn:-DTEST_NUMBER=1 --c++17:PASS: clang/cpp/SemaCXX/type-dependent-exprs.sft.cpp:fn:-DTEST_NUMBER=1:PASS: clang/cpp/SemaCXX/warn-reorder-ctor-initialization.sft.cpp:fp:-DTEST_NUMBER=1:FAIL: -clang/cpp/SemaCXX/warn-unsequenced-coro.sft.cpp:fp:-DTEST_NUMBER=1 --c++20:FAIL: clang/cpp/SemaTemplate/dependent-expr.sft.cpp:fn:-DTEST_NUMBER=1 --c++20:ABORT: clang/cpp/SemaTemplate/find-unexpanded-packs.sft.cpp:fn:-DTEST_NUMBER=1 --c++17:PASS: clang/cpp/SemaTemplate/fun-template-def.sft.cpp:fn:-DTEST_NUMBER=1 --c++03:PASS: diff --git a/tests/tests/changes/.GH546.rto/default.1.1.txt b/tests/tests/changes/.GH546.rto/default.1.1.txt new file mode 100644 index 0000000000..32fc82e916 --- /dev/null +++ b/tests/tests/changes/.GH546.rto/default.1.1.txt @@ -0,0 +1 @@ +fe_only -DTEST_NUMBER=1 --c++20 Test_name.c diff --git a/tests/tests/changes/GH546.sft.cpp b/tests/tests/changes/GH546.sft.cpp new file mode 100644 index 0000000000..a362aef782 --- /dev/null +++ b/tests/tests/changes/GH546.sft.cpp @@ -0,0 +1,72 @@ +//type:fp +//options:--c++20 +//remark:[GH #546] Parentheses around co_await and co_yield in generated C++ +// +// Without parentheses in the IL, the C++-generating back end dropped +// parentheses that are needed around a co_await or co_yield expression used +// as an operand, around a co_await operand with lower precedence, and around +// a comma operand of co_yield. + +namespace std { + template struct coroutine_handle; + template<> struct coroutine_handle<> { void *address(); }; + template struct coroutine_handle { + static coroutine_handle from_address(void *); + operator coroutine_handle<>() noexcept; + }; + template struct coroutine_traits { + using promise_type = typename R::promise_type; + }; +} + +struct suspend { + bool await_ready() noexcept; + void await_suspend(std::coroutine_handle<>) noexcept; + void await_resume() noexcept; +}; + +template +struct awaiter { + bool await_ready() noexcept; + void await_suspend(std::coroutine_handle<>) noexcept; + R await_resume() noexcept; +}; + +struct S { + int m; + void operator=(int); +}; + +struct task; +struct promise { + suspend initial_suspend() noexcept; + suspend final_suspend() noexcept; + void return_void(); + void unhandled_exception(); + task get_return_object(); + awaiter yield_value(S); +}; +struct task { using promise_type = promise; }; + +task outer() { + int i = (co_await awaiter{}).m; + (co_yield S{}) = 1; +} + +bool c; +task await_operand() { + co_await (c ? awaiter{} : awaiter{}); +} + +int first(); +S second(); +task yield_operand() { + co_yield (first(), second()); +} + +template +task dependent() { + (co_yield T{}) = 1; + co_return; +} +template task dependent(); diff --git a/tests/tests/imported/clang/cpp/SemaCXX/.warn-unsequenced-coro.rto/edg_x86_32_cp.1.1.txt b/tests/tests/imported/clang/cpp/SemaCXX/.warn-unsequenced-coro.rto/edg_x86_32_cp.1.1.txt deleted file mode 100644 index 0461e619b0..0000000000 --- a/tests/tests/imported/clang/cpp/SemaCXX/.warn-unsequenced-coro.rto/edg_x86_32_cp.1.1.txt +++ /dev/null @@ -1,6 +0,0 @@ -fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_version 999999 --c++20 Test_name.c -"SemaCXX/warn-unsequenced-coro.cpp", line 93: error: the operand to this co_await expression resolves to non-class "int" - co_await (i = 0), (std::suspend_always{}); - ^ - -1 error detected in the compilation of "Test_name.c". diff --git a/tests/tests/imported/clang/cpp/SemaCXX/.warn-unsequenced-coro.rto/edg_x86_64_cp.1.1.txt b/tests/tests/imported/clang/cpp/SemaCXX/.warn-unsequenced-coro.rto/edg_x86_64_cp.1.1.txt deleted file mode 100644 index 0461e619b0..0000000000 --- a/tests/tests/imported/clang/cpp/SemaCXX/.warn-unsequenced-coro.rto/edg_x86_64_cp.1.1.txt +++ /dev/null @@ -1,6 +0,0 @@ -fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_version 999999 --c++20 Test_name.c -"SemaCXX/warn-unsequenced-coro.cpp", line 93: error: the operand to this co_await expression resolves to non-class "int" - co_await (i = 0), (std::suspend_always{}); - ^ - -1 error detected in the compilation of "Test_name.c". From 7e016cd044d2c7169f77e58d0742281d8fbff7a3 Mon Sep 17 00:00:00 2001 From: Mohit Mishra Date: Wed, 18 Nov 2026 02:40:03 +0530 Subject: [PATCH 2/4] Add dependent co_yield cases to the GH546 test. [GH #546] --- tests/tests/changes/GH546.sft.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/tests/changes/GH546.sft.cpp b/tests/tests/changes/GH546.sft.cpp index a362aef782..7572adb425 100644 --- a/tests/tests/changes/GH546.sft.cpp +++ b/tests/tests/changes/GH546.sft.cpp @@ -5,7 +5,9 @@ // Without parentheses in the IL, the C++-generating back end dropped // parentheses that are needed around a co_await or co_yield expression used // as an operand, around a co_await operand with lower precedence, and around -// a comma operand of co_yield. +// a comma operand of co_yield. The dependent cases go through the IL (and +// so need the fix) only when templates are kept in the IL +// (ALL_TEMPLATE_INFO_IN_IL). namespace std { template struct coroutine_handle; @@ -45,6 +47,7 @@ struct promise { void unhandled_exception(); task get_return_object(); awaiter yield_value(S); + awaiter yield_value(int); }; struct task { using promise_type = promise; }; @@ -67,6 +70,8 @@ task yield_operand() { template task dependent() { (co_yield T{}) = 1; + int a = (co_yield 1) + 1; + int b = (co_yield T{}.m) + 1; co_return; } template task dependent(); From b7e729a5d7414baab2f24f445f815a4e370e0978 Mon Sep 17 00:00:00 2001 From: Mohit Mishra Date: Wed, 18 Nov 2026 12:05:48 +0530 Subject: [PATCH 3/4] Use type checks in the GH546 test; reword the Changes entry. [GH #546] --- .../gh-546-coroutine-parens.txt | 31 +++++++++++----- tests/tests/changes/GH546.sft.cpp | 36 ++++++++++++------- 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/pending_changes/gh-546-coroutine-parens.txt b/src/pending_changes/gh-546-coroutine-parens.txt index 892012438a..2ce5e7da3c 100644 --- a/src/pending_changes/gh-546-coroutine-parens.txt +++ b/src/pending_changes/gh-546-coroutine-parens.txt @@ -1,13 +1,26 @@ [GH #546] -Parentheses around co_await and co_yield in generated C++ +C++-generating back end: dropped parentheses around co_await and co_yield -The C++-generating back end could drop parentheses that are needed to keep -the meaning of co_await and co_yield expressions, so the generated code was -rejected or had a different meaning. For example: +With PARENS_IN_IL=0, the C++-generating back end could drop parentheses that +are needed to keep the meaning of co_await and co_yield expressions, so the +generated code was rejected or had a different meaning. For example, with +--c++20: - int i = (co_await a).m; // Was generated as "co_await a.m". - co_await (c ? x : y); // Was generated as "co_await c ? x : y". - co_yield (first(), second()); // Was generated as - // "co_yield first(), second()". + #include + struct S { int m; }; + struct A { + bool await_ready(); + void await_suspend(std::coroutine_handle<>); + S await_resume(); + }; + int f(); + std::task g(bool c, A x, A y) { + int i = (co_await x).m; // Was generated as "co_await x.m". + co_await (c ? x : y); // Was generated as "co_await c ? x : y". + co_yield (f(), i); // Was generated as "co_yield f(), i". + co_return i; + } -Parentheses are now added where they are needed. +A dependent co_yield expression used as an operand, as in +"(co_yield T{}) + 1", had the same problem when ALL_TEMPLATE_INFO_IN_IL is +also set. Parentheses are now added where they are needed. diff --git a/tests/tests/changes/GH546.sft.cpp b/tests/tests/changes/GH546.sft.cpp index 7572adb425..d474ea3ecc 100644 --- a/tests/tests/changes/GH546.sft.cpp +++ b/tests/tests/changes/GH546.sft.cpp @@ -2,12 +2,12 @@ //options:--c++20 //remark:[GH #546] Parentheses around co_await and co_yield in generated C++ // -// Without parentheses in the IL, the C++-generating back end dropped -// parentheses that are needed around a co_await or co_yield expression used -// as an operand, around a co_await operand with lower precedence, and around -// a comma operand of co_yield. The dependent cases go through the IL (and -// so need the fix) only when templates are kept in the IL -// (ALL_TEMPLATE_INFO_IN_IL). +// With PARENS_IN_IL=0, the C++-generating back end dropped parentheses that +// are needed around a co_await or co_yield expression used as an operand, +// around a co_await operand with lower precedence, and around a comma +// operand of co_yield. The static assertions fail if the generated code +// groups an expression differently. The dependent cases go through the IL +// (and so need the fix) only with ALL_TEMPLATE_INFO_IN_IL=1. namespace std { template struct coroutine_handle; @@ -19,6 +19,8 @@ namespace std { template struct coroutine_traits { using promise_type = typename R::promise_type; }; + template struct is_same { static constexpr bool value = false; }; + template struct is_same { static constexpr bool value = true; }; } struct suspend { @@ -48,30 +50,38 @@ struct promise { task get_return_object(); awaiter yield_value(S); awaiter yield_value(int); + awaiter yield_value(long); // A different type, to catch "co_yield (x + 2L)". }; struct task { using promise_type = promise; }; task outer() { - int i = (co_await awaiter{}).m; + auto i = (co_await awaiter{}).m; + static_assert(std::is_same::value); (co_yield S{}) = 1; + auto v = (co_yield 1) + 2L; + static_assert(std::is_same::value); } bool c; task await_operand() { - co_await (c ? awaiter{} : awaiter{}); + auto r = co_await (c ? awaiter{} : awaiter{}); + static_assert(std::is_same::value); } -int first(); -S second(); +long first(); +int second(); task yield_operand() { - co_yield (first(), second()); + auto v = co_yield (first(), second()); + static_assert(std::is_same::value); } template task dependent() { (co_yield T{}) = 1; - int a = (co_yield 1) + 1; - int b = (co_yield T{}.m) + 1; + auto a = (co_yield 1) + 2L; + static_assert(std::is_same::value); + auto b = (co_yield T{}.m) + 2L; + static_assert(std::is_same::value); co_return; } template task dependent(); From 81023c15694a127b6a13b938fb2cf02adbd383eb Mon Sep 17 00:00:00 2001 From: Mohit Mishra Date: Thu, 19 Nov 2026 10:17:10 +0530 Subject: [PATCH 4/4] Expand the GH546 test and use the usual Changes phrasing. [GH #546] Co-authored-by: Christof Meerwald --- .../gh-546-coroutine-parens.txt | 14 +- .../tests/changes/.GH546.rto/default.2.1.txt | 1 + .../tests/changes/.GH546.rto/default.3.1.txt | 1 + .../tests/changes/.GH546.rto/default.4.1.txt | 1 + tests/tests/changes/GH546.sft.cpp | 210 +++++++++++++++--- 5 files changed, 184 insertions(+), 43 deletions(-) create mode 100644 tests/tests/changes/.GH546.rto/default.2.1.txt create mode 100644 tests/tests/changes/.GH546.rto/default.3.1.txt create mode 100644 tests/tests/changes/.GH546.rto/default.4.1.txt diff --git a/src/pending_changes/gh-546-coroutine-parens.txt b/src/pending_changes/gh-546-coroutine-parens.txt index 2ce5e7da3c..b059d86895 100644 --- a/src/pending_changes/gh-546-coroutine-parens.txt +++ b/src/pending_changes/gh-546-coroutine-parens.txt @@ -1,10 +1,10 @@ [GH #546] C++-generating back end: dropped parentheses around co_await and co_yield -With PARENS_IN_IL=0, the C++-generating back end could drop parentheses that -are needed to keep the meaning of co_await and co_yield expressions, so the -generated code was rejected or had a different meaning. For example, with ---c++20: +In configurations with PARENS_IN_IL set to FALSE, the C++-generating back +end could drop parentheses that are needed to keep the meaning of co_await +and co_yield expressions, so the generated code was rejected or had a +different meaning. For example, with --c++20: #include struct S { int m; }; @@ -21,6 +21,6 @@ generated code was rejected or had a different meaning. For example, with co_return i; } -A dependent co_yield expression used as an operand, as in -"(co_yield T{}) + 1", had the same problem when ALL_TEMPLATE_INFO_IN_IL is -also set. Parentheses are now added where they are needed. +Additionally, in configurations with ALL_TEMPLATE_INFO_IN_IL set to TRUE, a +dependent co_yield expression used as an operand, as in "(co_yield T{}) + 1", +had the same problem. Parentheses are now added where they are needed. diff --git a/tests/tests/changes/.GH546.rto/default.2.1.txt b/tests/tests/changes/.GH546.rto/default.2.1.txt new file mode 100644 index 0000000000..32ab43e04f --- /dev/null +++ b/tests/tests/changes/.GH546.rto/default.2.1.txt @@ -0,0 +1 @@ +fe_only -DTEST_NUMBER=2 --c++20 --gnu_version 150200 Test_name.c diff --git a/tests/tests/changes/.GH546.rto/default.3.1.txt b/tests/tests/changes/.GH546.rto/default.3.1.txt new file mode 100644 index 0000000000..a0f1c6652b --- /dev/null +++ b/tests/tests/changes/.GH546.rto/default.3.1.txt @@ -0,0 +1 @@ +fe_only -DTEST_NUMBER=3 --c++20 --clang_version 230100 Test_name.c diff --git a/tests/tests/changes/.GH546.rto/default.4.1.txt b/tests/tests/changes/.GH546.rto/default.4.1.txt new file mode 100644 index 0000000000..1bbe45a65c --- /dev/null +++ b/tests/tests/changes/.GH546.rto/default.4.1.txt @@ -0,0 +1 @@ +fe_only -DTEST_NUMBER=4 --ms_c++20 --microsoft_version 1950 Test_name.c diff --git a/tests/tests/changes/GH546.sft.cpp b/tests/tests/changes/GH546.sft.cpp index d474ea3ecc..7b3db29523 100644 --- a/tests/tests/changes/GH546.sft.cpp +++ b/tests/tests/changes/GH546.sft.cpp @@ -1,13 +1,14 @@ //type:fp -//options:--c++20 +//options:--c++20:--c++20 --gnu_version 150200:--c++20 --clang_version 230100:--ms_c++20 --microsoft_version 1950 //remark:[GH #546] Parentheses around co_await and co_yield in generated C++ // -// With PARENS_IN_IL=0, the C++-generating back end dropped parentheses that -// are needed around a co_await or co_yield expression used as an operand, -// around a co_await operand with lower precedence, and around a comma -// operand of co_yield. The static assertions fail if the generated code -// groups an expression differently. The dependent cases go through the IL -// (and so need the fix) only with ALL_TEMPLATE_INFO_IN_IL=1. +// In configurations with PARENS_IN_IL set to FALSE, the C++-generating back +// end dropped parentheses that are needed around a co_await or co_yield +// expression used as an operand, and around some operands of co_await and +// co_yield. The static assertions fail if the generated code groups an +// expression differently. The dependent cases go through the IL (and so +// need the fix) only in configurations with ALL_TEMPLATE_INFO_IN_IL set to +// TRUE. namespace std { template struct coroutine_handle; @@ -19,21 +20,24 @@ namespace std { template struct coroutine_traits { using promise_type = typename R::promise_type; }; - template struct is_same { static constexpr bool value = false; }; - template struct is_same { static constexpr bool value = true; }; } +template +constexpr bool is_same_v = false; +template +constexpr bool is_same_v = true; + struct suspend { bool await_ready() noexcept; void await_suspend(std::coroutine_handle<>) noexcept; void await_resume() noexcept; }; -template +template struct awaiter { bool await_ready() noexcept; void await_suspend(std::coroutine_handle<>) noexcept; - R await_resume() noexcept; + T await_resume() noexcept; }; struct S { @@ -50,38 +54,172 @@ struct promise { task get_return_object(); awaiter yield_value(S); awaiter yield_value(int); - awaiter yield_value(long); // A different type, to catch "co_yield (x + 2L)". }; struct task { using promise_type = promise; }; -task outer() { - auto i = (co_await awaiter{}).m; - static_assert(std::is_same::value); - (co_yield S{}) = 1; - auto v = (co_yield 1) + 2L; - static_assert(std::is_same::value); +namespace await_expression { + /* The awaited temporary is not parenthesized for any other reason, so + this checks the co_await expression as the object of ".". */ + task f() { + auto i = (co_await awaiter{}).m; + static_assert(is_same_v); + co_return; + } } -bool c; -task await_operand() { - auto r = co_await (c ? awaiter{} : awaiter{}); - static_assert(std::is_same::value); +namespace await_operand { + /* The operand of co_await is a cast-expression, so a comma or an + assignment operand needs parentheses. */ + awaiter x, y; + task comma() { + auto r = co_await (void(), awaiter{}); + static_assert(is_same_v); + co_return; + } + task assignment() { + auto r = co_await (x = y); + static_assert(is_same_v); + co_return; + } } -long first(); -int second(); -task yield_operand() { - auto v = co_yield (first(), second()); - static_assert(std::is_same::value); +namespace yield_expression { + /* A yield-expression is an assignment-expression, so it needs + parentheses as the operand of an assignment, conditional, or comma + operation. */ + task assignment() { + (co_yield S{}) = 1; + co_return; + } + task operand() { + auto a = (co_yield 1) + 2L; + auto b = co_yield 1 + 2L; + auto c = co_yield (1 + 2L); + auto d = (co_yield 1 + 2L); + static_assert(is_same_v); + static_assert(is_same_v); + static_assert(is_same_v); + static_assert(is_same_v); + co_return; + } + task conditional() { + auto a = (co_yield 1) ? 2L : 3L; + auto b = co_yield 1 ? 2L : 3L; + auto c = co_yield (1 ? 2L : 3L); + auto d = (co_yield 1 ? 2L : 3L); + static_assert(is_same_v); + static_assert(is_same_v); + static_assert(is_same_v); + static_assert(is_same_v); + co_return; + } + task comma() { + int i = 0; + auto a = ((co_yield 1), 2L); + auto b = (++i, (co_yield 1)); + static_assert(is_same_v); + static_assert(is_same_v); + co_return; + } } -template -task dependent() { - (co_yield T{}) = 1; - auto a = (co_yield 1) + 2L; - static_assert(std::is_same::value); - auto b = (co_yield T{}.m) + 2L; - static_assert(std::is_same::value); - co_return; +namespace yield_operand { + /* The operand of co_yield is an assignment-expression, so only a comma + expression needs parentheses. void() cannot be passed to + yield_value, so a lost parenthesis makes the generated code + ill-formed. */ + task comma() { + co_yield (void(), 1); + co_return; + } +} + +namespace dependent { + /* These mirror the non-dependent tests, with both literal and dependent + T operands. */ + template + task assignment() { + (co_yield S{}) = 1; + (co_yield T{}) = 1; + co_return; + } + template task assignment(); + + template + task operand() { + auto a = (co_yield 1) + 2L; + auto b = (co_yield T{}) + 2L; + auto c = co_yield 1 + 2L; + auto d = co_yield T{} + 2L; + auto e = co_yield (T{} + 2L); + auto f = (co_yield T{} + 2L); + static_assert(is_same_v); + static_assert(is_same_v); + static_assert(is_same_v); + static_assert(is_same_v); + static_assert(is_same_v); + static_assert(is_same_v); + co_return; + } + template task operand(); + + template + task conditional() { + auto a = (co_yield 1) ? 2L : 3L; + auto b = (co_yield T{}) ? 2L : 3L; + auto c = co_yield T{} ? 2L : 3L; + auto d = co_yield (T{} ? 2L : 3L); + auto e = (co_yield T{} ? 2L : 3L); + static_assert(is_same_v); + static_assert(is_same_v); + static_assert(is_same_v); + static_assert(is_same_v); + static_assert(is_same_v); + co_return; + } + template task conditional(); + + template + task comma() { + T i{}; + auto a = ((co_yield 1), 2L); + auto b = ((co_yield T{}), 2L); + auto c = (++i, (co_yield T{})); + static_assert(is_same_v); + static_assert(is_same_v); + static_assert(is_same_v); + co_return; + } + template task comma(); + + template + task yield_operand() { + co_yield (void(), 1); + co_yield (void(), T{}); + co_return; + } + template task yield_operand(); + + template + task await_expression() { + auto a = (co_await awaiter{}).m; + auto b = (co_await awaiter{}).m; + static_assert(is_same_v); + static_assert(is_same_v); + co_return; + } + template task await_expression(); + + template + task await_operand() { + awaiter x, y; + auto a = co_await (void(), awaiter{}); + auto b = co_await (x = y); + auto c = co_await (void(), awaiter{}); + static_assert(is_same_v); + static_assert(is_same_v); + static_assert(is_same_v); + co_return; + } + template task await_operand(); } -template task dependent();