From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id B28EC3857802; Thu, 20 May 2021 21:35:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B28EC3857802 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 r10-9845] c++: lambda in DMI in class template [PR95870] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 7c365bb1462a7a9dadf9b8f8668a0c832b18056c X-Git-Newrev: ff24ef677edee888012aaddeb0ec9bbe366b4f57 Message-Id: <20210520213504.B28EC3857802@sourceware.org> Date: Thu, 20 May 2021 21:35:04 +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: Thu, 20 May 2021 21:35:04 -0000 https://gcc.gnu.org/g:ff24ef677edee888012aaddeb0ec9bbe366b4f57 commit r10-9845-gff24ef677edee888012aaddeb0ec9bbe366b4f57 Author: Jason Merrill Date: Mon Apr 5 11:34:48 2021 -0400 c++: lambda in DMI in class template [PR95870] Here enclosing_instantiation_of was failing to find a match because otctx is struct S and current_function_decl is S::S(), so the latter has more function contexts, and we end up trying to compare S() to NULL_TREE. After spending a bit of time working on establishing the correspondence in this case (class <=> constructor), it occurred to me that we could just use DECL_SOURCE_LOCATION, which is unique for lambdas, since they cannot be redeclared. Since we're so close to release, for now I'm only doing this for the case that was failing before. gcc/cp/ChangeLog: PR c++/95870 * pt.c (enclosing_instantiation_of): Compare DECL_SOURCE_LOCATION if there is no enclosing non-lambda function. gcc/testsuite/ChangeLog: PR c++/95870 * g++.dg/cpp0x/lambda/lambda-nsdmi10.C: New test. Diff: --- gcc/cp/pt.c | 13 +++++++++++++ gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi10.C | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 986c8207a49..2026827e875 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -14269,6 +14269,19 @@ enclosing_instantiation_of (tree otctx) || instantiated_lambda_fn_p (tctx)); tctx = decl_function_context (tctx)) ++lambda_count; + + if (!tctx) + { + /* Match using DECL_SOURCE_LOCATION, which is unique for all lambdas. + + For GCC 11 the above condition limits this to the previously failing + case where all enclosing functions are lambdas (95870). FIXME. */ + for (tree ofn = fn; ofn; ofn = decl_function_context (ofn)) + if (DECL_SOURCE_LOCATION (ofn) == DECL_SOURCE_LOCATION (otctx)) + return ofn; + gcc_unreachable (); + } + for (; fn; fn = decl_function_context (fn)) { tree ofn = fn; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi10.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi10.C new file mode 100644 index 00000000000..810ed538719 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi10.C @@ -0,0 +1,12 @@ +// PR c++/95870 +// { dg-do compile { target c++11 } } + +template struct S { + S(); + int b = []() -> int { enum E {}; return 1; }(); +}; +struct C : S { + C(); +}; +template S::S() = default; +C::C() {}