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.
Showing
This diff is collapsed.
Click to expand it.
Please
register
or
sign in
to comment