]> git.ipfire.org Git - thirdparty/gcc.git/commit
coroutines: Fix missed ramp function return copy elision [PR95346].
authorIain Sandoe <iain@sandoe.co.uk>
Wed, 10 Jun 2020 07:12:32 +0000 (08:12 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Wed, 10 Jun 2020 20:58:41 +0000 (21:58 +0100)
commit5bb75908cbcc0d2ddfbadedfcd716b33694fd9c4
tree01cc703fa1f2b53ff373a163fe0e2dab4f617f75
parent977a173c196dc5ba5ac2e1b890083beb0451cf60
coroutines: Fix missed ramp function return copy elision [PR95346].

Confusingly, "get_return_object ()" can do two things:
- Firstly it can provide the return object for the ramp function (as
  the name suggests).
- Secondly if the type of the ramp function is different from that
  of the get_return_object call, this is used as a single parameter
  to a CTOR for the ramp's return type.

In the first case we can rely on finish_return_stmt () to do the
necessary processing for copy elision.
In the second case, we should have passed a prvalue to the CTOR as
per the standard comment, but I had omitted the rvalue () call.  Fixed
thus.

gcc/cp/ChangeLog:

PR c++/95346
* coroutines.cc (morph_fn_to_coro): Ensure that the get-
return-object is constructed correctly; When it is not the
final return value, pass it to the CTOR of the return type
as an rvalue, per the standard comment.

gcc/testsuite/ChangeLog:

PR c++/95346
* g++.dg/coroutines/pr95346.C: New test.

(cherry picked from commit 4f2d05ef0142d269964e165c14c6f7fe4bdfd5a3)
gcc/cp/coroutines.cc
gcc/testsuite/g++.dg/coroutines/pr95346.C [new file with mode: 0644]