diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-02-17 16:41:16 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-02-17 16:41:16 +0000 |
commit | d267b3f03a3b35ca218dc2b0995ccff35092cf33 (patch) | |
tree | 8c3088c71296c843ac7b4391a4fdd28cf0a724da /lib/Parse/ParseInit.cpp | |
parent | 1f27805fe4f5463fd5b4d5396affe1ef23320688 (diff) | |
download | clang-d267b3f03a3b35ca218dc2b0995ccff35092cf33.tar.gz |
De-nest tentative parsing to disambiguate lambdas from designators; no
functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150817 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseInit.cpp')
-rw-r--r-- | lib/Parse/ParseInit.cpp | 87 |
1 files changed, 45 insertions, 42 deletions
diff --git a/lib/Parse/ParseInit.cpp b/lib/Parse/ParseInit.cpp index 45f1825f7e..d5e06f7fd8 100644 --- a/lib/Parse/ParseInit.cpp +++ b/lib/Parse/ParseInit.cpp @@ -58,52 +58,55 @@ bool Parser::MayBeDesignationStart() { return true; } - // Parse up to (at most) the token after the closing ']' to determine - // whether this is a C99 designator or a lambda. - TentativeParsingAction Tentative(*this); - ConsumeBracket(); - while (true) { - switch (Tok.getKind()) { - case tok::equal: - case tok::amp: - case tok::identifier: - case tok::kw_this: - // These tokens can occur in a capture list or a constant-expression. - // Keep looking. - ConsumeToken(); - continue; - - case tok::comma: - // Since a comma cannot occur in a constant-expression, this must - // be a lambda. - Tentative.Revert(); - return false; - - case tok::r_square: { - // Once we hit the closing square bracket, we look at the next - // token. If it's an '=', this is a designator. Otherwise, it's a - // lambda expression. This decision favors lambdas over the older - // GNU designator syntax, which allows one to omit the '=', but is - // consistent with GCC. - ConsumeBracket(); - tok::TokenKind Kind = Tok.getKind(); - Tentative.Revert(); - return Kind == tok::equal; - } - - default: - // Anything else cannot occur in a lambda capture list, so it - // must be a designator. - Tentative.Revert(); - return true; - } - } - - return true; + // Handle the complicated case below. + break; } case tok::identifier: // designation: identifier ':' return PP.LookAhead(0).is(tok::colon); } + + // Parse up to (at most) the token after the closing ']' to determine + // whether this is a C99 designator or a lambda. + TentativeParsingAction Tentative(*this); + ConsumeBracket(); + while (true) { + switch (Tok.getKind()) { + case tok::equal: + case tok::amp: + case tok::identifier: + case tok::kw_this: + // These tokens can occur in a capture list or a constant-expression. + // Keep looking. + ConsumeToken(); + continue; + + case tok::comma: + // Since a comma cannot occur in a constant-expression, this must + // be a lambda. + Tentative.Revert(); + return false; + + case tok::r_square: { + // Once we hit the closing square bracket, we look at the next + // token. If it's an '=', this is a designator. Otherwise, it's a + // lambda expression. This decision favors lambdas over the older + // GNU designator syntax, which allows one to omit the '=', but is + // consistent with GCC. + ConsumeBracket(); + tok::TokenKind Kind = Tok.getKind(); + Tentative.Revert(); + return Kind == tok::equal; + } + + default: + // Anything else cannot occur in a lambda capture list, so it + // must be a designator. + Tentative.Revert(); + return true; + } + } + + return true; } static void CheckArrayDesignatorSyntax(Parser &P, SourceLocation Loc, |