From: Kaelyn Takata Date: Tue, 14 Oct 2014 21:57:21 +0000 (+0000) Subject: Be smarter when parsing variable declarations with unknown types. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a3bafcad4b524f98ddb1ec2306b3fd856143343;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219732 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseTentative.cpp b/lib/Parse/ParseTentative.cpp index 1020eefb0c..4060fab658 100644 --- a/lib/Parse/ParseTentative.cpp +++ b/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/test/SemaCXX/typo-correction-pt2.cpp b/test/SemaCXX/typo-correction-pt2.cpp index 298ea175a6..d300764e64 100644 --- a/test/SemaCXX/typo-correction-pt2.cpp +++ b/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'?}} +} +}