public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-9855] c++: generic lambda in template fn with DMI [PR100054]
@ 2021-05-20 21:35 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-05-20 21:35 UTC (permalink / raw)
  To: gcc-cvs

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>();


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-20 21:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-20 21:35 [gcc r10-9855] c++: generic lambda in template fn with DMI [PR100054] Jason Merrill

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).