]> granicus.if.org Git - clang/commitdiff
Be smarter when parsing variable declarations with unknown types.
authorKaelyn Takata <rikka@google.com>
Tue, 14 Oct 2014 21:57:21 +0000 (21:57 +0000)
committerKaelyn Takata <rikka@google.com>
Tue, 14 Oct 2014 21:57:21 +0000 (21:57 +0000)
Specifically, avoid typo-correcting the variable name into a type before
typo-correcting the actual type name in the declaration. Doing so
results in a very unpleasant cascade of errors, with the typo correction
of the actual type name being buried in the middle.

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

lib/Parse/ParseTentative.cpp
test/SemaCXX/typo-correction-pt2.cpp

index 1020eefb0c4ffd53e26d44dcbccaf8626c206531..4060fab658ae874d4ccd7cbc03a2c7bbea9c5c39 100644 (file)
@@ -1131,7 +1131,10 @@ Parser::isCXXDeclarationSpecifier(Parser::TPResult BracedCastResult,
       // to types and identifiers, in order to try to recover from errors.
       CorrectionCandidateCallback TypoCorrection;
       TypoCorrection.WantRemainingKeywords = false;
-      TypoCorrection.WantTypeSpecifiers = Next.isNot(tok::arrow);
+      TypoCorrection.WantTypeSpecifiers =
+          Next.is(tok::l_paren) || Next.is(tok::r_paren) ||
+          Next.is(tok::greater) || Next.is(tok::l_brace) ||
+          Next.is(tok::identifier);
       switch (TryAnnotateName(false /* no nested name specifier */,
                               &TypoCorrection)) {
       case ANK_Error:
index 298ea175a6f3b238e81174a92a1572db315bf368..d300764e645973fe9758a05a9c3dac356d0cc218 100644 (file)
@@ -309,3 +309,13 @@ namespace testWantFunctionLikeCasts {
       return lon(8.0);  // expected-error {{use of undeclared identifier 'lon'; did you mean 'long'?}}
   }
 }
+
+namespace testCXXDeclarationSpecifierParsing {
+namespace test {
+  struct SomeSettings {};  // expected-note {{'test::SomeSettings' declared here}}
+}
+class Test {};
+int bar() {
+  Test::SomeSettings some_settings; // expected-error {{no type named 'SomeSettings' in 'testCXXDeclarationSpecifierParsing::Test'; did you mean 'test::SomeSettings'?}}
+}
+}