coroutines : Handle rethrow from unhandled_exception [PR98704].
authorIain Sandoe <iain@sandoe.co.uk>
Thu, 11 Mar 2021 17:04:14 +0000 (17:04 +0000)
committerIain Sandoe <iain@sandoe.co.uk>
Mon, 15 Mar 2021 15:54:29 +0000 (15:54 +0000)
commit020b286c769f4dc8a6b45491351f6bc2e69d7a7f
tree2d88556fada972c97c6015daa0a7d5c79f52d36b
parent26e0eb1071e318728bcd33f28d055729ac48792c
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.
gcc/cp/coroutines.cc
gcc/testsuite/g++.dg/coroutines/torture/pr98704.C [new file with mode: 0644]