This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix PR c++/70121 (premature folding of const var that was implicitly captured)
- From: Patrick Palka <patrick at parcs dot ath dot cx>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Jason Merrill <jason at redhat dot com>, Patrick Palka <patrick at parcs dot ath dot cx>
- Date: Thu, 10 Mar 2016 18:06:15 -0500
- Subject: Re: [PATCH] Fix PR c++/70121 (premature folding of const var that was implicitly captured)
- Authentication-results: sourceware.org; auth=none
- References: <1457650689-16404-1-git-send-email-patrick at parcs dot ath dot cx>
On Thu, Mar 10, 2016 at 5:58 PM, Patrick Palka <patrick@parcs.ath.cx> wrote:
> Within a lambda we should implicitly capture an outer const variable
> only if it's odr-used in the body of the lambda. But we are currently
> making the decision of whether to capture such a variable, or else to
> fold it to a constant, too early -- before we can know whether it's
> being odr-used or not. So we currently always fold a const variable to
> a constant if possible instead of otherwise capturing it, but of course
> doing this is wrong if e.g. the address of this variable is taken inside
> the lambda's body.
>
> This patch reverses the behavior of process_outer_var_ref, so that we
> always implicitly capture a const variable if it's capturable, instead
> of always trying to first fold it to a constant. This behavior however
> is wrong too, and introduces a different but perhaps less important
> regression: if we implicitly capture by value a const object that is not
> actually odr-used within the body of the lambda, we may introduce a
> redundant call to its copy/move constructor, see pr70121-2.C.
>
> Ideally we should be capturing a variable only if it's not odr-used
Er, this sentence should read
Ideally we should be _implicitly_ capturing a variable only if it
_is_ odr-used ...