Author: Nathan James
Date: 2020-03-18T22:14:40Z
New Revision: 1365ab4b63b7491697a3068777a9a7c6d68178c4

URL: 
https://github.com/llvm/llvm-project/commit/1365ab4b63b7491697a3068777a9a7c6d68178c4
DIFF: 
https://github.com/llvm/llvm-project/commit/1365ab4b63b7491697a3068777a9a7c6d68178c4.diff

LOG: [clang-tidy] RenamerClangTidy now correctly renames `using namespace` decls

Summary: Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=45039 | 
readability-identifier-naming doesn't rename using namespace correctly. ]]

Reviewers: aaron.ballman, gribozavr2, JonasToth, hokein, alexfh

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75220

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
    clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index c1145802aaa4..21d304e1a438 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -272,6 +272,11 @@ void RenamerClangTidyCheck::check(const 
MatchFinder::MatchResult &Result) {
   }
 
   if (const auto *Decl = Result.Nodes.getNodeAs<NamedDecl>("decl")) {
+    // Fix using namespace declarations.
+    if (const auto *UsingNS = dyn_cast<UsingDirectiveDecl>(Decl))
+      addUsage(NamingCheckFailures, UsingNS->getNominatedNamespaceAsWritten(),
+               UsingNS->getIdentLocation());
+
     if (!Decl->getIdentifier() || Decl->getName().empty() || 
Decl->isImplicit())
       return;
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp
index c9509434813c..908281391064 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp
@@ -527,3 +527,8 @@ void MyPoiterFunction(int * p_normal_pointer, int * const 
constant_ptr){
 // CHECK-FIXES: {{^}}    int * const lc_PointerB = nullptr;{{$}}
 }
 
+using namespace FOO_NS;
+// CHECK-FIXES: {{^}}using namespace foo_ns;
+
+using namespace FOO_NS::InlineNamespace;
+// CHECK-FIXES: {{^}}using namespace foo_ns::inline_namespace;


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to