This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/40342


In my patch for c++/34691 I had a typo whereby in the case of multiple matches it would compare the first match to itself and, unsurprisingly, find that it is the same function as itself.

Also, decls_match was incorrectly treating specializations of two different templates as the same function.

Tested x86_64-pc-linux-gnu, applied to trunk and 4.4.
2009-06-24  Jason Merrill  <jason@redhat.com>

	PR c++/40342
	* decl.c (decls_match): Check DECL_TI_TEMPLATE too.
	* class.c (resolve_address_of_overloaded_function): Fix typo.

diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index d86ff64..12192e6 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -6185,7 +6185,7 @@ resolve_address_of_overloaded_function (tree target_type,
 
       fn = TREE_PURPOSE (matches);
       for (match = TREE_CHAIN (matches); match; match = TREE_CHAIN (match))
-	if (!decls_match (fn, TREE_PURPOSE (matches)))
+	if (!decls_match (fn, TREE_PURPOSE (match)))
 	  break;
 
       if (match)
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 9ebfd27..9a7f42c 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -916,6 +916,15 @@ decls_match (tree newdecl, tree olddecl)
       tree p1 = TYPE_ARG_TYPES (f1);
       tree p2 = TYPE_ARG_TYPES (f2);
 
+      tree t1 = (DECL_USE_TEMPLATE (newdecl)
+		 ? DECL_TI_TEMPLATE (newdecl)
+		 : NULL_TREE);
+      tree t2 = (DECL_USE_TEMPLATE (olddecl)
+		 ? DECL_TI_TEMPLATE (olddecl)
+		 : NULL_TREE);
+      if (t1 != t2)
+	return 0;
+
       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
 	  && ! (DECL_EXTERN_C_P (newdecl)
 		&& DECL_EXTERN_C_P (olddecl)))
diff --git a/gcc/testsuite/g++.dg/template/overload10.C b/gcc/testsuite/g++.dg/template/overload10.C
new file mode 100644
index 0000000..088b9d2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/overload10.C
@@ -0,0 +1,6 @@
+// PR c++40342
+
+template <typename T1, typename T2> int f(T1 *, const T2 *); // { dg-error "" }
+template <typename T1, typename T2> int f(const T1 *, T2 *); // { dg-error "" }
+
+int (*p)(const int *, const int *) = f; // { dg-error "ambiguous" }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]