[Bug c++/95616] [coroutines] coroutines with potentially-throwing 'co_await promise.final_suspend()' expressions should be ill-formed

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Mar 5 16:59:24 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95616

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Iain D Sandoe <iains@gcc.gnu.org>:

https://gcc.gnu.org/g:9ee91079fd5879cba046e452ab5593372166b2ab

commit r11-7528-g9ee91079fd5879cba046e452ab5593372166b2ab
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Mon Feb 15 17:11:31 2021 +0000

    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.


More information about the Gcc-bugs mailing list