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-9855] c++: generic lambda in template fn with DMI [PR100054] Date: Thu, 20 May 2021 21:35:56 +0000 (GMT) [thread overview] Message-ID: <20210520213556.E949F398B429@sourceware.org> (raw) https://gcc.gnu.org/g:fe0f9ef823dda3205638a2f23d08eb7d0bc497b9 commit r10-9855-gfe0f9ef823dda3205638a2f23d08eb7d0bc497b9 Author: Jason Merrill <jason@redhat.com> 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 <class T> +void f() { + struct A { T m{}; }; + [](auto){ return A{}; }; +} + +template void f<int>();
reply other threads:[~2021-05-20 21:35 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=20210520213556.E949F398B429@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: linkBe 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).