]> granicus.if.org Git - clang/commitdiff
In Sema::ClassifyName, try to avoid nonsensical corrections to
authorKaelyn Uhrain <rikka@google.com>
Fri, 29 Jun 2012 21:30:39 +0000 (21:30 +0000)
committerKaelyn Uhrain <rikka@google.com>
Fri, 29 Jun 2012 21:30:39 +0000 (21:30 +0000)
keywords when doing type correction.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159464 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/typo-correction.cpp

index 40ec1baddba5aa9a8a03563a4679b28a510dad39..d63922ba326a83c9733c4bde3aee2b0aee30542c 100644 (file)
@@ -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)) {
index 77fca744406bb41a445086681acdec6b1e6f42e0..893f08a422ca56523a31e0c359cb19728ae2ab09 100644 (file)
@@ -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'$}}
+ }
+}