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

Argyrios Kyrtzidis kyrtzidis at apple.com
Fri May 30 11:34:28 PDT 2014


> On May 30, 2014, at 11:13 AM, jahanian <fjahanian at apple.com> wrote:
> 
> Is this intentional, or a specific case for retain/release methods?

This also returns TRUE:

	blk b = ^{};
	BOOL res = [b respondsToSelector:@selector(isKindOfClass:)];

So blocks seem to respond to NSObject protocol selectors.

> In generally though it makes no sense
> to allow qualified id conversion of blocks pointers.

It would make sense for id<NSObject> if we would guarantee that blocks conform to NSObject protocol.

> - Fariborz
> 
> On May 30, 2014, at 11:06 AM, Argyrios Kyrtzidis <kyrtzidis at apple.com> wrote:
> 
>> I’m mainly asking if blocks are implicitly implementing the NSObject protocol or not, for example this seems to work:
>> 
>> typedef void(^blk)(void);
>> 
>> int main() {
>> 	blk b = ^{};
>> 	BOOL res = [b respondsToSelector:@selector(retain)];
>> 	printf("res: %d\n", res);
>> 	return 0;
>> }
>> 
>> 
>>> On May 30, 2014, at 11:03 AM, Jordan Rose <jordan_rose at apple.com> wrote:
>>> 
>>> I think I agree with Fariborz on this one. I don't remember us ever promising that blocks implement the NSObject protocol, just that they are valid Objective-C objects and that they implement -retain, -release, and -copy. The spec on the Clang site doesn't even promise -retain. (http://clang.llvm.org/docs/BlockLanguageSpec.html#objective-c-extensions)
>>> 
>>> The developer can always cast if they really need this.
>>> 
>>> Jordan
>>> 
>>> 
>>> On May 30, 2014, at 10:49 , jahanian <fjahanian at apple.com> wrote:
>>> 
>>>> It makes no sense to assign block to an object conforming to protocols.
>>>> Such objects must implement methods of those protocols which  blocks cannot.
>>>> I explicitly ruled this out. Did you see this in an actual user code? Curious to see how it is being used.
>>>> 
>>>> - Fariborz
>>>> 
>>>> On May 30, 2014, at 10:32 AM, Argyrios Kyrtzidis <kyrtzidis at apple.com> wrote:
>>>> 
>>>>> 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)')
>>>>> }
>>>>> 
>>>> 
>>>> _______________________________________________
>>>> 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