r219732 - Be smarter when parsing variable declarations with unknown types.
Kaelyn Takata
rikka at google.com
Tue Oct 14 14:57:22 PDT 2014
Author: rikka
Date: Tue Oct 14 16:57:21 2014
New Revision: 219732
URL: http://llvm.org/viewvc/llvm-project?rev=219732&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp
Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=219732&r1=219731&r2=219732&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Tue Oct 14 16:57:21 2014
@@ -1131,7 +1131,10 @@ Parser::isCXXDeclarationSpecifier(Parser
// 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:
Modified: cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp?rev=219732&r1=219731&r2=219732&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp (original)
+++ cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp Tue Oct 14 16:57:21 2014
@@ -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'?}}
+}
+}
More information about the cfe-commits
mailing list