cp-tree.h
316 KB
-
coroutines: Amend parameter handling to match n4849. · dc192bbd
In n4849 and preceding versions, [class.copy.elision] (1.3) appears to confer additional permissions on coroutines to elide parameter copies. After considerable discussion on this topic by email and during the February 2020 WG21 meeting, it has been determined that there are no additional permissions applicable to coroutine parameter copy elision. The content of that clause in the standard is expected to be amended eventually to clarify this. Other than this, the handling of parameter lifetimes is expected to be as per n4849: * A copy is made before the promise is constructed * If the promise CTOR uses the parms, then it should use the copy where appropriate. * The param copy lifetimes end after the promise is destroyed (during the coroutine frame destruction). * Otherwise, C++20 copy elision rules apply. (as an aside) In practice, we expect that copy elision can only occur when the coroutine body is fully inlined, possibly in conjunction with heap allocation elision. The patch: * Reorders the copying process to precede the promise CTOR and ensures the correct use. * Copies all params into the frame regardless of whether the coro body uses them (this is a bit unfortunate, and we should figure out an amendment for C++23). gcc/cp/ChangeLog: 2020-02-26 Iain Sandoe <iain@sandoe.co.uk> * class.c (classtype_has_non_deleted_copy_ctor): New. * coroutines.cc (struct param_info): Keep track of params that are references, and cache the original type and whether the DTOR is trivial. (build_actor_fn): Handle param copies always, and adjust the handling for references. (register_param_uses): Only handle uses here. (classtype_has_non_deleted_copy_ctor): New. (morph_fn_to_coro): Adjust param copy handling to match n4849 by reordering ahead of the promise CTOR and always making a frame copy, even if the param is unused in the coroutine body. * cp-tree.h (classtype_has_non_deleted_copy_ctor): New. gcc/testsuite/ChangeLog: 2020-02-26 Iain Sandoe <iain@sandoe.co.uk> * g++.dg/coroutines/coro1-refs-and-ctors.h: New. * g++.dg/coroutines/torture/func-params-07.C: New test. * g++.dg/coroutines/torture/func-params-08.C: New test.
Iain Sandoe committed