r209906 - Objective-C. Diagnose assigning a block pointer type to

Argyrios Kyrtzidis kyrtzidis at apple.com
Fri May 30 10:32:04 PDT 2014


This is giving an error in the following case, is this correct ?

#import <Foundation/Foundation.h>

typedef void(^blk)(void);

void foo(blk b) {
	id<NSObject> x = b; // error: initializing 'id<NSObject>' with an expression of incompatible type 'blk' (aka 'void (^)(void)')
}


> On May 30, 2014, at 9:35 AM, Fariborz Jahanian <fjahanian at apple.com> wrote:
> 
> Author: fjahanian
> Date: Fri May 30 11:35:53 2014
> New Revision: 209906
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=209906&view=rev
> Log:
> Objective-C. Diagnose assigning a block pointer type to
> an Objective-C object type other than 'id'. 
> // rdar://16739120
> 
> Modified:
>    cfe/trunk/lib/Sema/SemaExpr.cpp
>    cfe/trunk/test/SemaObjC/block-type-safety.m
> 
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=209906&r1=209905&r2=209906&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri May 30 11:35:53 2014
> @@ -6435,8 +6435,8 @@ Sema::CheckAssignmentConstraints(QualTyp
>       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;
> 
> Modified: cfe/trunk/test/SemaObjC/block-type-safety.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/block-type-safety.m?rev=209906&r1=209905&r2=209906&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaObjC/block-type-safety.m (original)
> +++ cfe/trunk/test/SemaObjC/block-type-safety.m Fri May 30 11:35:53 2014
> @@ -155,3 +155,25 @@ void f() {
>         return NSOrderedSame;
>    }];
> }
> +
> +// rdar://16739120
> + at protocol P1 @end
> + at 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 *'}}
> +}
> +
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list