diff mbox

C++ PATCH for c++/52088 (ICE with template conversion op)

Message ID 4F303E89.3070502@redhat.com
State New
Headers show

Commit Message

Jason Merrill Feb. 6, 2012, 8:56 p.m. UTC
In this testcase, we ended up trying to call an uninstantiated template, 
and get confused as a result.  This patch changes the compiler to not 
consider a template to be a valid candidate for a default conversion.

Tested x86_64-pc-linux-gnu, applied to trunk
diff mbox

Patch

commit 06d4f1b83e5c393fd22421bbd12135338b891f8e
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Feb 5 22:36:59 2012 -1000

    	PR c++/52088
    	* cvt.c (build_expr_type_conversion): Check for template conversion.

diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 8570e3d..c411a47 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -1539,6 +1539,17 @@  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))
diff --git a/gcc/testsuite/g++.dg/template/conv13.C b/gcc/testsuite/g++.dg/template/conv13.C
new file mode 100644
index 0000000..717994b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/conv13.C
@@ -0,0 +1,13 @@ 
+// PR c++/52088
+
+struct S
+{
+  template <typename T>
+  operator T *() { return 0; }
+};
+
+int main()
+{
+  S s;
+  delete s;		       // { dg-error "ambiguous|template|pointer" }
+}