Patchwork C++ PATCH for c++/47703 (ICE on overload failure involving function pointer conversion)

login
register
mail settings
Submitter Jason Merrill
Date Feb. 20, 2011, 11:16 p.m.
Message ID <4D61A0D6.7030605@redhat.com>
Download mbox | patch
Permalink /patch/83769/
State New
Headers show

Comments

Jason Merrill - Feb. 20, 2011, 11:16 p.m.
This bug was reported in the context of C++0x lambdas, but affects any 
class with a conversion to function pointer.  We were trying to get the 
source position of the pointer type and crashing.

Tested x86_64-pc-linux-gnu, applied to trunk.
commit 1686cec0169c6d65a0838a6c60b6e2765b4ce67c
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Feb 20 17:33:23 2011 -0500

    	PR c++/47703
    	* error.c (location_of): Handle non-tagged types.

Patch

diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 3e91115..28305d2 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -2493,7 +2493,11 @@  location_of (tree t)
   if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
     t = DECL_CONTEXT (t);
   else if (TYPE_P (t))
-    t = TYPE_MAIN_DECL (t);
+    {
+      t = TYPE_MAIN_DECL (t);
+      if (t == NULL_TREE)
+	return input_location;
+    }
   else if (TREE_CODE (t) == OVERLOAD)
     t = OVL_FUNCTION (t);
 
diff --git a/gcc/testsuite/g++.dg/overload/conv-op1.C b/gcc/testsuite/g++.dg/overload/conv-op1.C
new file mode 100644
index 0000000..6a63cba
--- /dev/null
+++ b/gcc/testsuite/g++.dg/overload/conv-op1.C
@@ -0,0 +1,17 @@ 
+// PR c++/47703
+
+typedef void (*pfn)(int &);
+
+struct A
+{
+  operator pfn() { return 0; }
+};
+
+void f()
+{
+  const int i = 42;
+  A()(i);			// { dg-message "<conversion>" }
+}
+
+// { dg-prune-output "no match" }
+// { dg-prune-output "candidate" }