]> git.ipfire.org Git - thirdparty/gcc.git/commit
coroutines : Do not accept throwing final await expressions [PR95616].
authorIain Sandoe <iain@sandoe.co.uk>
Mon, 15 Feb 2021 17:11:31 +0000 (17:11 +0000)
committerIain Sandoe <iain@sandoe.co.uk>
Fri, 5 Mar 2021 16:56:19 +0000 (16:56 +0000)
commit9ee91079fd5879cba046e452ab5593372166b2ab
tree85fa95e658d91ee2e9f40e1953bceabf37d55039
parentfe55086547c9360b530e040a6673dae10ac77847
coroutines : Do not accept throwing final await expressions [PR95616].

From the PR:

The wording of [dcl.fct.def.coroutine]/15 states:
 * The expression co_await promise.final_suspend() shall not be
   potentially-throwing ([except.spec]).

See http://eel.is/c++draft/dcl.fct.def.coroutine#15
and http://eel.is/c++draft/except.spec#6

ie. all of the following must be declared noexcept (if they form part of the await-expression):
- promise_type::final_suspend()
- finalSuspendObj.operator co_await()
- finalSuspendAwaiter.await_ready()
- finalSuspendAwaiter.await_suspend()
- finalSuspendAwaiter.await_resume()
- finalSuspedObj destructor
- finalSuspendAwaiter destructor

This implements the checks for these cases and rejects such code with
a diagnostic if exceptions are enabled.

gcc/cp/ChangeLog:

PR c++/95616
* coroutines.cc (coro_diagnose_throwing_fn): New helper.
(coro_diagnose_throwing_final_aw_expr): New helper.
(build_co_await): Diagnose throwing final await expression
components.
(build_init_or_final_await): Diagnose a throwing promise
final_suspend() call.

gcc/testsuite/ChangeLog:

PR c++/95616
* g++.dg/coroutines/pr95616-0-no-exceptions.C: New test.
* g++.dg/coroutines/pr95616-0.C: New test.
* g++.dg/coroutines/pr95616-1-no-exceptions.C: New test.
* g++.dg/coroutines/pr95616-1.C: New test.
* g++.dg/coroutines/pr95616-2.C: New test.
* g++.dg/coroutines/pr95616-3-no-exceptions.C: New test.
* g++.dg/coroutines/pr95616-3.C: New test.
* g++.dg/coroutines/pr95616-4.C: New test.
* g++.dg/coroutines/pr95616-5.C: New test.
* g++.dg/coroutines/pr95616-6.C: New test.
gcc/cp/coroutines.cc
gcc/testsuite/g++.dg/coroutines/pr95616-0-no-exceptions.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr95616-0.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr95616-1-no-exceptions.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr95616-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr95616-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr95616-3-no-exceptions.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr95616-3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr95616-4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr95616-5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr95616-6.C [new file with mode: 0644]