diff options
author | Iain Sandoe <iain@sandoe.co.uk> | 2021-10-02 14:43:39 +0100 |
---|---|---|
committer | Iain Sandoe <iains@gcc.gnu.org> | 2024-06-27 13:55:08 +0100 |
commit | 57482cadeb12af2dd52b381b0766776d1e8ec59b (patch) | |
tree | 4ad501620107b4663a00b8a82de5c4a25271c9c0 | |
parent | bb943609534fcbd984d39a9a7efef12fa2667ac6 (diff) | |
download | gcc-57482cadeb12af2dd52b381b0766776d1e8ec59b.zip gcc-57482cadeb12af2dd52b381b0766776d1e8ec59b.tar.gz gcc-57482cadeb12af2dd52b381b0766776d1e8ec59b.tar.bz2 |
coroutines: Await expressions are not allowed in handlers [PR 99710].
C++20 [expr.await] / 2
An await-expression shall appear only in a potentially-evaluated expression
within the compound-statement of a function-body outside of a handler.
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
PR c++/99710
gcc/cp/ChangeLog:
* coroutines.cc (await_statement_walker): Report an error if
an await expression is found in a handler body.
gcc/testsuite/ChangeLog:
* g++.dg/coroutines/pr99710.C: New test.
(cherry picked from commit 650beb110538097b9c3e8600149b333a83e7e836)
-rw-r--r-- | gcc/cp/coroutines.cc | 17 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/coroutines/pr99710.C | 25 |
2 files changed, 41 insertions, 1 deletions
diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 34d9d3e..71246e9 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -3713,7 +3713,22 @@ await_statement_walker (tree *stmt, int *do_subtree, void *d) } return NULL_TREE; /* Done. */ } - break; + break; + case HANDLER: + { + /* [expr.await] An await-expression shall appear only in a + potentially-evaluated expression within the compound-statement + of a function-body outside of a handler. */ + tree *await_ptr; + hash_set<tree> visited; + if (!(cp_walk_tree (&HANDLER_BODY (expr), find_any_await, + &await_ptr, &visited))) + return NULL_TREE; /* All OK. */ + location_t loc = EXPR_LOCATION (*await_ptr); + error_at (loc, "await expressions are not permitted in handlers"); + return NULL_TREE; /* This is going to fail later anyway. */ + } + break; } else if (EXPR_P (expr)) { diff --git a/gcc/testsuite/g++.dg/coroutines/pr99710.C b/gcc/testsuite/g++.dg/coroutines/pr99710.C new file mode 100644 index 0000000..e4f7116 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/pr99710.C @@ -0,0 +1,25 @@ +#include <coroutine> + +struct task { + struct promise_type { + std::suspend_always initial_suspend(); + std::suspend_always final_suspend() noexcept; + task get_return_object(); + void return_void(); + void unhandled_exception(); + }; +}; + +task +my_coro () +{ + try + { } + catch (...) + { + // [expr.await] An await-expression shall appear only in a potentially- + // evaluated expression within the compound-statement of a function-body + // outside of a handler + co_await std::suspend_always{}; // { dg-error "await expressions are not permitted in handlers" } + } +} |