ObjC++ and MyObjCClass.class syntax

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 (540 Bytes)

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

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:

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

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

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

Thanks for the definite answer.

-- Jean-Daniel