Add implicit conversions for Objective-C qualified ids, e.g.,
id<P0>
The intended overloading behavior of these entities isn't entirely
clear, and GCC seems to have some strange limitations (e.g., the
inability to overload on id<P0> vs. id<P1>). We'll want to revisit
these semantics and determine just how Objective-C++ overloading
should really work.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60142 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 43b5e77..80bb9ed 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -744,7 +744,13 @@
/// might differ from ToType in its cv-qualifiers at some level) into
/// ConvertedType.
///
-/// This routine also supports conversions to and from block pointers.
+/// This routine also supports conversions to and from block pointers
+/// and conversions with Objective-C's 'id', 'id<protocols...>', and
+/// pointers to interfaces. FIXME: Once we've determined the
+/// appropriate overloading rules for Objective-C, we may want to
+/// split the Objective-C checks into a different routine; however,
+/// GCC seems to consider all of these conversions to be pointer
+/// conversions, so for now they live here.
bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
QualType& ConvertedType)
{
@@ -761,6 +767,13 @@
return true;
}
+ // Conversions with Objective-C's id<...>.
+ if ((FromType->isObjCQualifiedIdType() || ToType->isObjCQualifiedIdType()) &&
+ ObjCQualifiedIdTypesAreCompatible(ToType, FromType, /*compare=*/false)) {
+ ConvertedType = ToType;
+ return true;
+ }
+
const PointerType* ToTypePtr = ToType->getAsPointerType();
if (!ToTypePtr)
return false;
@@ -1332,7 +1345,10 @@
// Compare based on pointer conversions.
if (SCS1.Second == ICK_Pointer_Conversion &&
- SCS2.Second == ICK_Pointer_Conversion) {
+ SCS2.Second == ICK_Pointer_Conversion &&
+ /*FIXME: Remove if Objective-C id conversions get their own rank*/
+ FromType1->isPointerType() && FromType2->isPointerType() &&
+ ToType1->isPointerType() && ToType2->isPointerType()) {
QualType FromPointee1
= FromType1->getAsPointerType()->getPointeeType().getUnqualifiedType();
QualType ToPointee1