[cfe-commits] r60142 - in /cfe/trunk: lib/Sema/SemaOverload.cpp test/SemaObjCXX/overload.mm

Douglas Gregor doug.gregor at gmail.com
Wed Nov 26 17:19:21 PST 2008


Author: dgregor
Date: Wed Nov 26 19:19:21 2008
New Revision: 60142

URL: http://llvm.org/viewvc/llvm-project?rev=60142&view=rev
Log:
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.


Modified:
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/SemaObjCXX/overload.mm

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=60142&r1=60141&r2=60142&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Nov 26 19:19:21 2008
@@ -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 

Modified: cfe/trunk/test/SemaObjCXX/overload.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/overload.mm?rev=60142&r1=60141&r2=60142&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjCXX/overload.mm (original)
+++ cfe/trunk/test/SemaObjCXX/overload.mm Wed Nov 26 19:19:21 2008
@@ -1,10 +1,19 @@
 // RUN clang -fsyntax-only -verify %s
- at interface A 
+ at protocol P0
+ at end
+
+ at protocol P1
+ at end
+
+ at interface A <P0>
 @end
 
 @interface B : A
 @end
 
+ at interface C <P1>
+ at end
+
 int& f(A*);
 float& f(B*);
 void g(A*);
@@ -37,3 +46,13 @@
   int& i3 = cv2(a);
   float& f3 = cv2(ac);
 }
+
+
+int& qualid(id<P0>);
+float& qualid(id<P1>); // FIXME: GCC complains that this isn't an overload. Is it?
+
+void qualid_test(A *a, B *b, C *c) {
+  int& i1 = qualid(a);
+  int& i2 = qualid(b);
+  float& f1 = qualid(c);
+}





More information about the cfe-commits mailing list