summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2014-05-30 16:35:53 +0000
committerFariborz Jahanian <fjahanian@apple.com>2014-05-30 16:35:53 +0000
commitb3a706870021df81ca678400746ed44d20b74f49 (patch)
treeb9e6f6ac75ef3770a233f42fead87b63d4f1fbec
parent0ae08a849d432feaf4268872b506a3be9b2a1f09 (diff)
downloadbcm5719-llvm-b3a706870021df81ca678400746ed44d20b74f49.tar.gz
bcm5719-llvm-b3a706870021df81ca678400746ed44d20b74f49.zip
Objective-C. Diagnose assigning a block pointer type to
an Objective-C object type other than 'id'. // rdar://16739120 llvm-svn: 209906
-rw-r--r--clang/lib/Sema/SemaExpr.cpp4
-rw-r--r--clang/test/SemaObjC/block-type-safety.m22
2 files changed, 24 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 9b4c6382dce..be00c0e8b37 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6435,8 +6435,8 @@ Sema::CheckAssignmentConstraints(QualType LHSType, ExprResult &RHS,
return IncompatiblePointer;
}
- // T^ -> A*
- if (RHSType->isBlockPointerType()) {
+ // T^ -> id; not T^ ->A* and not T^ -> id<P>
+ if (RHSType->isBlockPointerType() && LHSType->isObjCIdType()) {
maybeExtendBlockObject(*this, RHS);
Kind = CK_BlockPointerToObjCPointerCast;
return Compatible;
diff --git a/clang/test/SemaObjC/block-type-safety.m b/clang/test/SemaObjC/block-type-safety.m
index 56342baae52..45866704b56 100644
--- a/clang/test/SemaObjC/block-type-safety.m
+++ b/clang/test/SemaObjC/block-type-safety.m
@@ -155,3 +155,25 @@ void f() {
return NSOrderedSame;
}];
}
+
+// rdar://16739120
+@protocol P1 @end
+@protocol P2 @end
+
+void Test() {
+void (^aBlock)();
+id anId = aBlock; // OK
+
+id<P1,P2> anQualId = aBlock; // expected-error {{initializing 'id<P1,P2>' with an expression of incompatible type 'void (^)()'}}
+
+NSArray* anArray = aBlock; // expected-error {{initializing 'NSArray *' with an expression of incompatible type 'void (^)()'}}
+
+aBlock = anId; // OK
+
+id<P1,P2> anQualId1;
+aBlock = anQualId1; // expected-error {{assigning to 'void (^)()' from incompatible type 'id<P1,P2>'}}
+
+NSArray* anArray1;
+aBlock = anArray1; // expected-error {{assigning to 'void (^)()' from incompatible type 'NSArray *'}}
+}
+
OpenPOWER on IntegriCloud