diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-12-31 08:26:35 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-12-31 08:26:35 +0000 |
commit | 175a65686eba7c7a9cb02412136fddd2d2c56dd7 (patch) | |
tree | 7835acebafb2f309fa8814f82eb5c6e1a60a4dcc | |
parent | bfea239cafdb13256982eb891b151c5c07c1e7a9 (diff) |
Typo correction for identifiers within nested name specifiers, e.g.,
typo.cpp:18:1: error: use of undeclared identifier 'other_std'; did
you mean 'otherstd'?
other_std::strng str1;
^~~~~~~~~
otherstd
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92350 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaCXXScopeSpec.cpp | 22 | ||||
-rw-r--r-- | test/FixIt/typo.cpp | 3 |
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/Sema/SemaCXXScopeSpec.cpp b/lib/Sema/SemaCXXScopeSpec.cpp index 9467d8eb09..82d58eab1a 100644 --- a/lib/Sema/SemaCXXScopeSpec.cpp +++ b/lib/Sema/SemaCXXScopeSpec.cpp @@ -428,6 +428,28 @@ Sema::CXXScopeTy *Sema::BuildCXXNestedNameSpecifier(Scope *S, } // FIXME: Deal with ambiguities cleanly. + + if (Found.empty() && !ErrorRecoveryLookup) { + // We haven't found anything, and we're not recovering from a + // different kind of error, so look for typos. + DeclarationName Name = Found.getLookupName(); + if (CorrectTypo(Found, S, &SS, LookupCtx, EnteringContext) && + Found.isSingleResult() && + isAcceptableNestedNameSpecifier(Found.getAsSingle<NamedDecl>())) { + if (LookupCtx) + Diag(Found.getNameLoc(), diag::err_no_member_suggest) + << Name << LookupCtx << Found.getLookupName() << SS.getRange() + << CodeModificationHint::CreateReplacement(Found.getNameLoc(), + Found.getLookupName().getAsString()); + else + Diag(Found.getNameLoc(), diag::err_undeclared_var_use_suggest) + << Name << Found.getLookupName() + << CodeModificationHint::CreateReplacement(Found.getNameLoc(), + Found.getLookupName().getAsString()); + } else + Found.clear(); + } + NamedDecl *SD = Found.getAsSingle<NamedDecl>(); if (isAcceptableNestedNameSpecifier(SD)) { if (!ObjectType.isNull() && !ObjectTypeSearchedInScope) { diff --git a/test/FixIt/typo.cpp b/test/FixIt/typo.cpp index a7cc0332fc..fb71426392 100644 --- a/test/FixIt/typo.cpp +++ b/test/FixIt/typo.cpp @@ -15,7 +15,8 @@ namespace otherstd { using namespace std; -otherstd::strng str1; // expected-error{{no type named 'strng' in namespace 'otherstd'; did you mean 'string'?}} +other_std::strng str1; // expected-error{{use of undeclared identifier 'other_std'; did you mean 'otherstd'?}} \ +// expected-error{{no type named 'strng' in namespace 'otherstd'; did you mean 'string'?}} tring str2; // expected-error{{unknown type name 'tring'; did you mean 'string'?}} float area(float radius, float pi) { |