Patchwork C++ PATCH for c++/51613 (accepts-invalid with ambiguous template instantiation)

login
register
mail settings
Submitter Jason Merrill
Date Jan. 11, 2012, 4:45 p.m.
Message ID <4F0DBCB7.4090704@redhat.com>
Download mbox | patch
Permalink /patch/135427/
State New
Headers show

Comments

Jason Merrill - Jan. 11, 2012, 4:45 p.m.
Simple thinko; when copy/pasting this loop from elsewhere we needed to 
change decls_match to same_type_p since here we're just dealing with types.

Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit 32ca2088d87e3a3204cc28f4d7fa543d5616f8b6
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Jan 11 09:05:31 2012 -0500

    	PR c++/51613
    	* pt.c (resolve_overloaded_unification): Compare types with
    	same_type_p, not decls_match.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index bc3dd97..ac72b6d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -15471,7 +15471,7 @@  resolve_overloaded_unification (tree tparms,
 	      elem = tsubst (TREE_TYPE (fn), subargs, tf_none, NULL_TREE);
 	      if (try_one_overload (tparms, targs, tempargs, parm,
 				    elem, strict, sub_strict, addr_p, explain_p)
-		  && (!goodfn || !decls_match (goodfn, elem)))
+		  && (!goodfn || !same_type_p (goodfn, elem)))
 		{
 		  goodfn = elem;
 		  ++good;
diff --git a/gcc/testsuite/g++.dg/template/explicit-args5.C b/gcc/testsuite/g++.dg/template/explicit-args5.C
new file mode 100644
index 0000000..d6c9a57
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/explicit-args5.C
@@ -0,0 +1,24 @@ 
+// PR c++/51613
+
+template<typename F, typename T>
+void apply(F f, T t)
+{
+    f(t);
+}
+
+template<typename T>
+void multi(T)
+{
+}
+
+template<typename T>
+void multi(T*)
+{
+}
+
+int main()
+{
+    apply(&multi<int>, 7);	// { dg-error "no match" }
+
+    return 0;
+}

commit a03d5b81f06edbe8b919baa4791f2d52ef223582
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Jan 11 09:05:49 2012 -0500

    	* decl.c (decls_match): Assert that the arguments are decls.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 7daac5f..ef43dbf 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -952,6 +952,8 @@  decls_match (tree newdecl, tree olddecl)
        interested in their types.  */
     return 0;
 
+  gcc_assert (DECL_P (newdecl));
+
   if (TREE_CODE (newdecl) == FUNCTION_DECL)
     {
       tree f1 = TREE_TYPE (newdecl);