]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++, coroutines: Use decltype(auto) for the g_r_o.
authorIain Sandoe <iain@sandoe.co.uk>
Sun, 11 May 2025 19:36:58 +0000 (20:36 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Wed, 21 May 2025 07:55:38 +0000 (08:55 +0100)
commite71a6e002c6650a7a7be99277120d3e59ecb78a3
tree96047e0ffcadc01c952daf3bdfd7b5eddc45196b
parente06555a40c051d5062405b02f93b89b01a397f97
c++, coroutines: Use decltype(auto) for the g_r_o.

The revised wording for coroutines, uses decltype(auto) for the
type of the get return object, which preserves references.

It is quite reasonable for a  coroutine body implementation to
complete before control is returned to the ramp - and in that
case we would be creating the ramp return object from an already-
deleted promise object.

Jason observes that this is a terrible situation and we should
seek a resolution to it via core.

Since the test added here explicitly performs the unsafe action
dscribed above we expect it to fail (until a resolution is found).

gcc/cp/ChangeLog:

* coroutines.cc
(cp_coroutine_transform::build_ramp_function): Use
decltype(auto) to determine the type of the temporary
get_return_object.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr115908.C: Count promise construction
and destruction. Run the test and XFAIL it.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/cp/coroutines.cc
gcc/testsuite/g++.dg/coroutines/pr115908.C