aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2010-04-01 19:50:22 +0000
committerFariborz Jahanian <fjahanian@apple.com>2010-04-01 19:50:22 +0000
commit699fca2d7aeb854e4c4d68b3483734b52b7cc932 (patch)
treedb88add97c21072e26c9dc2a8421410ebb237b53
parentb7a09260204f2079e0f998bf7ee52b95122a4c5d (diff)
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
-rw-r--r--lib/AST/ASTContext.cpp5
-rw-r--r--test/SemaObjC/block-type-safety.m8
2 files changed, 7 insertions, 6 deletions
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<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];
}];
}