aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOllie Wild <aaw@google.com>2007-12-01 08:56:55 +0000
committerOllie Wild <aaw@gcc.gnu.org>2007-12-01 08:56:55 +0000
commit867f133ec412ca7592f16b804b34aac9b82703f2 (patch)
treef21ad738b7b0305e3f87dff48b61d0d0961b1a69
parentc23ebce246998f20609482a675ac202f535c1676 (diff)
downloadgcc-867f133ec412ca7592f16b804b34aac9b82703f2.zip
gcc-867f133ec412ca7592f16b804b34aac9b82703f2.tar.gz
gcc-867f133ec412ca7592f16b804b34aac9b82703f2.tar.bz2
re PR c++/8171 (Cannot compare pointer to member function of base and derived class)
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
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck.c14
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/conversion/ptrmem9.C26
4 files changed, 49 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index b8f1e88..494c98f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index c43eb79..6a3405a 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -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))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3c09a8d..272cba9 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..2ccd683
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/ptrmem9.C
@@ -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 "" }
+}