From: Douglas Gregor Date: Tue, 29 Jun 2010 18:55:19 +0000 (+0000) Subject: Typo correction for namespace alias definitions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e8c4b9fac447c6c9849e3ef8beb1ef273ac0f97;p=clang Typo correction for namespace alias definitions git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107191 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 66d0bf5bd4..bf75773f6d 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -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() || + R.getAsSingle()) { + 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 = diff --git a/test/FixIt/typo.cpp b/test/FixIt/typo.cpp index 9789a5807a..9393ce13da 100644 --- a/test/FixIt/typo.cpp +++ b/test/FixIt/typo.cpp @@ -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 b1; // expected-error{{no template named 'basc_string'; did you mean 'basic_string'?}} std::basic_sting b2; // expected-error{{no template named 'basic_sting' in namespace 'std'; did you mean 'basic_string'?}}