From 2b312420aadfc3f0e0ff24bd95574ab9f81b7f24 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Mon, 2 Mar 2015 12:25:03 +0000 Subject: [PATCH] [clang-tidy] Refactor: Move misc clang-tidy checks to namespace clang::tidy::misc clang-tidy checks are organized into modules. This refactoring moves the misc module checks into the namespace clang::tidy::misc http://reviews.llvm.org/D7996 Patch by Richard Thomson! llvm-svn: 230950 --- clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.cpp | 2 ++ clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.h | 2 ++ clang-tools-extra/clang-tidy/misc/AssignOperatorSignatureCheck.cpp | 2 ++ clang-tools-extra/clang-tidy/misc/AssignOperatorSignatureCheck.h | 2 ++ clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.cpp | 2 ++ clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.h | 2 ++ clang-tools-extra/clang-tidy/misc/InaccurateEraseCheck.cpp | 2 ++ clang-tools-extra/clang-tidy/misc/InaccurateEraseCheck.h | 2 ++ clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp | 2 ++ clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.h | 2 ++ clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp | 5 ++++- clang-tools-extra/clang-tidy/misc/SwappedArgumentsCheck.cpp | 2 ++ clang-tools-extra/clang-tidy/misc/SwappedArgumentsCheck.h | 3 ++- clang-tools-extra/clang-tidy/misc/UndelegatedConstructor.cpp | 2 ++ clang-tools-extra/clang-tidy/misc/UndelegatedConstructor.h | 2 ++ clang-tools-extra/clang-tidy/misc/UniqueptrResetRelease.cpp | 2 ++ clang-tools-extra/clang-tidy/misc/UniqueptrResetRelease.h | 2 ++ clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp | 2 ++ clang-tools-extra/clang-tidy/misc/UnusedRAII.h | 2 ++ clang-tools-extra/clang-tidy/misc/UseOverride.cpp | 2 ++ clang-tools-extra/clang-tidy/misc/UseOverride.h | 3 ++- clang-tools-extra/unittests/clang-tidy/MiscModuleTest.cpp | 2 ++ 22 files changed, 46 insertions(+), 3 deletions(-) diff --git a/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.cpp b/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.cpp index 810d557..100998d 100644 --- a/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.cpp @@ -17,6 +17,7 @@ using namespace clang::ast_matchers; namespace clang { namespace tidy { +namespace misc { ArgumentCommentCheck::ArgumentCommentCheck(StringRef Name, ClangTidyContext *Context) @@ -181,5 +182,6 @@ void ArgumentCommentCheck::check(const MatchFinder::MatchResult &Result) { } } +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.h b/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.h index 131b56a..69c5b12 100644 --- a/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.h +++ b/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.h @@ -15,6 +15,7 @@ namespace clang { namespace tidy { +namespace misc { /// \brief Checks that argument comments match parameter names. class ArgumentCommentCheck : public ClangTidyCheck { @@ -36,6 +37,7 @@ private: llvm::ArrayRef Args); }; +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/AssignOperatorSignatureCheck.cpp b/clang-tools-extra/clang-tidy/misc/AssignOperatorSignatureCheck.cpp index 2625540..ad62c56 100644 --- a/clang-tools-extra/clang-tidy/misc/AssignOperatorSignatureCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/AssignOperatorSignatureCheck.cpp @@ -15,6 +15,7 @@ using namespace clang::ast_matchers; namespace clang { namespace tidy { +namespace misc { void AssignOperatorSignatureCheck::registerMatchers( ast_matchers::MatchFinder *Finder) { @@ -63,5 +64,6 @@ void AssignOperatorSignatureCheck::check( } } +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/AssignOperatorSignatureCheck.h b/clang-tools-extra/clang-tidy/misc/AssignOperatorSignatureCheck.h index e5e244a..a2dfb5b 100644 --- a/clang-tools-extra/clang-tidy/misc/AssignOperatorSignatureCheck.h +++ b/clang-tools-extra/clang-tidy/misc/AssignOperatorSignatureCheck.h @@ -14,6 +14,7 @@ namespace clang { namespace tidy { +namespace misc { /// \brief Finds declarations of assign operators with the wrong return and/or /// argument types. @@ -29,6 +30,7 @@ public: void check(const ast_matchers::MatchFinder::MatchResult &Result) override; }; +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.cpp b/clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.cpp index dcc98ae..b243ddb 100644 --- a/clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.cpp +++ b/clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.cpp @@ -22,6 +22,7 @@ AST_MATCHER(QualType, isBoolean) { return Node->isBooleanType(); } } // namespace ast_matchers namespace tidy { +namespace misc { void BoolPointerImplicitConversion::registerMatchers(MatchFinder *Finder) { // Look for ifs that have an implicit bool* to bool conversion in the @@ -71,5 +72,6 @@ BoolPointerImplicitConversion::check(const MatchFinder::MatchResult &Result) { << FixItHint::CreateInsertion(Var->getLocStart(), "*"); } +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.h b/clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.h index d6c6dfe..915ebc4 100644 --- a/clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.h +++ b/clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.h @@ -14,6 +14,7 @@ namespace clang { namespace tidy { +namespace misc { /// \brief Checks for conditions based on implicit conversion from a bool /// pointer to bool e.g. @@ -29,6 +30,7 @@ public: void check(const ast_matchers::MatchFinder::MatchResult &Result) override; }; +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/InaccurateEraseCheck.cpp b/clang-tools-extra/clang-tidy/misc/InaccurateEraseCheck.cpp index 80174ad..c172cd7 100644 --- a/clang-tools-extra/clang-tidy/misc/InaccurateEraseCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/InaccurateEraseCheck.cpp @@ -16,6 +16,7 @@ using namespace clang::ast_matchers; namespace clang { namespace tidy { +namespace misc { void InaccurateEraseCheck::registerMatchers(MatchFinder *Finder) { const auto CheckForEndCall = hasArgument( @@ -60,5 +61,6 @@ void InaccurateEraseCheck::check(const MatchFinder::MatchResult &Result) { << Hint; } +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/InaccurateEraseCheck.h b/clang-tools-extra/clang-tidy/misc/InaccurateEraseCheck.h index cde7320..89e5c93a 100644 --- a/clang-tools-extra/clang-tidy/misc/InaccurateEraseCheck.h +++ b/clang-tools-extra/clang-tidy/misc/InaccurateEraseCheck.h @@ -14,6 +14,7 @@ namespace clang { namespace tidy { +namespace misc { /// \brief Checks for inaccurate use of \c erase() method. /// @@ -30,6 +31,7 @@ public: void check(const ast_matchers::MatchFinder::MatchResult &Result) override; }; +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp b/clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp index 16401b7..8d58a81 100644 --- a/clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp @@ -16,6 +16,7 @@ using namespace clang::ast_matchers; namespace clang { namespace tidy { +namespace misc { static bool areTypesCompatible(QualType Left, QualType Right) { if (const auto *LeftRefType = Left->getAs()) @@ -123,5 +124,6 @@ void InefficientAlgorithmCheck::check(const MatchFinder::MatchResult &Result) { << Hint; } +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.h b/clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.h index f55297f..0148813 100644 --- a/clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.h +++ b/clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.h @@ -14,6 +14,7 @@ namespace clang { namespace tidy { +namespace misc { /// \brief Warns on inefficient use of STL algorithms on associative containers. /// @@ -28,6 +29,7 @@ public: void check(const ast_matchers::MatchFinder::MatchResult &Result) override; }; +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp index 9c9ff70..d5f3841 100644 --- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp @@ -25,6 +25,7 @@ namespace clang { namespace tidy { +namespace misc { class MiscModule : public ClangTidyModule { public: @@ -53,8 +54,10 @@ public: } }; +} // namespace misc + // Register the MiscTidyModule using this statically initialized variable. -static ClangTidyModuleRegistry::Add +static ClangTidyModuleRegistry::Add X("misc-module", "Adds miscellaneous lint checks."); // This anchor is used to force the linker to link in the generated object file diff --git a/clang-tools-extra/clang-tidy/misc/SwappedArgumentsCheck.cpp b/clang-tools-extra/clang-tidy/misc/SwappedArgumentsCheck.cpp index 18edd91..f6f52ed 100644 --- a/clang-tools-extra/clang-tidy/misc/SwappedArgumentsCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/SwappedArgumentsCheck.cpp @@ -16,6 +16,7 @@ using namespace clang::ast_matchers; namespace clang { namespace tidy { +namespace misc { void SwappedArgumentsCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher(callExpr().bind("call"), this); @@ -121,5 +122,6 @@ void SwappedArgumentsCheck::check(const MatchFinder::MatchResult &Result) { } } +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/SwappedArgumentsCheck.h b/clang-tools-extra/clang-tidy/misc/SwappedArgumentsCheck.h index 42293cd..78881af 100644 --- a/clang-tools-extra/clang-tidy/misc/SwappedArgumentsCheck.h +++ b/clang-tools-extra/clang-tidy/misc/SwappedArgumentsCheck.h @@ -14,6 +14,7 @@ namespace clang { namespace tidy { +namespace misc { /// \brief Finds potentially swapped arguments by looking at implicit /// conversions. @@ -25,8 +26,8 @@ public: void check(const ast_matchers::MatchFinder::MatchResult &Result) override; }; +} // namespace misc } // namespace tidy } // namespace clang #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_SWAPPED_ARGUMENTS_CHECK_H - diff --git a/clang-tools-extra/clang-tidy/misc/UndelegatedConstructor.cpp b/clang-tools-extra/clang-tidy/misc/UndelegatedConstructor.cpp index 143c27a..3fabbe6 100644 --- a/clang-tools-extra/clang-tidy/misc/UndelegatedConstructor.cpp +++ b/clang-tools-extra/clang-tidy/misc/UndelegatedConstructor.cpp @@ -46,6 +46,7 @@ AST_MATCHER_P(CXXRecordDecl, baseOfBoundNode, std::string, ID) { } // namespace ast_matchers namespace tidy { +namespace misc { void UndelegatedConstructorCheck::registerMatchers(MatchFinder *Finder) { // We look for calls to constructors of the same type in constructors. To do @@ -70,5 +71,6 @@ void UndelegatedConstructorCheck::check(const MatchFinder::MatchResult &Result) "A temporary object is created here instead"); } +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/UndelegatedConstructor.h b/clang-tools-extra/clang-tidy/misc/UndelegatedConstructor.h index 1afe355..150735d 100644 --- a/clang-tools-extra/clang-tidy/misc/UndelegatedConstructor.h +++ b/clang-tools-extra/clang-tidy/misc/UndelegatedConstructor.h @@ -14,6 +14,7 @@ namespace clang { namespace tidy { +namespace misc { /// \brief Finds creation of temporary objects in constructors that look like a /// function call to another constructor of the same class. The user most likely @@ -26,6 +27,7 @@ public: void check(const ast_matchers::MatchFinder::MatchResult &Result) override; }; +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/UniqueptrResetRelease.cpp b/clang-tools-extra/clang-tidy/misc/UniqueptrResetRelease.cpp index 0a648e2..e7782c1 100644 --- a/clang-tools-extra/clang-tidy/misc/UniqueptrResetRelease.cpp +++ b/clang-tools-extra/clang-tidy/misc/UniqueptrResetRelease.cpp @@ -15,6 +15,7 @@ using namespace clang::ast_matchers; namespace clang { namespace tidy { +namespace misc { void UniqueptrResetRelease::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( @@ -62,5 +63,6 @@ void UniqueptrResetRelease::check(const MatchFinder::MatchResult &Result) { CharSourceRange::getTokenRange(ResetCall->getSourceRange()), NewText); } +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/UniqueptrResetRelease.h b/clang-tools-extra/clang-tidy/misc/UniqueptrResetRelease.h index aacc6a1..df74159 100644 --- a/clang-tools-extra/clang-tidy/misc/UniqueptrResetRelease.h +++ b/clang-tools-extra/clang-tidy/misc/UniqueptrResetRelease.h @@ -14,6 +14,7 @@ namespace clang { namespace tidy { +namespace misc { /// \brief Find and replace unique_ptr::reset(release()) with std::move /// @@ -32,6 +33,7 @@ public: void check(const ast_matchers::MatchFinder::MatchResult &Result) override; }; +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp b/clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp index 41327b6..c993ab3 100644 --- a/clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp +++ b/clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp @@ -22,6 +22,7 @@ AST_MATCHER(CXXRecordDecl, hasUserDeclaredDestructor) { } // namespace ast_matchers namespace tidy { +namespace misc { void UnusedRAIICheck::registerMatchers(MatchFinder *Finder) { // Look for temporaries that are constructed in-place and immediately @@ -79,5 +80,6 @@ void UnusedRAIICheck::check(const MatchFinder::MatchResult &Result) { Replacement); } +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/UnusedRAII.h b/clang-tools-extra/clang-tidy/misc/UnusedRAII.h index 4d45c4a..04783cf 100644 --- a/clang-tools-extra/clang-tidy/misc/UnusedRAII.h +++ b/clang-tools-extra/clang-tidy/misc/UnusedRAII.h @@ -14,6 +14,7 @@ namespace clang { namespace tidy { +namespace misc { /// \brief Finds temporaries that look like RAII objects. /// @@ -43,6 +44,7 @@ public: void check(const ast_matchers::MatchFinder::MatchResult &Result) override; }; +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/UseOverride.cpp b/clang-tools-extra/clang-tidy/misc/UseOverride.cpp index 9c3b5b6..9e438a2 100644 --- a/clang-tools-extra/clang-tidy/misc/UseOverride.cpp +++ b/clang-tools-extra/clang-tidy/misc/UseOverride.cpp @@ -16,6 +16,7 @@ using namespace clang::ast_matchers; namespace clang { namespace tidy { +namespace misc { void UseOverride::registerMatchers(MatchFinder *Finder) { Finder->addMatcher(methodDecl(isOverride()).bind("method"), this); @@ -175,5 +176,6 @@ void UseOverride::check(const MatchFinder::MatchResult &Result) { } } +} // namespace misc } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/UseOverride.h b/clang-tools-extra/clang-tidy/misc/UseOverride.h index aab40b5..839c7fe 100644 --- a/clang-tools-extra/clang-tidy/misc/UseOverride.h +++ b/clang-tools-extra/clang-tidy/misc/UseOverride.h @@ -14,6 +14,7 @@ namespace clang { namespace tidy { +namespace misc { /// \brief Use C++11's 'override' and remove 'virtual' where applicable. class UseOverride : public ClangTidyCheck { @@ -24,8 +25,8 @@ public: void check(const ast_matchers::MatchFinder::MatchResult &Result) override; }; +} // namespace misc } // namespace tidy } // namespace clang #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_USE_OVERRIDE_H - diff --git a/clang-tools-extra/unittests/clang-tidy/MiscModuleTest.cpp b/clang-tools-extra/unittests/clang-tidy/MiscModuleTest.cpp index 2e1fbba..a42b2e5 100644 --- a/clang-tools-extra/unittests/clang-tidy/MiscModuleTest.cpp +++ b/clang-tools-extra/unittests/clang-tidy/MiscModuleTest.cpp @@ -6,6 +6,8 @@ namespace clang { namespace tidy { namespace test { +using misc::ArgumentCommentCheck; + TEST(ArgumentCommentCheckTest, CorrectComments) { EXPECT_NO_CHANGES(ArgumentCommentCheck, "void f(int x, int y); void g() { f(/*x=*/0, /*y=*/0); }"); -- 2.7.4