From: Fariborz Jahanian Date: Thu, 1 Apr 2010 19:50:22 +0000 (+0000) Subject: Relax the typesafty rules of block pointers types which X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=699fca2d7aeb854e4c4d68b3483734b52b7cc932;p=clang Relax the typesafty rules of block pointers types which 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 --- diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 31c4370ad3..c77acce1bd 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -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); diff --git a/test/SemaObjC/block-type-safety.m b/test/SemaObjC/block-type-safety.m index dab0af4026..b40f9b0935 100644 --- a/test/SemaObjC/block-type-safety.m +++ b/test/SemaObjC/block-type-safety.m @@ -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() { 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 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]; }]; }