diff options
author | Richard Trieu <rtrieu@google.com> | 2012-01-18 22:54:52 +0000 |
---|---|---|
committer | Richard Trieu <rtrieu@google.com> | 2012-01-18 22:54:52 +0000 |
commit | c64d3230d2f37014b9419e1555c9bca22c45634d (patch) | |
tree | 46e53e5fd0c83049cf3a7327dd2a0285d7916e56 /clang/lib/Parse/Parser.cpp | |
parent | 94298a906a2fcab80dee68f63e0657c9008dd27a (diff) | |
download | bcm5719-llvm-c64d3230d2f37014b9419e1555c9bca22c45634d.tar.gz bcm5719-llvm-c64d3230d2f37014b9419e1555c9bca22c45634d.zip |
Change the error when a '+=' follows a declaration to suggest a fixit to '=' instead of just suggesting a ';'.
Old error:
plusequaldeclare1.cc:3:8: error: expected ';' at end of declaration
int x += 6;
^
;
New error:
plusequaldeclare1.cc:3:9: error: invalid '+=' at end of declaration; did you
mean '='?
int x += 6;
^~
=
llvm-svn: 148433
Diffstat (limited to 'clang/lib/Parse/Parser.cpp')
-rw-r--r-- | clang/lib/Parse/Parser.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 501e50c1e79..6342b105680 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -1401,18 +1401,21 @@ bool Parser::TryAnnotateCXXScopeToken(bool EnteringContext) { return false; } -bool Parser::isTokenEqualOrMistypedEqualEqual(unsigned DiagID) { - if (Tok.is(tok::equalequal)) { - // We have '==' in a context that we would expect a '='. - // The user probably made a typo, intending to type '='. Emit diagnostic, - // fixit hint to turn '==' -> '=' and continue as if the user typed '='. - Diag(Tok, DiagID) - << FixItHint::CreateReplacement(SourceRange(Tok.getLocation()), - getTokenSimpleSpelling(tok::equal)); - return true; - } +bool Parser::CreateTokenReplacement(tok::TokenKind ExpectedToken, + tok::TokenKind FoundToken, + unsigned DiagID) { + if (Tok.isNot(FoundToken)) + return false; - return Tok.is(tok::equal); + // We have FoundToken in a context that we would expect an ExpectedToken. + // The user probably made a typo, intending to type ExpectedToken. + // Emit diagnostic, fixit hint to turn ReplaceToken -> ExpectedToken + // and continue as if the user typed ExpectedToken. + Tok.setKind(ExpectedToken); + Diag(Tok, DiagID) + << FixItHint::CreateReplacement(SourceRange(Tok.getLocation()), + getTokenSimpleSpelling(ExpectedToken)); + return true; } SourceLocation Parser::handleUnexpectedCodeCompletionToken() { |