[cfe-commits] r46366 - in /cfe/trunk: Parse/ParseInit.cpp test/Parser/objc-init.m
Chris Lattner
sabre at nondot.org
Fri Jan 25 11:37:24 PST 2008
Author: lattner
Date: Fri Jan 25 13:37:24 2008
New Revision: 46366
URL: http://llvm.org/viewvc/llvm-project?rev=46366&view=rev
Log:
First half of a fix for the "objc message send in initializer" bug. This only
handles message sends with typenames to start with.
Added:
cfe/trunk/test/Parser/objc-init.m
Modified:
cfe/trunk/Parse/ParseInit.cpp
Modified: cfe/trunk/Parse/ParseInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseInit.cpp?rev=46366&r1=46365&r2=46366&view=diff
==============================================================================
--- cfe/trunk/Parse/ParseInit.cpp (original)
+++ cfe/trunk/Parse/ParseInit.cpp Fri Jan 25 13:37:24 2008
@@ -86,9 +86,24 @@
case tok::l_square: {
// array-designator: '[' constant-expression ']'
// array-designator: '[' constant-expression '...' constant-expression ']'
+ // When designation is empty, this can be '[' objc-message-expr ']'. Note
+ // that we also have the case of [4][foo bar], which is the gnu designator
+ // extension + objc message send.
SourceLocation StartLoc = ConsumeBracket();
- ExprResult Idx = ParseConstantExpression();
+ // If Objective-C is enabled and this is a typename or other identifier
+ // receiver, parse this as a message send expression.
+ if (getLang().ObjC1 && isTokObjCMessageIdentifierReceiver()) {
+ IdentifierInfo *Name = Tok.getIdentifierInfo();
+ ConsumeToken();
+ ExprResult R = ParseObjCMessageExpressionBody(StartLoc, Name, 0);
+ return ParsePostfixExpressionSuffix(R);
+ }
+
+ // Note that we parse this as an assignment expression, not a constant
+ // expression (allowing *=, =, etc). Sema needs to validate that the
+ // expression is a constant.
+ ExprResult Idx = ParseAssignmentExpression();
if (Idx.isInvalid) {
SkipUntil(tok::r_square);
return Idx;
Added: cfe/trunk/test/Parser/objc-init.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-init.m?rev=46366&view=auto
==============================================================================
--- cfe/trunk/test/Parser/objc-init.m (added)
+++ cfe/trunk/test/Parser/objc-init.m Fri Jan 25 13:37:24 2008
@@ -0,0 +1,13 @@
+// RUN: clang -fsyntax-only -verify %s
+// rdar://5707001
+
+ at interface NSNumber;
+- () METH;
+
+ at end
+
+int main() {
+ id objects[] = {[NSNumber METH]};
+ return 0;
+}
+
More information about the cfe-commits
mailing list