diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-10-08 02:39:23 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-10-08 02:39:23 +0000 |
commit | a6eb5f81d13bacac01faff70a947047725b4413f (patch) | |
tree | bcaa31849ec52affed208d74b4a6cd821785fb06 /lib/Parse/Parser.cpp | |
parent | b4eb64d8426c0eaa58d398961e0e74ff85063d7c (diff) |
When we encounter a '==' in a context expecting a '=', assume the user made a typo:
t.c:1:7: error: invalid '==' at end of declaration; did you mean '='?
int x == 0;
^~
=
Implements rdar://8488464.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116035 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/Parser.cpp')
-rw-r--r-- | lib/Parse/Parser.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 33c7b7dcb4..8084088afc 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -1156,6 +1156,20 @@ 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; + } + + return Tok.is(tok::equal); +} + void Parser::CodeCompletionRecovery() { for (Scope *S = getCurScope(); S; S = S->getParent()) { if (S->getFlags() & Scope::FnScope) { |