diff mbox

[C++,/,RFC] PR 38174

Message ID 4E98460B.8020503@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Oct. 14, 2011, 2:24 p.m. UTC
Hi,
> 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.
Thanks. I'm finishing regtesting again the below variant and mean to 
commit it if everything goes well.

Paolo.

//////////////////
/cp
2011-10-14  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/38174
	* call.c (add_builtin_candidate): If two pointers have a composite
	pointer type, generate a single candidate with that type.

/testsuite
2011-10-14  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/38174
	* g++.dg/overload/operator4.C: New.
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 179978)
+++ cp/call.c	(working copy)
@@ -2582,6 +2582,21 @@  add_builtin_candidate (struct z_candidate **candid
 	  || MAYBE_CLASS_TYPE_P (type1)
 	  || TREE_CODE (type1) == ENUMERAL_TYPE))
     {
+      if (TYPE_PTR_P (type1) || TYPE_PTR_TO_MEMBER_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