]> granicus.if.org Git - clang/commitdiff
Relax the typesafty rules of block pointers types which
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 1 Apr 2010 19:50:22 +0000 (19:50 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 1 Apr 2010 19:50:22 +0000 (19:50 +0000)
take'id' or return 'id' in their type. Fixes radar 7814131.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100129 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp
test/SemaObjC/block-type-safety.m

index 31c4370ad33414416dde0fac59d5ce72d8c2c9c6..c77acce1bd067179489e69c77719cd90c8f1919e 100644 (file)
@@ -4136,14 +4136,15 @@ bool ASTContext::canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT,
 bool ASTContext::canAssignObjCInterfacesInBlockPointer(
                                          const ObjCObjectPointerType *LHSOPT,
                                          const ObjCObjectPointerType *RHSOPT) {
-  if (RHSOPT->isObjCBuiltinType())
+  if (RHSOPT->isObjCBuiltinType() || 
+      LHSOPT->isObjCIdType() || LHSOPT->isObjCQualifiedIdType())
     return true;
   
   if (LHSOPT->isObjCBuiltinType()) {
     return RHSOPT->isObjCBuiltinType() || RHSOPT->isObjCQualifiedIdType();
   }
   
-  if (LHSOPT->isObjCQualifiedIdType() || RHSOPT->isObjCQualifiedIdType())
+  if (RHSOPT->isObjCQualifiedIdType())
     return ObjCQualifiedIdTypesAreCompatible(QualType(LHSOPT,0),
                                              QualType(RHSOPT,0),
                                              false);
index dab0af4026df98eb3d0b74d1039202206aa171cc..b40f9b09358555210baa4d7b722514aa0127bdcf 100644 (file)
@@ -34,11 +34,11 @@ void test1() {
 
     r0(^Super* () { return 0; });  // OK
     r0(^Sub* () { return 0; });    // OK, variable of type Super* gets return value of type Sub*
-    r0(^id () { return 0; });  // expected-error {{incompatible block pointer types passing 'id (^)(void)', expected 'Super *(^)()'}}
+    r0(^id () { return 0; });
 
     r1(^Super* () { return 0; });  // expected-error {{incompatible block pointer types passing 'Super *(^)(void)', expected 'Sub *(^)()'}}
     r1(^Sub* () { return 0; });    // OK
-    r1(^id () { return 0; });      // expected-error {{incompatible block pointer types passing 'id (^)(void)', expected 'Sub *(^)()'}}
+    r1(^id () { return 0; }); 
      
     r2(^id<NSObject>() { return 0; });
 }
@@ -60,7 +60,7 @@ void f1(void (^f)(id x)) {
 void test2(void) 
 { 
   f0(^(id a) { }); // OK
-  f1(^(A* a) { }); // expected-error {{incompatible block pointer types passing 'void (^)(A *)', expected 'void (^)(id)'}}
+  f1(^(A* a) { });
    f1(^(id<NSObject> a) { });  // OK
 }
 
@@ -80,7 +80,7 @@ void test2(void)
 
 // programmer wants to write this:
    -printMyThings1 {
-       [myThings enumerateObjectsWithBlock: ^(MyThing *obj) { // expected-error {{incompatible block pointer types sending 'void (^)(MyThing *)', expected 'void (^)(id)'}}
+       [myThings enumerateObjectsWithBlock: ^(MyThing *obj) {
            [obj printThing];
        }];
    }