Nathan Sidwell <nat...@acm.org> wrote:
On 3/4/21 2:54 PM, Iain Sandoe wrote:Hi, 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#6ie. 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. [ accepts invalid ] tested on x86_64-darwin, x86_64-linux-gnu, OK for master / 10.x? thanks Iain 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.ok. Does this DTRT in the presence of -fno-exceptions?
thanks for catching this…
(i.e. use of that flag means you don't have to decorate everything with noexcept)
As discussed on IRC, I updated this to gate the diagnostics on flag_exceptions (and added three more tests to cover that circumstance).
pushed to master, (for the record, updated version attached), thanks, Iain
0001-coroutines-Do-not-accept-throwing-final-await-expres.patch
Description: Binary data