diff options
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 13 | ||||
-rw-r--r-- | test/SemaCXX/typo-correction.cpp | 7 |
2 files changed, 20 insertions, 0 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 40ec1baddb..d63922ba32 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -634,6 +634,19 @@ Corrected: if (!SecondTry) { SecondTry = true; CorrectionCandidateCallback DefaultValidator; + // Try to limit which sets of keywords should be included in typo + // correction based on what the next token is. + DefaultValidator.WantTypeSpecifiers = + NextToken.is(tok::l_paren) || NextToken.is(tok::less) || + NextToken.is(tok::identifier) || NextToken.is(tok::star) || + NextToken.is(tok::amp) || NextToken.is(tok::l_square); + DefaultValidator.WantExpressionKeywords = + NextToken.is(tok::l_paren) || NextToken.is(tok::identifier) || + NextToken.is(tok::arrow) || NextToken.is(tok::period); + DefaultValidator.WantRemainingKeywords = + NextToken.is(tok::l_paren) || NextToken.is(tok::semi) || + NextToken.is(tok::identifier) || NextToken.is(tok::l_brace); + DefaultValidator.WantCXXNamedCasts = false; if (TypoCorrection Corrected = CorrectTypo(Result.getLookupNameInfo(), Result.getLookupKind(), S, &SS, DefaultValidator)) { diff --git a/test/SemaCXX/typo-correction.cpp b/test/SemaCXX/typo-correction.cpp index 77fca74440..893f08a422 100644 --- a/test/SemaCXX/typo-correction.cpp +++ b/test/SemaCXX/typo-correction.cpp @@ -227,3 +227,10 @@ class foo { }; // expected-note{{'foo' declared here}} // 'boo' to 'bool' is the same edit distance as correcting 'boo' to 'foo'. class bar : boo { }; // expected-error{{unknown class name 'boo'; did you mean 'foo'?}} } + +namespace bogus_keyword_suggestion { +void test() { + status = "OK"; // expected-error-re{{use of undeclared identifier 'status'$}} + return status; // expected-error-re{{use of undeclared identifier 'status'$}} + } +} |