Author: erichkeane
Date: Tue Jun 12 06:59:32 2018
New Revision: 334503

Fix overload resolution between Ptr-To-Member and Bool

As reported here (
and discovered independently when looking at plum-hall tests,
we incorrectly implemented over.ics.rank, which says "A conversion
that is not a conversion of a pointer, or pointer to member, to bool
is better than another conversion that is such a conversion.".

In the current Draft (N4750), this is phrased slightly differently in
paragraph 4.1: A conversion that does not convert a pointer, a pointer
to member, or std::nullptr_t to bool is better than one that does.

The comment on isPointerConversionToBool (the changed function)
also confirms that this is the case (note outdated reference):
isPointerConversionToBool - Determines whether this conversion is
a conversion of a pointer or pointer-to-member to bool. This is
used as part of the ranking of standard conversion sequences

However, despite this comment, it didn't check isMemberPointerType
on the 'FromType', presumably incorrectly assuming that 'isPointerType' 
matched it.  This patch fixes this by adding isMemberPointerType to
this function. Additionally, member function pointers are just 
MemberPointerTypes that point to functions insted of data, so that
is fixed in this patch as well.


Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Jun 12 06:59:32 2018
@@ -223,6 +223,7 @@ bool StandardConversionSequence::isPoint
   // a pointer.
   if (getToType(1)->isBooleanType() &&
       (getFromType()->isPointerType() ||
+       getFromType()->isMemberPointerType() ||
        getFromType()->isObjCObjectPointerType() ||
        getFromType()->isBlockPointerType() ||
        getFromType()->isNullPtrType() ||

Modified: cfe/trunk/test/SemaCXX/overload-call.cpp
--- cfe/trunk/test/SemaCXX/overload-call.cpp (original)
+++ cfe/trunk/test/SemaCXX/overload-call.cpp Tue Jun 12 06:59:32 2018
@@ -667,3 +667,24 @@ namespace ProduceNotesAfterSFINAEFailure
   void f(void*, A); // expected-note {{candidate function not viable}}
   void g() { f(1, 2); } // expected-error {{no matching function}}
+namespace PR19808 {
+  struct B {
+    int i;
+    void bar();
+  };
+  struct D : public B{};
+  void f(bool);
+  void f(int D::*);
+  void f(void (D::*)());
+  void Usage() {
+    int B::*pmem;
+    void (B::*pmf)();
+    // These should not be ambiguous.
+    f(pmem);
+    f(pmf);
+  }

cfe-commits mailing list

Reply via email to