diff options
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 4 | ||||
-rw-r--r-- | clang/test/SemaObjC/block-type-safety.m | 22 |
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 *'}} +} + |