From 2f448467e4254ddc3191136c968e6054bc009b88 Mon Sep 17 00:00:00 2001 From: Kaelyn Takata Date: Tue, 14 Oct 2014 21:57:21 +0000 Subject: [PATCH] Be smarter when parsing variable declarations with unknown types. 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. llvm-svn: 219732 --- clang/lib/Parse/ParseTentative.cpp | 5 ++++- clang/test/SemaCXX/typo-correction-pt2.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp index 1020eef..4060fab 100644 --- a/clang/lib/Parse/ParseTentative.cpp +++ b/clang/lib/Parse/ParseTentative.cpp @@ -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: diff --git a/clang/test/SemaCXX/typo-correction-pt2.cpp b/clang/test/SemaCXX/typo-correction-pt2.cpp index 298ea17..d300764 100644 --- a/clang/test/SemaCXX/typo-correction-pt2.cpp +++ b/clang/test/SemaCXX/typo-correction-pt2.cpp @@ -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'?}} +} +} -- 2.7.4