[cfe-commits] r84660 - in /cfe/trunk: lib/Sema/SemaOverload.cpp test/SemaCXX/ptrtomember-overload-resolution.cpp
Fariborz Jahanian
fjahanian at apple.com
Tue Oct 20 13:04:46 PDT 2009
Author: fjahanian
Date: Tue Oct 20 15:04:46 2009
New Revision: 84660
URL: http://llvm.org/viewvc/llvm-project?rev=84660&view=rev
Log:
Patch implements ranking conversions between member pointers [over.ics.rank]
Added:
cfe/trunk/test/SemaCXX/ptrtomember-overload-resolution.cpp
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=84660&r1=84659&r2=84660&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Oct 20 15:04:46 2009
@@ -1935,13 +1935,42 @@
}
}
+ // conversion of A::* to B::* is better than conversion of A::* to C::*,
- // FIXME: conversion of A::* to B::* is better than conversion of
- // A::* to C::*,
-
- // FIXME: conversion of B::* to C::* is better than conversion of
- // A::* to C::*, and
-
+ if (SCS1.Second == ICK_Pointer_Member && SCS2.Second == ICK_Pointer_Member &&
+ FromType1->isMemberPointerType() && FromType2->isMemberPointerType() &&
+ ToType1->isMemberPointerType() && ToType2->isMemberPointerType()) {
+ const MemberPointerType * FromMemPointer1 =
+ FromType1->getAs<MemberPointerType>();
+ const MemberPointerType * ToMemPointer1 =
+ ToType1->getAs<MemberPointerType>();
+ const MemberPointerType * FromMemPointer2 =
+ FromType2->getAs<MemberPointerType>();
+ const MemberPointerType * ToMemPointer2 =
+ ToType2->getAs<MemberPointerType>();
+ const Type *FromPointeeType1 = FromMemPointer1->getClass();
+ const Type *ToPointeeType1 = ToMemPointer1->getClass();
+ const Type *FromPointeeType2 = FromMemPointer2->getClass();
+ const Type *ToPointeeType2 = ToMemPointer2->getClass();
+ QualType FromPointee1 = QualType(FromPointeeType1, 0).getUnqualifiedType();
+ QualType ToPointee1 = QualType(ToPointeeType1, 0).getUnqualifiedType();
+ QualType FromPointee2 = QualType(FromPointeeType2, 0).getUnqualifiedType();
+ QualType ToPointee2 = QualType(ToPointeeType2, 0).getUnqualifiedType();
+ if (FromPointee1 == FromPointee2 && ToPointee1 != ToPointee2) {
+ if (IsDerivedFrom(ToPointee1, ToPointee2))
+ return ImplicitConversionSequence::Worse;
+ else if (IsDerivedFrom(ToPointee2, ToPointee1))
+ return ImplicitConversionSequence::Better;
+ }
+ // conversion of B::* to C::* is better than conversion of A::* to C::*
+ if (ToPointee1 == ToPointee2 && FromPointee1 != FromPointee2) {
+ if (IsDerivedFrom(FromPointee1, FromPointee2))
+ return ImplicitConversionSequence::Better;
+ else if (IsDerivedFrom(FromPointee2, FromPointee1))
+ return ImplicitConversionSequence::Worse;
+ }
+ }
+
if (SCS1.CopyConstructor && SCS2.CopyConstructor &&
SCS1.Second == ICK_Derived_To_Base) {
// -- conversion of C to B is better than conversion of C to A,
Added: cfe/trunk/test/SemaCXX/ptrtomember-overload-resolution.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ptrtomember-overload-resolution.cpp?rev=84660&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/ptrtomember-overload-resolution.cpp (added)
+++ cfe/trunk/test/SemaCXX/ptrtomember-overload-resolution.cpp Tue Oct 20 15:04:46 2009
@@ -0,0 +1,44 @@
+// RUN: clang-cc -fsyntax-only -verify %s -std=c++0x
+
+// 13.3.3.2 Ranking implicit conversion sequences
+// conversion of A::* to B::* is better than conversion of A::* to C::*,
+struct A {
+int Ai;
+};
+
+struct B : public A {};
+struct C : public B {};
+
+const char * f(int C::*){ return ""; }
+int f(int B::*) { return 1; }
+
+struct D : public C {};
+
+const char * g(int B::*){ return ""; }
+int g(int D::*) { return 1; }
+
+void test()
+{
+ int i = f(&A::Ai);
+
+ const char * str = g(&A::Ai);
+}
+
+// conversion of B::* to C::* is better than conversion of A::* to C::*
+typedef void (A::*pmfa)();
+typedef void (B::*pmfb)();
+typedef void (C::*pmfc)();
+
+struct X {
+ operator pmfa();
+ operator pmfb();
+};
+
+
+void g(pmfc);
+
+void test2(X x)
+{
+ g(x);
+}
+
More information about the cfe-commits
mailing list