public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-8137] c++: premature overload resolution [PR93085]
@ 2021-04-12 21:30 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-04-12 21:30 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:84081e2c6bd43a6790f751755865cf4227adac7c

commit r11-8137-g84081e2c6bd43a6790f751755865cf4227adac7c
Author: Jason Merrill <jason@redhat.com>
Date:   Sat Apr 10 02:10:32 2021 -0400

    c++: premature overload resolution [PR93085]
    
    We can't resolve the call to foo<42> before instantiation of G, because the
    template parameter of #1 has dependent type.  But we were missing that in
    our dependency check, because the tree walk of DECL_TEMPLATE_PARMS doesn't
    look into the types of template parameters.  So look at them directly.
    
    gcc/cp/ChangeLog:
    
            PR c++/93085
            * pt.c (uses_outer_template_parms): Handle non-type and template
            template parameters specifically.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/93085
            * g++.dg/template/dependent-tmpl1.C: New test.

Diff:
---
 gcc/cp/pt.c                                     | 21 ++++++++++++++++-----
 gcc/testsuite/g++.dg/template/dependent-tmpl1.C |  9 +++++++++
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index abd1ad4d1a6..efcbc59f5c9 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -10846,11 +10846,22 @@ uses_outer_template_parms (tree decl)
 			      &depth, NULL, /*include_nondeduced_p=*/true))
     return true;
   if (PRIMARY_TEMPLATE_P (decl)
-      && for_each_template_parm (INNERMOST_TEMPLATE_PARMS
-				 (DECL_TEMPLATE_PARMS (decl)),
-				 template_parm_outer_level,
-				 &depth, NULL, /*include_nondeduced_p=*/true))
-    return true;
+      || DECL_TEMPLATE_TEMPLATE_PARM_P (decl))
+    {
+      tree parms = INNERMOST_TEMPLATE_PARMS (DECL_TEMPLATE_PARMS (decl));
+      for (int i = TREE_VEC_LENGTH (parms) - 1; i >= 0; --i)
+	{
+	  tree parm = TREE_VALUE (TREE_VEC_ELT (parms, i));
+	  if (TREE_CODE (parm) == PARM_DECL
+	      && for_each_template_parm (TREE_TYPE (parm),
+					 template_parm_outer_level,
+					 &depth, NULL, /*nondeduced*/true))
+	    return true;
+	  if (TREE_CODE (parm) == TEMPLATE_DECL
+	      && uses_outer_template_parms (parm))
+	    return true;
+	}
+    }
   tree ci = get_constraints (decl);
   if (ci)
     ci = CI_ASSOCIATED_CONSTRAINTS (ci);
diff --git a/gcc/testsuite/g++.dg/template/dependent-tmpl1.C b/gcc/testsuite/g++.dg/template/dependent-tmpl1.C
new file mode 100644
index 00000000000..7b800b6869a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/dependent-tmpl1.C
@@ -0,0 +1,9 @@
+// PR c++/93085
+// { dg-do compile { target c++11 } }
+
+template<class T>
+struct G {
+    template<T> static int foo();    // #1
+    template<int> static int foo();  // #2
+    int x = foo<42>();  // OK
+};


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

only message in thread, other threads:[~2021-04-12 21:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-12 21:30 [gcc r11-8137] c++: premature overload resolution [PR93085] 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).