public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-1224] c++: context completion in lookup_template_class [PR105982]
@ 2022-06-23 20:19 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2022-06-23 20:19 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:01aff2ba18a654324957af446a3065db489c0f14

commit r13-1224-g01aff2ba18a654324957af446a3065db489c0f14
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Jun 23 16:18:55 2022 -0400

    c++: context completion in lookup_template_class [PR105982]
    
    The below testcase demonstrates that completion of the substituted
    context during lookup_template_class can end up registering the desired
    specialization for us in more cases than r13-1045-gcb7fd1ea85feea
    anticipated.  In particular this can happen for a non-dependent
    specialization of a nested class as well.
    
    For this testcase, during overload resolution with A's guides, we
    substitute the deduced argument T=int into the TYPENAME_TYPE B::C,
    during which we call lookup_template_class for A<T>::B with T=int,
    which completes A<int> for the first time, which recursively registers
    the desired specialization of B already.  The parent call to
    lookup_template_class then tries to register the same specialization,
    triggering an ICE.
    
    This patch fixes this by making lookup_template_class determine more
    directly whether we need to recheck the specializations table after
    completion of the context -- when and only when the call to complete_type
    had an effect.
    
            PR c++/105982
    
    gcc/cp/ChangeLog:
    
            * pt.cc (lookup_template_class): After calling complete_type for
            the substituted context, check the table again iff the type was
            previously incomplete and complete_type made it complete.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp1z/class-deduction111.C: New test.

Diff:
---
 gcc/cp/pt.cc                                    | 21 ++++++++++++---------
 gcc/testsuite/g++.dg/cpp1z/class-deduction111.C | 10 ++++++++++
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 12a2b57d9e3..8672da123f4 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -10089,16 +10089,19 @@ lookup_template_class (tree d1, tree arglist, tree in_decl, tree context,
 	    {
 	      context = tsubst_aggr_type (context, arglist,
 					  complain, in_decl, true);
-	      context = complete_type (context);
-	      if (is_dependent_type && arg_depth > 1)
+	      /* Try completing the enclosing context if it's not already so.  */
+	      if (context != error_mark_node
+		  && !COMPLETE_TYPE_P (context))
 		{
-		  /* If this is a dependent nested specialization such as
-		     A<T>::B<U> [with T=int, U=U], then completion of A<int>
-		     could have caused to register the desired specialization
-		     of B already, so check the table again (33959).  */
-		  entry = type_specializations->find_with_hash (&elt, hash);
-		  if (entry)
-		    return entry->spec;
+		  context = complete_type (context);
+		  if (COMPLETE_TYPE_P (context))
+		    {
+		      /* Completion could have caused us to register the desired
+			 specialization already, so check the table again.  */
+		      entry = type_specializations->find_with_hash (&elt, hash);
+		      if (entry)
+			return entry->spec;
+		    }
 		}
 	    }
 	}
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction111.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction111.C
new file mode 100644
index 00000000000..2406529ea5a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction111.C
@@ -0,0 +1,10 @@
+// PR c++/105982
+// { dg-do compile { target c++17 } }
+
+template<class T>
+struct A {
+  struct B { struct C { }; };
+  A(T, typename B::C);
+};
+
+A a(0, {});


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

only message in thread, other threads:[~2022-06-23 20:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-23 20:19 [gcc r13-1224] c++: context completion in lookup_template_class [PR105982] Patrick Palka

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