coroutines: Update lambda capture handling to n4849.
authorIain Sandoe <iain@sandoe.co.uk>
Mon, 2 Mar 2020 20:29:32 +0000 (20:29 +0000)
committerIain Sandoe <iain@sandoe.co.uk>
Mon, 2 Mar 2020 20:53:51 +0000 (20:53 +0000)
commitcd14f288ddf246d40f109aa7999b99a44739cd99
tree0f41a5b640068a00e9dcf962dcfe4f2861e1c3f7
parentb80cbe2d8d46c8518dca2d781c8ee4d02c5ba1ed
coroutines: Update lambda capture handling to n4849.

In the absence of specific comment on the handling of closures I'd
implemented something more than was intended (extending the lifetime
of lambda capture-by-copy vars to the duration of the coro).

After discussion at WG21 in February and by email, the correct handling
is to treat the closure "this" pointer the same way as for a regular one,
and thus it is the user's responsibility to ensure that the lambda capture
object has suitable lifetime for the coroutine.  It is noted that users
frequently get this wrong, so it would be a good thing to revisit for C++23.

This patch removes the additional copying behaviour for lambda capture-by-
copy vars.

gcc/cp/ChangeLog:

2020-03-02  Iain Sandoe  <iain@sandoe.co.uk>

* coroutines.cc (struct local_var_info): Adjust to remove the
reference to the captured var, and just to note that this is a
lambda capture proxy.
(transform_local_var_uses): Handle lambda captures specially.
(struct param_frame_data): Add a visited set.
(register_param_uses): Also check for param uses in lambda
capture proxies.
(struct local_vars_frame_data): Remove captures list.
(register_local_var_uses): Handle lambda capture proxies by
noting and bypassing them.
(morph_fn_to_coro): Update to remove lifetime extension of
lambda capture-by-copy vars.

gcc/testsuite/ChangeLog:

2020-03-02  Iain Sandoe  <iain@sandoe.co.uk>
    Jun Ma <JunMa@linux.alibaba.com>

* g++.dg/coroutines/torture/class-05-lambda-capture-copy-local.C:
* g++.dg/coroutines/torture/lambda-09-init-captures.C: New test.
* g++.dg/coroutines/torture/lambda-10-mutable.C: New test.
gcc/cp/ChangeLog
gcc/cp/coroutines.cc
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/coroutines/torture/class-05-lambda-capture-copy-local.C
gcc/testsuite/g++.dg/coroutines/torture/lambda-09-init-captures.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/torture/lambda-10-mutable.C [new file with mode: 0644]