From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id AD9CD395BC0E; Fri, 13 May 2022 17:41:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD9CD395BC0E MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-10168] c++: nested generic lambda in DMI [PR101717] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/releases/gcc-9 X-Git-Oldrev: 45fb36bf93a7cc6506c2a12f9c4aa3981f4e6b44 X-Git-Newrev: 7ce3d2ab2a1a144f94a3a9be716fb831cb76603b Message-Id: <20220513174122.AD9CD395BC0E@sourceware.org> Date: Fri, 13 May 2022 17:41:22 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 May 2022 17:41:22 -0000 https://gcc.gnu.org/g:7ce3d2ab2a1a144f94a3a9be716fb831cb76603b commit r9-10168-g7ce3d2ab2a1a144f94a3a9be716fb831cb76603b Author: Jason Merrill 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 1ee75814004..46ee390a9b8 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -745,6 +745,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, @@ -763,6 +764,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)); @@ -772,7 +778,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); }; +};