coroutines: Handle initial awaiters with non-void returns [PR 100127].
authorIain Sandoe <iain@sandoe.co.uk>
Sat, 2 Oct 2021 16:20:08 +0000 (17:20 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Fri, 17 Dec 2021 16:57:47 +0000 (16:57 +0000)
commit2466a8d0dd40d05cb4a239d7d4a21bbd9ffab698
tree52c549a73230b5b77b3da4bd2ba296f85af36860
parent921942a8a106cb53994c21162922e4934eb3a3e0
coroutines: Handle initial awaiters with non-void returns [PR 100127].

The way in which a C++20 coroutine is specified discards any value
that might be returned from the initial or final await expressions.

This ICE was caused by an initial await expression with an
await_resume () returning a reference, the function rewrite code
was not set up to expect this.

Fixed by looking through any indirection present and by explicitly
discarding the value, if any, returned by await_resume().

It does not seem useful to make a diagnostic for this, since
the user could define a generic awaiter that usefully returns
values when used in a different position from the initial (or
final) await expressions.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
PR c++/100127

gcc/cp/ChangeLog:

* coroutines.cc (coro_rewrite_function_body): Handle initial
await expressions that try to produce a reference value.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr100127.C: New test.
gcc/cp/coroutines.cc
gcc/testsuite/g++.dg/coroutines/pr100127.C [new file with mode: 0644]