[cfe-dev] ObjC++ and MyObjCClass.class syntax
Douglas Gregor
dgregor at apple.com
Wed Aug 11 11:38:26 PDT 2010
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
> ---------------------------------
We decided not to support this idiom in Clang++. It's too horrible for words, and [NSString class] is a suitable formulation that will work.
- Doug
More information about the cfe-dev
mailing list