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.

/////////////////////
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

Reply via email to