public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Ollie Wild" <aaw@google.com>
To: "GCC Patches" <gcc-patches@gcc.gnu.org>
Subject: Re: PATCH: fix comparison of C++ pointers to member functions
Date: Wed, 28 Nov 2007 15:01:00 -0000	[thread overview]
Message-ID: <65dd6fd50711280237j4f5177f7m561ace90363e77b7@mail.gmail.com> (raw)
In-Reply-To: <65dd6fd50711122217t322e6852r5cda0b4c36e95d70@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 975 bytes --]

On Nov 12, 2007 10:17 PM, Ollie Wild <aaw@google.com> wrote:
>
> It might help if I attached the patch.

It's been a couple weeks since I sent this out, so here's a quick
ping.  Details reproduced below:

Section 5.10 of the C++ standard states:

"In addition, pointers to members can be compared, or a pointer to
member and a null pointer constant.  Pointer to member conversions
(4.11) and qualification conversions (4.4) are performed to bring them
to a common type."

The C++ front end fails to perform the indicated conversions when
comparing pointers to member functions.  This patch rectifies this.

Tested with a C/C++/Java bootstrap and testsuite on i686-pc-linux-gnu.

Ollie

:ADDPATCH c++:

2007-11-12  Ollie Wild  <aaw@google.com>

       * typeck.c (build_binary_op): Add conversion of pointers to member
       functions appearing as operands to the equality operators.

2007-11-12  Ollie Wild  <aaw@google.com>

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

[-- Attachment #2: ptrmem_equality.txt --]
[-- Type: text/plain, Size: 1915 bytes --]

diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index d167de2..270defe 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -3392,9 +3392,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.  */
@@ -3405,6 +3405,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 (TREE_TYPE (op0) != type)
+	    op0 = cp_convert_and_check (type, op0);
+	  if (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/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 "" }
+}

      reply	other threads:[~2007-11-28 10:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-13 10:17 Ollie Wild
2007-11-13 10:24 ` Ollie Wild
2007-11-28 15:01   ` Ollie Wild [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=65dd6fd50711280237j4f5177f7m561ace90363e77b7@mail.gmail.com \
    --to=aaw@google.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).