]> granicus.if.org Git - clang/commitdiff
Objective-C. Diagnose assigning a block pointer type to
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 30 May 2014 16:35:53 +0000 (16:35 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 30 May 2014 16:35:53 +0000 (16:35 +0000)
an Objective-C object type other than 'id'.
// rdar://16739120

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

lib/Sema/SemaExpr.cpp
test/SemaObjC/block-type-safety.m

index 9b4c6382dceff36ab7b21be51e44d29bc1a6cc29..be00c0e8b37fc2bebeae22fe52b43bc831ce6e92 100644 (file)
@@ -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;
index 56342baae528783cd148f4daa5e4e154a10c7899..45866704b56d173714d8d968a75c71495c618ed0 100644 (file)
@@ -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 *'}}
+}
+