summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/ParseTentative.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard@metafoo.co.uk>2019-11-27 17:54:26 -0800
committerRichard Smith <richard@metafoo.co.uk>2019-11-27 17:54:26 -0800
commit789a7aa37d0cca70d6e48908ce3e8bb4e761e266 (patch)
treece69461aa918ae14ad6e7287e6b797c06b34b860 /clang/lib/Parse/ParseTentative.cpp
parentacc79aa0e747b9777077e0a337e99540a52b94b2 (diff)
downloadbcm5719-llvm-789a7aa37d0cca70d6e48908ce3e8bb4e761e266.tar.gz
bcm5719-llvm-789a7aa37d0cca70d6e48908ce3e8bb4e761e266.zip
Properly disambiguate between array declarators and array subscript expressions.
Diffstat (limited to 'clang/lib/Parse/ParseTentative.cpp')
-rw-r--r--clang/lib/Parse/ParseTentative.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp
index e2e16ca63d1..9cc41328c46 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -2066,9 +2066,21 @@ Parser::TPResult Parser::TryParseFunctionDeclarator() {
///
Parser::TPResult Parser::TryParseBracketDeclarator() {
ConsumeBracket();
- if (!SkipUntil(tok::r_square, StopAtSemi))
+
+ // A constant-expression cannot begin with a '{', but the
+ // expr-or-braced-init-list of a postfix-expression can.
+ if (Tok.is(tok::l_brace))
+ return TPResult::False;
+
+ if (!SkipUntil(tok::r_square, tok::comma, StopAtSemi | StopBeforeMatch))
return TPResult::Error;
+ // If we hit a comma before the ']', this is not a constant-expression,
+ // but might still be the expr-or-braced-init-list of a postfix-expression.
+ if (Tok.isNot(tok::r_square))
+ return TPResult::False;
+
+ ConsumeBracket();
return TPResult::Ambiguous;
}
OpenPOWER on IntegriCloud