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++/58119 (possibly wrong error with conversion template)


In this testcase, the A conversion template can't possibly produce a pointer type, so its presence in the overload set shouldn't cause an error. The standard is unclear about the B case, but it seems appropriate to me to still complain there.

Tested x86_64-pc-linux-gnu, applying to trunk, 4.8, 4.7.
commit bd43671e5087c4fbee728305af02abd54bafa91e
Author: Jason Merrill <jason@redhat.com>
Date:   Sat Aug 17 21:30:36 2013 -0400

    	PR c++/58119
    	* cvt.c (build_expr_type_conversion): Don't complain about a
    	template that can't match the desired type category.

diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 532e8fd..08c026d 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -1590,17 +1590,6 @@ build_expr_type_conversion (int desires, tree expr, bool complain)
       if (DECL_NONCONVERTING_P (cand))
 	continue;
 
-      if (TREE_CODE (cand) == TEMPLATE_DECL)
-	{
-	  if (complain)
-	    {
-	      error ("ambiguous default type conversion from %qT",
-		     basetype);
-	      error ("  candidate conversions include %qD", cand);
-	    }
-	  return error_mark_node;
-	}
-
       candidate = non_reference (TREE_TYPE (TREE_TYPE (cand)));
 
       switch (TREE_CODE (candidate))
@@ -1634,11 +1623,23 @@ build_expr_type_conversion (int desires, tree expr, bool complain)
 	  break;
 
 	default:
+	  /* A wildcard could be instantiated to match any desired
+	     type, but we can't deduce the template argument.  */
+	  if (WILDCARD_TYPE_P (candidate))
+	    win = true;
 	  break;
 	}
 
       if (win)
 	{
+	  if (TREE_CODE (cand) == TEMPLATE_DECL)
+	    {
+	      if (complain)
+		error ("default type conversion can't deduce template"
+		       " argument for %qD", cand);
+	      return error_mark_node;
+	    }
+
 	  if (winner)
 	    {
 	      tree winner_type
diff --git a/gcc/testsuite/g++.dg/template/delete2.C b/gcc/testsuite/g++.dg/template/delete2.C
new file mode 100644
index 0000000..b6ab380
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/delete2.C
@@ -0,0 +1,26 @@
+// PR c++/58119
+
+template <class T>
+struct A
+{
+  operator T*();
+  template <class U>
+  operator A<U>();
+};
+
+template <class T>
+struct B
+{
+  operator T*();
+  template <class U>
+  operator A<U>*();
+};
+
+int main()
+{
+  A<int> a;
+  delete a;
+
+  B<int> b;
+  delete b;			// { dg-error "template|delete" }
+}

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