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

Argyrios Kyrtzidis kyrtzidis at apple.com
Fri May 30 11:13:08 PDT 2014


Ok, WFM.

> On May 30, 2014, at 11:10 AM, Jordan Rose <jordan_rose at apple.com> wrote:
> 
> Our implementation currently does, but I don't think that's guaranteed, publicly documented (other than our libobjc being open-source), or something people should be relying on.
> 
> Jordan
> 
> 
> On May 30, 2014, at 11:06 , 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