[cfe-dev] ObjC++ and MyObjCClass.class syntax

Blaine Garst blaine at apple.com
Wed Aug 11 11:38:20 PDT 2010


Since 'class' is a defined instance method, and [o class] is supported, o.class should be supported.  Dot syntax should work for all non-void returning no-argument methods.

Blaine

On Aug 11, 2010, at 11:26 AM, Fariborz Jahanian wrote:

> 
> On Aug 11, 2010, at 11:11 AM, Jean-Daniel Dupas wrote:
> 
>> You can't use class as a property name or as an ivar name in objc++
>> 
>> This extension is just to be able to write for example:
>> 
>> [obj isKindOfClass:NSString.class]
>> 
>> instead of
>> 
>> [obj isKindOfClass:[NSString class]]
>> 
>> 
>> As the +(Class)class method is defined on NSObject, this syntax may  
>> virtually be used by any ObjC class.
>> 
>> I know this syntax is "abusing" the new property syntax as it uses  
>> it to call a standard accessor method (not defined as a property),  
>> but this kind of "abuse" is supported for all other accessors name  
>> and g++ support it for 'class', so it may be worth supporting it too.
>> 
>> Here is a test case accepted by g++ but rejected by clang:
>> ---------------------------------
>> @interface I {
>> int cls;
>> }
>> 
>> + (int)class;
>> 
>> @end
>> 
>> @implementation  I
>> - (int) Meth { return I.class; }
>> @end
> 
> I see. Yet g++ rejects a similar case when 'class' is instance method,  
> or any other use of 'class' in an objective-c context.
>  g++'s behavior is probably an accident of implementation. I am not  
> sure if we need to follow this particular g++ behavior.
> 
> - Fariborz
> 
>> 
>> ---------------------------------
>> 
>> Le 11 août 2010 à 19:57, Fariborz Jahanian a écrit :
>> 
>>> Can you provide a test case. I see that in this case 'class' is  
>>> supported as property name in objective-c mode (but not objective-c+ 
>>> +).
>>> g++ ObjC++  does not support it either.
>>> 
>>> @interface I
>>> {
>>> int class;
>>> }
>>> @property int class;
>>> @end
>>> 
>>> @implementation  I
>>> - (int) Meth { I* Foo; return Foo.class; }
>>> @end
>>> 
>>> 
>>> % gcc -ObjC++ t.m
>>> t.m:3: error: expected identifier before ';' token
>>> t.m:5: error: expected identifier before ';' token
>>> t.m: In function 'int -[I Meth](I*, objc_selector*)':
>>> t.m:9: error: expected unqualified-id before 'class'
>>> t.m:9: error: expected ';' before 'class'
>>> - Fariborz
>>> 
>>> 
>>> On Aug 11, 2010, at 9:40 AM, Jean-Daniel Dupas wrote:
>>> 
>>>> Hello,
>>>> 
>>>> I would like to know if it is acceptable to add a special case in  
>>>> the parser to support the Foo.class syntax in ObjC++ (where Foo is  
>>>> an ObjC class).
>>>> This syntax already works in classic ObjC, and is supported by GCC  
>>>> in both ObjC and ObjC++. But actually, clang does not support it.
>>>> 
>>>> Thanks
>>>> <Class.class.patch>
>>>> 
>>>> 
>>>> -- Jean-Daniel
>>>> 
>>>> 
>>>> 
>>>> 
>>>> _______________________________________________
>>>> cfe-dev mailing list
>>>> cfe-dev at cs.uiuc.edu
>>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>> 
>> 
>> -- Jean-Daniel
>> 
>> 
>> 
>> 
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev





More information about the cfe-dev mailing list