From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id E949F398B429; Thu, 20 May 2021 21:35:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E949F398B429 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-9855] c++: generic lambda in template fn with DMI [PR100054] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: d83c30ec6c4865ca23a135c067eb9b56ac74a1f2 X-Git-Newrev: fe0f9ef823dda3205638a2f23d08eb7d0bc497b9 Message-Id: <20210520213556.E949F398B429@sourceware.org> Date: Thu, 20 May 2021 21:35:56 +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:57 -0000 https://gcc.gnu.org/g:fe0f9ef823dda3205638a2f23d08eb7d0bc497b9 commit r10-9855-gfe0f9ef823dda3205638a2f23d08eb7d0bc497b9 Author: Jason Merrill Date: Tue Apr 13 12:33:39 2021 -0400 c++: generic lambda in template fn with DMI [PR100054] get_nsdmi instantiates default member initializers on demand. It tries to push into the context of the class before doing so, so access checking works properly, but since my patch for 90479 not for local classes. We should only be doing this when any template parameters have arguments. But in this case, we get here while regenerating a generic lambda, so processing_template_decl is true, even though the class and its DMI are non-dependent at this point. And so we crashed. So let's do more of the pushing into the context of the class even for local classes. gcc/cp/ChangeLog: PR c++/100054 PR c++/90479 * init.c (get_nsdmi): Do more context adjustment for local classes. gcc/testsuite/ChangeLog: PR c++/100054 * g++.dg/cpp1y/lambda-generic-local-class1.C: New test. Diff: --- gcc/cp/init.c | 17 +++++++++++------ .../g++.dg/cpp1y/lambda-generic-local-class1.C | 10 ++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/gcc/cp/init.c b/gcc/cp/init.c index f7065567093..c6b3f3bf8ce 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -585,17 +585,21 @@ get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain) bool pushed = false; tree ctx = DECL_CONTEXT (member); - if (!currently_open_class (ctx) - && !LOCAL_CLASS_P (ctx)) + + processing_template_decl_sentinel ptds (/*reset*/false); + if (!currently_open_class (ctx)) { - push_to_top_level (); + if (!LOCAL_CLASS_P (ctx)) + push_to_top_level (); + else + /* push_to_top_level would lose the necessary function context, + just reset processing_template_decl. */ + processing_template_decl = 0; push_nested_class (ctx); push_deferring_access_checks (dk_no_deferred); pushed = true; } - gcc_checking_assert (!processing_template_decl); - inject_this_parameter (ctx, TYPE_UNQUALIFIED); start_lambda_scope (member); @@ -618,7 +622,8 @@ get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain) { pop_deferring_access_checks (); pop_nested_class (); - pop_from_top_level (); + if (!LOCAL_CLASS_P (ctx)) + pop_from_top_level (); } input_location = sloc; diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-local-class1.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-local-class1.C new file mode 100644 index 00000000000..7498327981b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-local-class1.C @@ -0,0 +1,10 @@ +// PR c++/100054 +// { dg-do compile { target c++14 } } + +template +void f() { + struct A { T m{}; }; + [](auto){ return A{}; }; +} + +template void f();