PR c++/42219
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 11 Dec 2009 21:03:55 +0000 (21:03 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 11 Dec 2009 21:03:55 +0000 (21:03 +0000)
* typeck.c (error_type_p): New.
(ptr_reasonably_similar): Use it.
* cp-tree.h: Declare it.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@155177 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/conversion/err-recover1.C [new file with mode: 0644]

index 988f98f..e51641b 100644 (file)
@@ -1,3 +1,10 @@
+2009-12-11  Jason Merrill  <jason@redhat.com>
+
+       PR c++/42219
+       * typeck.c (error_type_p): New.
+       (ptr_reasonably_similar): Use it.
+       * cp-tree.h: Declare it.
+
 2009-12-11  Dodji Seketeli  <dodji@redhat.com>
 
        PR c++/42225
index d0a0435..eb7f06d 100644 (file)
@@ -5336,6 +5336,7 @@ extern tree convert_for_initialization            (tree, tree, tree, int,
                                                  tsubst_flags_t);
 extern int comp_ptr_ttypes                     (tree, tree);
 extern bool comp_ptr_ttypes_const              (tree, tree);
+extern bool error_type_p                       (const_tree);
 extern int ptr_reasonably_similar              (const_tree, const_tree);
 extern tree build_ptrmemfunc                   (tree, tree, int, bool);
 extern int cp_type_quals                       (const_tree);
index 791b506..782502d 100644 (file)
@@ -7471,6 +7471,44 @@ comp_ptr_ttypes (tree to, tree from)
   return comp_ptr_ttypes_real (to, from, 1);
 }
 
+/* Returns true iff FNTYPE is a non-class type that involves
+   error_mark_node.  We can get FUNCTION_TYPE with buried error_mark_node
+   if a parameter type is ill-formed.  */
+
+bool
+error_type_p (const_tree type)
+{
+  tree t;
+
+  switch (TREE_CODE (type))
+    {
+    case ERROR_MARK:
+      return true;
+
+    case POINTER_TYPE:
+    case REFERENCE_TYPE:
+    case OFFSET_TYPE:
+      return error_type_p (TREE_TYPE (type));
+
+    case FUNCTION_TYPE:
+    case METHOD_TYPE:
+      if (error_type_p (TREE_TYPE (type)))
+       return true;
+      for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
+       if (error_type_p (TREE_VALUE (t)))
+         return true;
+      return false;
+
+    case RECORD_TYPE:
+      if (TYPE_PTRMEMFUNC_P (type))
+       return error_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type));
+      return false;
+
+    default:
+      return false;
+    }
+}
+
 /* Returns 1 if to and from are (possibly multi-level) pointers to the same
    type or inheritance-related types, regardless of cv-quals.  */
 
@@ -7480,9 +7518,10 @@ ptr_reasonably_similar (const_tree to, const_tree from)
   for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
     {
       /* Any target type is similar enough to void.  */
-      if (TREE_CODE (to) == VOID_TYPE
-         || TREE_CODE (from) == VOID_TYPE)
-       return 1;
+      if (TREE_CODE (to) == VOID_TYPE)
+       return !error_type_p (from);
+      if (TREE_CODE (from) == VOID_TYPE)
+       return !error_type_p (to);
 
       if (TREE_CODE (to) != TREE_CODE (from))
        return 0;
@@ -7502,7 +7541,7 @@ ptr_reasonably_similar (const_tree to, const_tree from)
        return 1;
 
       if (TREE_CODE (to) == FUNCTION_TYPE)
-       return 1;
+       return !error_type_p (to) && !error_type_p (from);
 
       if (TREE_CODE (to) != POINTER_TYPE)
        return comptypes
index 598c1aa..92163b3 100644 (file)
@@ -1,3 +1,8 @@
+2009-12-11  Jason Merrill  <jason@redhat.com>
+
+       PR c++/42219
+       * g++.dg/conversion/err-recover1.C: New.
+
 2009-12-11  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/42335
diff --git a/gcc/testsuite/g++.dg/conversion/err-recover1.C b/gcc/testsuite/g++.dg/conversion/err-recover1.C
new file mode 100644 (file)
index 0000000..9723789
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/42219
+
+void foo(const void);          // { dg-error "incomplete|const" }
+
+void bar()
+{
+  void (*pf)() = foo;          // { dg-error "cannot convert" }
+}