]> granicus.if.org Git - clang/commitdiff
Typo correction for identifiers within nested name specifiers, e.g.,
authorDouglas Gregor <dgregor@apple.com>
Thu, 31 Dec 2009 08:26:35 +0000 (08:26 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 31 Dec 2009 08:26:35 +0000 (08:26 +0000)
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

lib/Sema/SemaCXXScopeSpec.cpp
test/FixIt/typo.cpp

index 9467d8eb0968e359a95e7065ca591daee14914a9..82d58eab1aad8d4d9b8ad6af1415ecd302a922f5 100644 (file)
@@ -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) {
index a7cc0332fcec5f2a06df586653f213fbae94ee10..fb714263925f5cae4700ac59f3866bd2902ab729 100644 (file)
@@ -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) {