]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/38228 (ICE with invalid use of bound member function)
authorDodji Seketeli <dodji@redhat.com>
Thu, 23 Apr 2009 15:55:47 +0000 (15:55 +0000)
committerDodji Seketeli <dodji@gcc.gnu.org>
Thu, 23 Apr 2009 15:55:47 +0000 (17:55 +0200)
2009-04-23  Dodji Seketeli  <dodji@redhat.com>

    gcc/cp/ChangeLog:
     PR c++/38228
     * pt.c (unify): Do not allow the result of a template argument
     deduction to be a METHOD_TYPE.
     * cvt.c (cp_convert): Report a meaningful error for non-valid use
     of pointer to member functions during conversions.
     * call.c (build_new_op): Report a meaningful error for non-valid
     use of pointer to member functions in binary expressions.
     * typeck.c (invalid_nonstatic_memfn_p): Do not crash when EXPR is
     NULL;

    gcc/testsuite/ChangeLog:
     PR c++/38228
     * g++.dg/expr/bound-mem-fun.C: New test.

From-SVN: r146651

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/cvt.c
gcc/cp/pt.c
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/expr/bound-mem-fun.C [new file with mode: 0644]

index 7e5eb2d78cb01d4a5869dc6c18f7097d69bdab00..395196af05ea1ca606346eebc1f406d7b321e5cd 100644 (file)
@@ -1,3 +1,15 @@
+2009-04-23  Dodji Seketeli  <dodji@redhat.com>
+
+       PR c++/38228
+       * pt.c (unify): Do not allow the result of a template argument
+       deduction to be a METHOD_TYPE.
+       * cvt.c (cp_convert): Report a meaningful error for non-valid use
+       of pointer to member functions during conversions.
+       * call.c (build_new_op): Report a meaningful error for non-valid
+       use of pointer to member functions in binary expressions.
+       * typeck.c (invalid_nonstatic_memfn_p): Do not crash when EXPR is
+       NULL;
+
 2009-04-22  Dodji Seketeli  <dodji@redhat.com>
 
        PR c++/39639
index 13713131d0b1a930979f62240d0697033781fa8d..fb2420f2a596fe6ff271485759fe6fedb297a293 100644 (file)
@@ -3910,8 +3910,20 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3,
        default:
          if (flags & LOOKUP_COMPLAIN)
            {
-             op_error (code, code2, arg1, arg2, arg3, "no match");
-             print_z_candidates (candidates);
+               /* If one of the arguments of the operator represents
+                  an invalid use of member function pointer, try to report
+                  a meaningful error ...  */
+               if (invalid_nonstatic_memfn_p (arg1)
+                   || invalid_nonstatic_memfn_p (arg2)
+                   || invalid_nonstatic_memfn_p (arg3))
+                 /* We displayed the error message.  */;
+               else
+                 {
+                   /* ... Otherwise, report the more generic
+                      "no matching operator found" error */
+                   op_error (code, code2, arg1, arg2, arg3, "no match");
+                   print_z_candidates (candidates);
+                 }
            }
          result = error_mark_node;
          break;
index a75036f53c115353bcc1d9d41a5dd14517a52efd..7da8cc3cbf6d680e24b22fad8a6e8cf54d97b039 100644 (file)
@@ -740,8 +740,15 @@ ocp_convert (tree type, tree expr, int convtype, int flags)
     }
 
   if (flags & LOOKUP_COMPLAIN)
-    error ("conversion from %qT to non-scalar type %qT requested",
-          TREE_TYPE (expr), type);
+    {
+      /* If the conversion failed and expr was an invalid use of pointer to
+        member function, try to report a meaningful error.  */
+      if (invalid_nonstatic_memfn_p (expr))
+       /* We displayed the error message.  */;
+      else
+       error ("conversion from %qT to non-scalar type %qT requested",
+              TREE_TYPE (expr), type);
+    }
   return error_mark_node;
 }
 
index 8cf6f410e64c696fa09ff0889b8a629b20742dde..46866c030485f20091eda0948066b06e0ae3aaa8 100644 (file)
@@ -13035,6 +13035,13 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict)
          && !template_parameter_pack_p (parm))
        return 1;
 
+      /* If the argument deduction results is a METHOD_TYPE,
+         then there is a problem.
+         METHOD_TYPE doesn't map to any real C++ type the result of
+        the deduction can not be of that type.  */
+      if (TREE_CODE (arg) == METHOD_TYPE)
+       return 1;
+
       TREE_VEC_ELT (INNERMOST_TEMPLATE_ARGS (targs), idx) = arg;
       return 0;
 
index e8094b746845fa3ef18eda69239a4ff551bac1f7..10c3a022c3d8e8e0fd1e92f9bea35a302787b4c6 100644 (file)
@@ -1450,7 +1450,7 @@ cxx_sizeof_or_alignof_expr (tree e, enum tree_code op)
 bool
 invalid_nonstatic_memfn_p (const_tree expr)
 {
-  if (TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE)
+  if (expr && TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE)
     {
       error ("invalid use of non-static member function");
       return true;
index a9b3c604fc33303f034076f7776c1a55066fc8e8..0a7cd962005a3a64c9584e20c0b844d2c7bd6f51 100644 (file)
@@ -1,3 +1,8 @@
+2009-04-23  Dodji Seketeli  <dodji@redhat.com>
+
+       PR c++/38228
+       * g++.dg/expr/bound-mem-fun.C: New test.
+
 2009-04-22  Dodji Seketeli  <dodji@redhat.com>
 
        PR c++/39639
diff --git a/gcc/testsuite/g++.dg/expr/bound-mem-fun.C b/gcc/testsuite/g++.dg/expr/bound-mem-fun.C
new file mode 100644 (file)
index 0000000..9e699b6
--- /dev/null
@@ -0,0 +1,18 @@
+// Contributed by Dodji Seketeli <dodji@redhat.com>
+// Origin PR c++/38228
+// { dg-do "compile" }
+
+struct A
+{
+  A ();
+  template<typename T> A(T);
+};
+
+struct B
+{
+  int foo();
+};
+
+A a = B().*(&B::foo); // { dg-error "invalid use of non-static member function" }
+
+