summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-12-31 08:26:35 +0000
committerDouglas Gregor <dgregor@apple.com>2009-12-31 08:26:35 +0000
commit532e68f1f32e4bcea69c9b1c558511ba010a8a2f (patch)
treeab297720a5801c9031087a029ebd094eef28c7e0
parentd5bace7092b94f8d872dd05fe59de33e1928e6de (diff)
downloadbcm5719-llvm-532e68f1f32e4bcea69c9b1c558511ba010a8a2f.tar.gz
bcm5719-llvm-532e68f1f32e4bcea69c9b1c558511ba010a8a2f.zip
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 llvm-svn: 92350
-rw-r--r--clang/lib/Sema/SemaCXXScopeSpec.cpp22
-rw-r--r--clang/test/FixIt/typo.cpp3
2 files changed, 24 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index 9467d8eb096..82d58eab1aa 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/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/clang/test/FixIt/typo.cpp b/clang/test/FixIt/typo.cpp
index a7cc0332fce..fb714263925 100644
--- a/clang/test/FixIt/typo.cpp
+++ b/clang/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) {
OpenPOWER on IntegriCloud