From: Jason Merrill <jason@redhat.com>
To: Patrick Palka <ppalka@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: nested lambda capturing a capture proxy, part 2 [PR94376]
Date: Wed, 15 Dec 2021 16:01:01 -0500 [thread overview]
Message-ID: <0594bc89-b458-13f2-047f-745da5ff23ca@redhat.com> (raw)
In-Reply-To: <20211215203612.4095222-1-ppalka@redhat.com>
On 12/15/21 15:36, Patrick Palka wrote:
> The r12-5403 fix apparently doesn't handle the case where the inner
> lambda explicitly rather implicitly captures the capture proxy from
> the outer lambda, and so we still reject the first example in the
> testcase below.
>
> The reason is that compared to an implicit capture, the effective
> initializer for an explicit capture is wrapped in a location wrapper
> (pointing to the source location of the explicit capture), and this
> wrapper foils the is_capture_proxy check. The simplest fix appears to
> be to strip location wrappers accordingly.
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?
>
> PR c++/94376
>
> gcc/cp/ChangeLog:
>
> * lambda.c (lambda_capture_field_type): Strip location wrappers
> before checking for a capture proxy.
I think either is_capture_proxy should strip location wrappers or
gcc_checking_assert that it doesn't see one.
> gcc/testsuite/ChangeLog:
>
> * g++.dg/cpp0x/lambda/lambda-nested9a.C: New test.
> ---
> gcc/cp/lambda.c | 1 +
> .../g++.dg/cpp0x/lambda/lambda-nested9a.C | 42 +++++++++++++++++++
> 2 files changed, 43 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nested9a.C
>
> diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c
> index c39a2bca416..7f2f927bda2 100644
> --- a/gcc/cp/lambda.c
> +++ b/gcc/cp/lambda.c
> @@ -221,6 +221,7 @@ lambda_capture_field_type (tree expr, bool explicit_init_p,
> }
> else
> {
> + STRIP_ANY_LOCATION_WRAPPER (expr);
> if (!by_reference_p && is_capture_proxy (expr))
> {
> /* When capturing by-value another capture proxy from an enclosing
> diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nested9a.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nested9a.C
> new file mode 100644
> index 00000000000..d62f8f0c952
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nested9a.C
> @@ -0,0 +1,42 @@
> +// PR c++/94376
> +// Like lambda-nested9.C but using explicit captures in the inner lambda.
> +// { dg-do compile { target c++11 } }
> +
> +int main() {
> + // We used to incorrectly reject the first two cases.
> + int i = 0;
> + [=] () {
> + [i] () mutable {
> + ++i;
> + };
> + };
> +
> +#if __cpp_init_captures
> + [j=0] () {
> + [j] () mutable {
> + ++j;
> + };
> + };
> +#endif
> +
> + [=] () {
> + [&i] () mutable {
> + ++i; // { dg-error "read-only" }
> + };
> + };
> +
> + const int j = 0;
> + [=] () {
> + [j] () mutable {
> + ++j; // { dg-error "read-only" }
> + };
> + };
> +
> +#if __cpp_init_captures
> + [j=0] () {
> + [&j] () mutable {
> + ++j; // { dg-error "read-only" "" { target c++14 } }
> + };
> + };
> +#endif
> +}
next prev parent reply other threads:[~2021-12-15 21:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-15 20:36 Patrick Palka
2021-12-15 21:01 ` Jason Merrill [this message]
2021-12-16 16:28 ` Patrick Palka
2021-12-16 21:14 ` Jason Merrill
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0594bc89-b458-13f2-047f-745da5ff23ca@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=ppalka@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).