[cfe-commits] r68899 - in /cfe/trunk: lib/Sema/SemaExpr.cpp lib/Sema/SemaExprObjC.cpp test/SemaObjC/comptypes-1.m test/SemaObjC/id-1.m

Chris Lattner sabre at nondot.org
Sun Apr 12 02:03:09 PDT 2009


Author: lattner
Date: Sun Apr 12 04:02:39 2009
New Revision: 68899

URL: http://llvm.org/viewvc/llvm-project?rev=68899&view=rev
Log:
Fix rdar://6770142 - Class and qualified id's are compatible, just like
Class and unqualified id's are.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/test/SemaObjC/comptypes-1.m
    cfe/trunk/test/SemaObjC/id-1.m

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Apr 12 04:02:39 2009
@@ -3060,8 +3060,7 @@
       if (PerformImplicitConversion(rExpr, lhsType.getUnqualifiedType(),
                                     "assigning"))
         return Incompatible;
-      else
-        return Compatible;
+      return Compatible;
     }
 
     // FIXME: Currently, we fall through and treat C++ classes like C

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Sun Apr 12 04:02:39 2009
@@ -681,11 +681,15 @@
   // Allow id<P..> and an 'id' or void* type in all cases.
   if (const PointerType *PT = lhs->getAsPointerType()) {
     QualType PointeeTy = PT->getPointeeType();
-    if (Context.isObjCIdStructType(PointeeTy) || PointeeTy->isVoidType())
+    if (PointeeTy->isVoidType() ||
+        Context.isObjCIdStructType(PointeeTy) || 
+        Context.isObjCClassStructType(PointeeTy))
       return true;
   } else if (const PointerType *PT = rhs->getAsPointerType()) {
     QualType PointeeTy = PT->getPointeeType();
-    if (Context.isObjCIdStructType(PointeeTy) || PointeeTy->isVoidType())
+    if (PointeeTy->isVoidType() ||
+        Context.isObjCIdStructType(PointeeTy) || 
+        Context.isObjCClassStructType(PointeeTy))
       return true;
   }
   

Modified: cfe/trunk/test/SemaObjC/comptypes-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/comptypes-1.m?rev=68899&r1=68898&r2=68899&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/comptypes-1.m (original)
+++ cfe/trunk/test/SemaObjC/comptypes-1.m Sun Apr 12 04:02:39 2009
@@ -44,7 +44,7 @@
   obj_p = obj;    /* Ok */
   obj_p = obj_c;  // expected-warning {{incompatible type assigning 'MyClass *', expected 'id<MyProtocol>'}}
   obj_p = obj_cp; /* Ok  */
-  obj_p = obj_C;  // expected-warning {{incompatible type assigning 'Class', expected 'id<MyProtocol>'}}
+  obj_p = obj_C;  // Ok
 
   /* Assigning to a 'MyOtherClass *' variable should always generate
      a warning, unless done from an 'id' or an 'id<MyProtocol>' (since

Modified: cfe/trunk/test/SemaObjC/id-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/id-1.m?rev=68899&r1=68898&r2=68899&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/id-1.m (original)
+++ cfe/trunk/test/SemaObjC/id-1.m Sun Apr 12 04:02:39 2009
@@ -1,6 +1,20 @@
 // RUN: clang-cc -fsyntax-only -verify %s
-/* Test attempt to redefine 'id' in an incompatible fashion.  */
 
-typedef int id;   // expected-error {{typedef redefinition with different types}}
+ at protocol Foo;
+
+Class T;
+id<Foo> S;
+id R;
+void foo() {
+  // Test assignment compatibility of Class and id.  No warning should be
+  // produced.
+  // rdar://6770142 - Class and id<foo> are compatible.
+  S = T; T = S;
+  R = T; T = R;
+  R = S; S = R;
+}
 
+// Test attempt to redefine 'id' in an incompatible fashion.
+typedef int id;   // expected-error {{typedef redefinition with different types}}
 id b;
+





More information about the cfe-commits mailing list