[cfe-commits] r150710 - in /cfe/trunk: lib/Parse/ParseExpr.cpp test/SemaObjCXX/properties.mm
Douglas Gregor
dgregor at apple.com
Thu Feb 16 10:19:22 PST 2012
Author: dgregor
Date: Thu Feb 16 12:19:22 2012
New Revision: 150710
URL: http://llvm.org/viewvc/llvm-project?rev=150710&view=rev
Log:
In Objective-C++, allow the keyword 'class' to be used as a property
name for dot syntax, e.g., NSObject.class or foo.class. For other
C++-keywords-as-method-names, use message send syntax. Fixes
<rdar://problem/10794452>.
Modified:
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/test/SemaObjCXX/properties.mm
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=150710&r1=150709&r2=150710&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Thu Feb 16 12:19:22 2012
@@ -726,7 +726,9 @@
(&II == Ident_super && getCurScope()->isInObjcMethodScope()))) {
ConsumeToken();
- if (Tok.isNot(tok::identifier)) {
+ // Allow either an identifier or the keyword 'class' (in C++).
+ if (Tok.isNot(tok::identifier) &&
+ !(getLang().CPlusPlus && Tok.is(tok::kw_class))) {
Diag(Tok, diag::err_expected_property_name);
return ExprError();
}
@@ -1406,11 +1408,23 @@
// FIXME: Add support for explicit call of template constructor.
SourceLocation TemplateKWLoc;
UnqualifiedId Name;
- if (ParseUnqualifiedId(SS,
- /*EnteringContext=*/false,
- /*AllowDestructorName=*/true,
- /*AllowConstructorName=*/ getLang().MicrosoftExt,
- ObjectType, TemplateKWLoc, Name))
+ if (getLang().ObjC2 && OpKind == tok::period && Tok.is(tok::kw_class)) {
+ // Objective-C++:
+ // After a '.' in a member access expression, treat the keyword
+ // 'class' as if it were an identifier.
+ //
+ // This hack allows property access to the 'class' method because it is
+ // such a common method name. For other C++ keywords that are
+ // Objective-C method names, one must use the message send syntax.
+ IdentifierInfo *Id = Tok.getIdentifierInfo();
+ SourceLocation Loc = ConsumeToken();
+ Name.setIdentifier(Id, Loc);
+ } else if (ParseUnqualifiedId(SS,
+ /*EnteringContext=*/false,
+ /*AllowDestructorName=*/true,
+ /*AllowConstructorName=*/
+ getLang().MicrosoftExt,
+ ObjectType, TemplateKWLoc, Name))
LHS = ExprError();
if (!LHS.isInvalid())
Modified: cfe/trunk/test/SemaObjCXX/properties.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/properties.mm?rev=150710&r1=150709&r2=150710&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/properties.mm (original)
+++ cfe/trunk/test/SemaObjCXX/properties.mm Thu Feb 16 12:19:22 2012
@@ -68,3 +68,20 @@
if (t5->count < 2) { }
}
+
+ at interface Test6
++ (Class)class;
+- (Class)class;
+ at end
+
+void test6(Test6 *t6) {
+ Class x = t6.class;
+ Class x2 = Test6.class;
+}
+
+template<typename T>
+void test6_template(T *t6) {
+ Class x = t6.class;
+}
+
+template void test6_template(Test6*);
More information about the cfe-commits
mailing list