]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++, coroutines: Fix ordering of return object conversions [PR115908].
authorIain Sandoe <iain@sandoe.co.uk>
Sun, 18 Aug 2024 13:54:38 +0000 (14:54 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Sat, 24 Aug 2024 18:55:15 +0000 (19:55 +0100)
commit68ee624bc52ba1154040a904db56dd2f9c3af1f6
tree4f78a13a31fcf42822a2e55fcfe087e577d7f035
parentf4915e6c4cd42e7d6f397dc36fab507cc47dad05
c++, coroutines: Fix ordering of return object conversions [PR115908].

[dcl.fct.def.coroutine]/7 says:
The expression promise.get_return_object() is used to initialize the returned
reference or prvalue result object of a call to a coroutine. The call to
get_return_object is sequenced before the call to initial_suspend and is
invoked at most once.

The issue is about when any conversions are carried out if the type of
the g_r_o call is not the same as the ramp return.  Currently, we have been
doing this by materialising the g_r_o return value and passing that to
finish_return_expr() which handles the necessary conversions and checks.

As the PR shows, this does not work as expected.

In the revised version we carry out the work of the conversions when
intialising the return slot (with the same facilities that are used by
finish_return_expr()).  We do this before the call that initiates the
coroutine body, satisfying the requirements for one call before initial
suspend.

The return expression becomes a trivial 'return <retval>'.

This simplifies the ramp logic considerably, since we no longer need to
keep track of the temporarily-materialised g_r_o value.

PR c++/115908

gcc/cp/ChangeLog:

* coroutines.cc
(cp_coroutine_transform::build_ramp_function): Rework the return
value initialisation to initialise the return slot always from
get_return_object,  even if that implies carrying out conversions
to do so.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr115908.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/cp/coroutines.cc
gcc/testsuite/g++.dg/coroutines/pr115908.C [new file with mode: 0644]