coroutines: Handle non-method promise expressions [PR95519]
authorIain Sandoe <iain@sandoe.co.uk>
Fri, 26 Jun 2020 09:48:35 +0000 (10:48 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Fri, 26 Jun 2020 11:40:16 +0000 (12:40 +0100)
commite74c76073092f4715007584edb1fe6b7a17274db
tree4adba9f1ad297f614e5ed6055bc71f7e0045a067
parente195c8045a1f3604f0f6b339e9ff731ebd9dcb0e
coroutines: Handle non-method promise expressions [PR95519]

The PR  points out that the standard does not restrict promise
expressions to methods, but the current implementation does.

The patch factors out the building of a general promise expression,
and then uses it in a fairly mechanical replacement of each case
that we need such an expressions.

This extends the handling for p.xxxxxx() expressions to cover the
cases where the promise member is some form callable.

Tests are added for each of the promise expressions.

It's somewhat tortuous to find good uses for this for the
get-return-object and get-return-object-on-allocation-failure
cases, but they are included anyway.

gcc/cp/ChangeLog:

PR c++/95519
* coroutines.cc (struct coroutine_info):Add a field
to hold computed p.return_void expressions.
(coro_build_promise_expression): New.
(get_coroutine_return_void_expr): New.
(finish_co_yield_expr): Build the promise expression
using coro_build_promise_expression.
(finish_co_return_stmt): Likewise.
(build_init_or_final_await): Likewise.
(morph_fn_to_coro): Likewise, for several cases.

gcc/testsuite/ChangeLog:

PR c++/95519
* g++.dg/coroutines/torture/pr95519-00-return_void.C: New test.
* g++.dg/coroutines/torture/pr95519-01-initial-suspend.C: New test.
* g++.dg/coroutines/torture/pr95519-02-final_suspend.C: New test.
* g++.dg/coroutines/torture/pr95519-03-return-value.C: New test.
* g++.dg/coroutines/torture/pr95519-04-yield-value.C: New test.
* g++.dg/coroutines/torture/pr95519-05-gro.C: New test.
* g++.dg/coroutines/torture/pr95519-06-grooaf.C: New test.
* g++.dg/coroutines/torture/pr95519-07-unhandled-exception.C: New test.
gcc/cp/coroutines.cc
gcc/testsuite/g++.dg/coroutines/torture/pr95519-00-return_void.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/torture/pr95519-01-initial-suspend.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/torture/pr95519-02-final_suspend.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/torture/pr95519-03-return-value.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/torture/pr95519-04-yield-value.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/torture/pr95519-05-gro.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/torture/pr95519-06-grooaf.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/torture/pr95519-07-unhandled-exception.C [new file with mode: 0644]