[Bug c++/98704] coroutine_handle::done() == false after promise's unhandled_exception() has thrown

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Mar 22 22:04:29 GMT 2021


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

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

https://gcc.gnu.org/g:07444226c6a3c78788aa967aad6889b1f31eceb0

commit r10-9517-g07444226c6a3c78788aa967aad6889b1f31eceb0
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Thu Mar 11 17:04:14 2021 +0000

    coroutines : Handle rethrow from unhandled_exception [PR98704].

    Although there is still some discussion in CWG 2451 on this, the
    implementors are agreed on the intent.

    When promise.unhandled_exception () is entered, the coroutine is
    considered to be still running - returning from the method will
    cause the final await expression to be evaluated.

    If the method throws, that action is considered to make the
    coroutine suspend (since, otherwise, it would be impossible to
    reclaim its resources, since one cannot destroy a running coro).

    The wording issue is to do with how to represent the place at
    which the coroutine should be considered suspended.

    For the implementation here, that place is immediately before the
    promise life-time ends. A handler for the rethrown exception, can
    thus call xxxx.destroy() which will run DTORs for the promise and
    any parameter copies [as needed] then the coroutine frame will be
    deallocated.

    At present, we also set "done=true" in this case (for compatibility
    with other current implementations).  One might consider 'done()'
    to be misleading in the case of an abnormal termination - that is
    also part of the CWG 2451 discussion.

    gcc/cp/ChangeLog:

            PR c++/98704
            * coroutines.cc (build_actor_fn): Make destroy index 1
            correspond to the abnormal unhandled_exception() exit.
            Substitute the proxy for the resume index.
            (coro_rewrite_function_body): Arrange to reset the resume
            index and make done = true for a rethrown exception from
            unhandled_exception ().
            (morph_fn_to_coro): Adjust calls to build_actor_fn and
            coro_rewrite_function_body.

    gcc/testsuite/ChangeLog:

            PR c++/98704
            * g++.dg/coroutines/torture/pr98704.C: New test.

    (cherry picked from commit 020b286c769f4dc8a6b45491351f6bc2e69d7a7f)


More information about the Gcc-bugs mailing list