]> granicus.if.org Git - clang/commitdiff
Typo correction for namespace alias definitions
authorDouglas Gregor <dgregor@apple.com>
Tue, 29 Jun 2010 18:55:19 +0000 (18:55 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 29 Jun 2010 18:55:19 +0000 (18:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107191 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 66d0bf5bd410303532cf38dd52626ae17a49e5f2..bf75773f6d0ca92646daa6fb298f29d00f86fb0a 100644 (file)
@@ -4223,8 +4223,30 @@ Sema::DeclPtrTy Sema::ActOnNamespaceAliasDef(Scope *S,
     return DeclPtrTy();
 
   if (R.empty()) {
-    Diag(NamespaceLoc, diag::err_expected_namespace_name) << SS.getRange();
-    return DeclPtrTy();
+    if (DeclarationName Corrected = CorrectTypo(R, S, &SS, 0, false, 
+                                                CTC_NoKeywords, 0)) {
+      if (R.getAsSingle<NamespaceDecl>() || 
+          R.getAsSingle<NamespaceAliasDecl>()) {
+        if (DeclContext *DC = computeDeclContext(SS, false))
+          Diag(IdentLoc, diag::err_using_directive_member_suggest)
+            << Ident << DC << Corrected << SS.getRange()
+            << FixItHint::CreateReplacement(IdentLoc, Corrected.getAsString());        
+        else
+          Diag(IdentLoc, diag::err_using_directive_suggest)
+            << Ident << Corrected
+            << FixItHint::CreateReplacement(IdentLoc, Corrected.getAsString());
+        
+        Diag(R.getFoundDecl()->getLocation(), diag::note_namespace_defined_here)
+          << Corrected;
+        
+        Ident = Corrected.getAsIdentifierInfo();
+      }
+    }
+    
+    if (R.empty()) {
+      Diag(NamespaceLoc, diag::err_expected_namespace_name) << SS.getRange();
+      return DeclPtrTy();
+    }
   }
 
   NamespaceAliasDecl *AliasDecl =
index 9789a5807a6926e59777d17b2ec827b1677a796b..9393ce13da0c4fa9af01bc454751eee075cc72e2 100644 (file)
@@ -13,7 +13,7 @@ namespace std {
 }
 
 namespace otherstd { // expected-note 2{{'otherstd' declared here}} \
-                     // expected-note{{namespace 'otherstd' defined here}}
+                     // expected-note 2{{namespace 'otherstd' defined here}}
   using namespace std;
 }
 
@@ -31,9 +31,12 @@ float area(float radius, // expected-note{{'radius' declared here}}
 }
 
 using namespace othestd; // expected-error{{no namespace named 'othestd'; did you mean 'otherstd'?}}
-namespace blargh = otherstd; // expected-note{{namespace 'blargh' defined here}}
+namespace blargh = otherstd; // expected-note 2{{namespace 'blargh' defined here}}
 using namespace ::blarg; // expected-error{{no namespace named 'blarg' in the global namespace; did you mean 'blargh'?}}
 
+namespace wibble = blarg; // expected-error{{no namespace named 'blarg'; did you mean 'blargh'?}}
+namespace wobble = ::blarg; // expected-error{{no namespace named 'blarg' in the global namespace; did you mean 'blargh'?}}
+
 bool test_string(std::string s) {
   basc_string<char> b1; // expected-error{{no template named 'basc_string'; did you mean 'basic_string'?}}
   std::basic_sting<char> b2; // expected-error{{no template named 'basic_sting' in namespace 'std'; did you mean 'basic_string'?}}