summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-01-25 19:37:24 +0000
committerChris Lattner <sabre@nondot.org>2008-01-25 19:37:24 +0000
commit8917c5ace284ede412fcac8357aa3fca4e191701 (patch)
tree59ff41941982fd38e768b39d57a771854d876c02
parente10c6da41e11a0e7b181165d7060de9b5a76f921 (diff)
downloadbcm5719-llvm-8917c5ace284ede412fcac8357aa3fca4e191701.tar.gz
bcm5719-llvm-8917c5ace284ede412fcac8357aa3fca4e191701.zip
First half of a fix for the "objc message send in initializer" bug. This only
handles message sends with typenames to start with. llvm-svn: 46366
-rw-r--r--clang/Parse/ParseInit.cpp17
-rw-r--r--clang/test/Parser/objc-init.m13
2 files changed, 29 insertions, 1 deletions
diff --git a/clang/Parse/ParseInit.cpp b/clang/Parse/ParseInit.cpp
index cf8293e0096..9c5b6d8921b 100644
--- a/clang/Parse/ParseInit.cpp
+++ b/clang/Parse/ParseInit.cpp
@@ -86,9 +86,24 @@ Parser::ExprResult Parser::ParseInitializerWithPotentialDesignator() {
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;
diff --git a/clang/test/Parser/objc-init.m b/clang/test/Parser/objc-init.m
new file mode 100644
index 00000000000..43e6c2e26ec
--- /dev/null
+++ b/clang/test/Parser/objc-init.m
@@ -0,0 +1,13 @@
+// RUN: clang -fsyntax-only -verify %s
+// rdar://5707001
+
+@interface NSNumber;
+- () METH;
+
+@end
+
+int main() {
+ id objects[] = {[NSNumber METH]};
+ return 0;
+}
+
OpenPOWER on IntegriCloud