summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/ParseExprCXX.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-12-17 01:39:22 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-12-17 01:39:22 +0000
commit6ca445e0dd370ad564a12e5053241c82deaedf10 (patch)
treeeb0084907f0a2954897566826d7d6d51b3550d3e /clang/lib/Parse/ParseExprCXX.cpp
parentfc2201e922261d1c21bfe68fb205de6a13b1f18e (diff)
downloadbcm5719-llvm-6ca445e0dd370ad564a12e5053241c82deaedf10.tar.gz
bcm5719-llvm-6ca445e0dd370ad564a12e5053241c82deaedf10.zip
Parse: Consume tokens more carefully in CheckForLParenAfterColonColon
We would consume the lparen even if it wasn't followed by an identifier or a star-identifier pair. This fixes PR21815. llvm-svn: 224403
Diffstat (limited to 'clang/lib/Parse/ParseExprCXX.cpp')
-rw-r--r--clang/lib/Parse/ParseExprCXX.cpp56
1 files changed, 29 insertions, 27 deletions
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 613246ef712..dad1f0da2ef 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -108,35 +108,37 @@ void Parser::CheckForLParenAfterColonColon() {
if (!Tok.is(tok::l_paren))
return;
- SourceLocation l_parenLoc = ConsumeParen(), r_parenLoc;
- Token Tok1 = getCurToken();
- if (!Tok1.is(tok::identifier) && !Tok1.is(tok::star))
+ Token LParen = Tok;
+ Token NextTok = GetLookAheadToken(1);
+ Token StarTok = NextTok;
+ // Check for (identifier or (*identifier
+ Token IdentifierTok = StarTok.is(tok::star) ? GetLookAheadToken(2) : StarTok;
+ if (IdentifierTok.isNot(tok::identifier))
return;
-
- if (Tok1.is(tok::identifier)) {
- Token Tok2 = GetLookAheadToken(1);
- if (Tok2.is(tok::r_paren)) {
+ // Eat the '('.
+ ConsumeParen();
+ Token RParen;
+ // Do we have a ')' ?
+ NextTok = StarTok.is(tok::star) ? GetLookAheadToken(2) : GetLookAheadToken(1);
+ if (NextTok.is(tok::r_paren)) {
+ RParen = NextTok;
+ // Eat the '*' if it is present.
+ if (StarTok.is(tok::star))
ConsumeToken();
- PP.EnterToken(Tok1);
- r_parenLoc = ConsumeParen();
- }
- } else if (Tok1.is(tok::star)) {
- Token Tok2 = GetLookAheadToken(1);
- if (Tok2.is(tok::identifier)) {
- Token Tok3 = GetLookAheadToken(2);
- if (Tok3.is(tok::r_paren)) {
- ConsumeToken();
- ConsumeToken();
- PP.EnterToken(Tok2);
- PP.EnterToken(Tok1);
- r_parenLoc = ConsumeParen();
- }
- }
- }
-
- Diag(l_parenLoc, diag::err_paren_after_colon_colon)
- << FixItHint::CreateRemoval(l_parenLoc)
- << FixItHint::CreateRemoval(r_parenLoc);
+ // Eat the identifier.
+ ConsumeToken();
+ // Add the identifier token back.
+ PP.EnterToken(IdentifierTok);
+ // Add the '*' back if it was present.
+ if (StarTok.is(tok::star))
+ PP.EnterToken(StarTok);
+ // Eat the ')'.
+ ConsumeParen();
+ }
+
+ Diag(LParen.getLocation(), diag::err_paren_after_colon_colon)
+ << FixItHint::CreateRemoval(LParen.getLocation())
+ << FixItHint::CreateRemoval(RParen.getLocation());
}
/// \brief Parse global scope or nested-name-specifier if present.
OpenPOWER on IntegriCloud