public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-10721] c++: nested generic lambda in DMI [PR101717]
Date: Thu, 12 May 2022 21:15:19 +0000 (GMT)	[thread overview]
Message-ID: <20220512211519.319753847814@sourceware.org> (raw)

https://gcc.gnu.org/g:20dc7a2119cc0a4e5ddc4a6899a7350621f05440

commit r10-10721-g20dc7a2119cc0a4e5ddc4a6899a7350621f05440
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Apr 6 22:20:49 2022 -0400

    c++: nested generic lambda in DMI [PR101717]
    
    We were already checking COMPLETE_TYPE_P to recognize instantiation of a
    generic lambda, but didn't consider that we might be nested in a non-generic
    lambda.
    
            PR c++/101717
    
    gcc/cp/ChangeLog:
    
            * lambda.c (lambda_expr_this_capture): Check all enclosing
            lambdas for completeness.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp1y/lambda-generic-this4.C: New test.

Diff:
---
 gcc/cp/lambda.c                                   | 8 +++++++-
 gcc/testsuite/g++.dg/cpp1y/lambda-generic-this4.C | 7 +++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c
index f143cec61d3..1b0cd869fe3 100644
--- a/gcc/cp/lambda.c
+++ b/gcc/cp/lambda.c
@@ -743,6 +743,7 @@ lambda_expr_this_capture (tree lambda, int add_capture_p)
     {
       tree lambda_stack = NULL_TREE;
       tree init = NULL_TREE;
+      bool saw_complete = false;
 
       /* If we are in a lambda function, we can move out until we hit:
            1. a non-lambda function or NSDMI,
@@ -761,6 +762,11 @@ lambda_expr_this_capture (tree lambda, int add_capture_p)
 				      lambda_stack);
 
 	  tree closure = LAMBDA_EXPR_CLOSURE (tlambda);
+	  if (COMPLETE_TYPE_P (closure))
+	    /* We're instantiating a generic lambda op(), the containing
+	       scope may be gone.  */
+	    saw_complete = true;
+
 	  tree containing_function
 	    = decl_function_context (TYPE_NAME (closure));
 
@@ -770,7 +776,7 @@ lambda_expr_this_capture (tree lambda, int add_capture_p)
 	      /* Lambda in an NSDMI.  We don't have a function to look up
 		 'this' in, but we can find (or rebuild) the fake one from
 		 inject_this_parameter.  */
-	      if (!containing_function && !COMPLETE_TYPE_P (closure))
+	      if (!containing_function && !saw_complete)
 		/* If we're parsing a lambda in a non-local class,
 		   we can find the fake 'this' in scope_chain.  */
 		init = scope_chain->x_current_class_ptr;
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-this4.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-this4.C
new file mode 100644
index 00000000000..38d582bec5e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-this4.C
@@ -0,0 +1,7 @@
+// PR c++/101717
+// { dg-do compile { target c++14 } }
+
+struct x {
+  static void f() { }
+  void (*_)() = [] { [=](auto) { f(); }(0); };
+};


                 reply	other threads:[~2022-05-12 21:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220512211519.319753847814@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).