diff mbox

[C++,/,RFC] PR 38174

Message ID 4E97A081.6060200@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Oct. 14, 2011, 2:37 a.m. UTC
Hi,

so, assuming I understood correctly Jason's tips (thanks again for your 
patience ;) the fix for this pretty old issue seems even simpler than I 
guessed at triage time, because we already have available 
composite_pointer_type, doing all the real work.
The below passes the testsuite on x86_64-linux.

What do you think?

Paolo.

/////////////////////

Comments

Jason Merrill Oct. 14, 2011, 1:54 p.m. UTC | #1
On 10/13/2011 10:37 PM, Paolo Carlini wrote:
> +      if ((TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
> +	  || (TYPE_PTRMEM_P (type1) && TYPE_PTRMEM_P (type2))
> +	  || TYPE_PTRMEMFUNC_P (type1))

You don't need to check TYPE_PTR_P or TYPE_PTRMEM_P for type2 here (or 
in the condition above) because we already established that type1 and 
type2 have the same TREE_CODE.  OK with that change.

Jason
diff mbox

Patch

Index: testsuite/g++.dg/overload/operator4.C
===================================================================
--- testsuite/g++.dg/overload/operator4.C	(revision 0)
+++ testsuite/g++.dg/overload/operator4.C	(revision 0)
@@ -0,0 +1,14 @@ 
+// PR c++/38174
+
+struct VolatileIntPtr {
+  operator int volatile *();
+};
+
+struct ConstIntPtr {
+  operator int const *();
+};
+
+void test_with_ptrs(VolatileIntPtr vip, ConstIntPtr cip) {
+  bool b1 = (vip == cip);
+  long p1 = vip - cip;
+}
Index: cp/call.c
===================================================================
--- cp/call.c	(revision 179947)
+++ cp/call.c	(working copy)
@@ -2582,6 +2582,23 @@  add_builtin_candidate (struct z_candidate **candid
 	  || MAYBE_CLASS_TYPE_P (type1)
 	  || TREE_CODE (type1) == ENUMERAL_TYPE))
     {
+      if ((TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
+	  || (TYPE_PTRMEM_P (type1) && TYPE_PTRMEM_P (type2))
+	  || TYPE_PTRMEMFUNC_P (type1))
+	{
+	  tree cptype = composite_pointer_type (type1, type2,
+						error_mark_node,
+						error_mark_node,
+						CPO_CONVERSION,
+						tf_none);
+	  if (cptype != error_mark_node)
+	    {
+	      build_builtin_candidate
+		(candidates, fnname, cptype, cptype, args, argtypes, flags);
+	      return;
+	    }
+	}
+
       build_builtin_candidate
 	(candidates, fnname, type1, type1, args, argtypes, flags);
       build_builtin_candidate