re PR c++/8171 (Cannot compare pointer to member function of base and derived class)
authorOllie Wild <aaw@google.com>
Sat, 1 Dec 2007 08:56:55 +0000 (08:56 +0000)
committerOllie Wild <aaw@gcc.gnu.org>
Sat, 1 Dec 2007 08:56:55 +0000 (08:56 +0000)
PR c++/8171

gcc/cp/
* typeck.c (build_binary_op): Add conversion of pointers to function
members appearing as operands to the equality operators.

gcc/testsuite/
* g++.dg/conversion/ptrmem9.C: New test.

From-SVN: r130554

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/conversion/ptrmem9.C [new file with mode: 0644]

index b8f1e889de9e876edd53b75454d30b12e9cc50a2..494c98f418ada998e3ac011aff2c251cebfe9812 100644 (file)
@@ -1,3 +1,9 @@
+2007-12-01  Ollie Wild  <aaw@google.com>
+
+       PR c++/8171
+       * typeck.c (build_binary_op): Add conversion of pointers to function
+       members appearing as operands to the equality operators.
+
 2007-11-30  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/34275
index c43eb793584121dc3e3ccd6022eb886ae8fd8173..6a3405a6c364a98a8d7cfba1aefeb3af5bdaaecc 100644 (file)
@@ -3394,9 +3394,9 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
        }
       else if (TYPE_PTRMEMFUNC_P (type1) && null_ptr_cst_p (op0))
        return cp_build_binary_op (code, op1, op0);
-      else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1)
-              && same_type_p (type0, type1))
+      else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1))
        {
+         tree type;
          /* E will be the final comparison.  */
          tree e;
          /* E1 and E2 are for scratch.  */
@@ -3407,6 +3407,16 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
          tree delta0;
          tree delta1;
 
+         type = composite_pointer_type (type0, type1, op0, op1, "comparison");
+
+         if (!same_type_p (TREE_TYPE (op0), type))
+           op0 = cp_convert_and_check (type, op0);
+         if (!same_type_p (TREE_TYPE (op1), type))
+           op1 = cp_convert_and_check (type, op1);
+
+         if (op0 == error_mark_node || op1 == error_mark_node)
+           return error_mark_node;
+
          if (TREE_SIDE_EFFECTS (op0))
            op0 = save_expr (op0);
          if (TREE_SIDE_EFFECTS (op1))
index 3c09a8db6989da89d74a5210504512e8d00ae0eb..272cba92c14a0ab9f3bf12ae9b6c3b6aee7ddeee 100644 (file)
@@ -1,3 +1,8 @@
+2007-12-01  Ollie Wild  <aaw@google.com>
+
+       PR c++/8171
+       * g++.dg/conversion/ptrmem9.C: New test.
+
 2007-11-30  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libfortran/34291
diff --git a/gcc/testsuite/g++.dg/conversion/ptrmem9.C b/gcc/testsuite/g++.dg/conversion/ptrmem9.C
new file mode 100644 (file)
index 0000000..2ccd683
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright (C) 2007 Free Software Foundation
+// Contributed by Ollie Wild <aaw@google.com>
+// { dg-do compile }
+
+// Test implicit conversion of pointers to member functions appearing as
+// operands of the equality operators.
+
+struct B { };
+
+struct BV { };
+
+struct D : B, virtual BV { };
+
+struct C { };
+
+void f ()
+{
+  void (D::*pd) () = 0;
+  void (B::*pb) () = 0;
+  void (BV::*pbv) () = 0;
+  void (C::*pc) () = 0;
+
+  pd == pb;
+  pd == pbv;  // { dg-error "" }
+  pd == pc;   // { dg-error "" }
+}