diff --git a/clang-tools-extra/clang-tidy/boost/UseToStringCheck.cpp b/clang-tools-extra/clang-tidy/boost/UseToStringCheck.cpp index 8ca3656ea623..1775440d52cf 100644 --- a/clang-tools-extra/clang-tidy/boost/UseToStringCheck.cpp +++ b/clang-tools-extra/clang-tidy/boost/UseToStringCheck.cpp @@ -15,10 +15,12 @@ namespace clang { namespace tidy { namespace boost { +namespace { AST_MATCHER(Type, isStrictlyInteger) { return Node.isIntegerType() && !Node.isAnyCharacterType() && !Node.isBooleanType(); } +} // namespace void UseToStringCheck::registerMatchers(MatchFinder *Finder) { if (!getLangOpts().CPlusPlus) diff --git a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp index 5607ce6a4873..420428fc3832 100644 --- a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp @@ -18,9 +18,11 @@ namespace clang { namespace tidy { namespace bugprone { +namespace { AST_MATCHER_P(IntegerLiteral, isBiggerThan, unsigned, N) { return Node.getValue().getZExtValue() > N; } +} // namespace StringConstructorCheck::StringConstructorCheck(StringRef Name, ClangTidyContext *Context) diff --git a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp index 6b3f49879af7..bb9c9b65c9c1 100644 --- a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp @@ -19,11 +19,13 @@ namespace clang { namespace tidy { namespace bugprone { +namespace { AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); } AST_MATCHER(CXXMethodDecl, isOverloadedOperator) { return Node.isOverloadedOperator(); } +} // namespace /// Finds out if the given method overrides some method. static bool isOverrideMethod(const CXXMethodDecl *MD) { diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp index 923555b90d84..3e800cd59e1a 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp @@ -17,9 +17,11 @@ namespace clang { namespace tidy { namespace cppcoreguidelines { +namespace { AST_MATCHER(GotoStmt, isForwardJumping) { return Node.getLocStart() < Node.getLabel()->getLocStart(); } +} // namespace void AvoidGotoCheck::registerMatchers(MatchFinder *Finder) { if (!getLangOpts().CPlusPlus) diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp index bfcef89e6bbb..8b0f7ce11d26 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp @@ -17,6 +17,7 @@ namespace clang { namespace tidy { namespace cppcoreguidelines { +namespace { AST_MATCHER_P(CXXForRangeStmt, hasRangeBeginEndStmt, ast_matchers::internal::Matcher, InnerMatcher) { for (const DeclStmt *Stmt : {Node.getBeginStmt(), Node.getEndStmt()}) @@ -46,6 +47,7 @@ AST_MATCHER_P(Expr, hasParentIgnoringImpCasts, return InnerMatcher.matches(*E, Finder, Builder); } +} // namespace void ProBoundsArrayToPointerDecayCheck::registerMatchers(MatchFinder *Finder) { if (!getLangOpts().CPlusPlus) diff --git a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp index 4893b2152e0e..d4624d013f4f 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp +++ b/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp @@ -17,12 +17,14 @@ using namespace clang::ast_matchers; namespace clang { namespace tidy { namespace fuchsia { - + +namespace { AST_MATCHER(CXXRecordDecl, hasBases) { if (Node.hasDefinition()) return Node.getNumBases() > 0; return false; } +} // namespace // Adds a node (by name) to the interface map, if it was not present in the map // previously. diff --git a/clang-tools-extra/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp index bf0a5069291b..847f7635dd6e 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp +++ b/clang-tools-extra/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp @@ -15,6 +15,7 @@ namespace clang { namespace tidy { namespace fuchsia { +namespace { AST_MATCHER(FunctionDecl, isFuchsiaOverloadedOperator) { if (const auto *CXXMethodNode = dyn_cast(&Node)) { if (CXXMethodNode->isCopyAssignmentOperator() || @@ -23,6 +24,7 @@ AST_MATCHER(FunctionDecl, isFuchsiaOverloadedOperator) { } return Node.isOverloadedOperator(); } +} // namespace void OverloadedOperatorCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher(functionDecl(isFuchsiaOverloadedOperator()).bind("decl"), diff --git a/clang-tools-extra/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp index 8291f98879ba..16a534b1810b 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp +++ b/clang-tools-extra/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp @@ -14,7 +14,8 @@ using namespace clang::ast_matchers; namespace clang { namespace tidy { namespace fuchsia { - + +namespace { AST_MATCHER(Expr, isConstantInitializer) { return Node.isConstantInitializer(Finder->getASTContext(), false); } @@ -22,7 +23,8 @@ AST_MATCHER(Expr, isConstantInitializer) { AST_MATCHER(VarDecl, isGlobalStatic) { return Node.getStorageDuration() == SD_Static && !Node.isLocalVarDecl(); } - +} // namespace + void StaticallyConstructedObjectsCheck::registerMatchers(MatchFinder *Finder) { // Constructing global, non-trivial objects with static storage is // disallowed, unless the object is statically initialized with a constexpr diff --git a/clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp index 27989d9bba1c..8494da8269c3 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp +++ b/clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp @@ -15,18 +15,16 @@ using namespace clang::ast_matchers; namespace clang { -namespace ast_matchers { - -const internal::VariadicDynCastAllOfMatcher decltypeType; - -} // namespace ast_matchers - namespace tidy { namespace fuchsia { +namespace { +const internal::VariadicDynCastAllOfMatcher decltypeType; + AST_MATCHER(FunctionDecl, hasTrailingReturn) { return Node.getType()->castAs()->hasTrailingReturn(); } +} // namespace void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) { diff --git a/clang-tools-extra/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp index 6f3b433a7ef0..f3da2b6ef1d1 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp +++ b/clang-tools-extra/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp @@ -17,6 +17,7 @@ namespace clang { namespace tidy { namespace fuchsia { +namespace { AST_MATCHER(CXXRecordDecl, hasDirectVirtualBaseClass) { if (!Node.hasDefinition()) return false; if (!Node.getNumVBases()) return false; @@ -24,6 +25,7 @@ AST_MATCHER(CXXRecordDecl, hasDirectVirtualBaseClass) { if (Base.isVirtual()) return true; return false; } +} // namespace void VirtualInheritanceCheck::registerMatchers(MatchFinder *Finder) { // Defining classes using direct virtual inheritance is disallowed. diff --git a/clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp b/clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp index 053db61322ef..06969a873f44 100644 --- a/clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp +++ b/clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp @@ -13,18 +13,17 @@ using namespace clang::ast_matchers; -namespace clang { -namespace ast_matchers { -AST_MATCHER(VarDecl, isAsm) { return Node.hasAttr(); } -const internal::VariadicDynCastAllOfMatcher - fileScopeAsmDecl; -} -} - namespace clang { namespace tidy { namespace hicpp { +namespace { +AST_MATCHER(VarDecl, isAsm) { return Node.hasAttr(); } +const ast_matchers::internal::VariadicDynCastAllOfMatcher + fileScopeAsmDecl; +} // namespace + void NoAssemblerCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher(asmStmt().bind("asm-stmt"), this); Finder->addMatcher(fileScopeAsmDecl().bind("asm-file-scope"), this); diff --git a/clang-tools-extra/clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp b/clang-tools-extra/clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp index 335927b2ec7c..7567f6f644b7 100644 --- a/clang-tools-extra/clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp @@ -17,12 +17,14 @@ namespace clang { namespace tidy { namespace misc { +namespace { AST_MATCHER(StringLiteral, containsNul) { for (size_t i = 0; i < Node.getLength(); ++i) if (Node.getCodeUnit(i) == '\0') return true; return false; } +} // namespace void StringLiteralWithEmbeddedNulCheck::registerMatchers(MatchFinder *Finder) { // Match a string that contains embedded NUL character. Extra-checks are diff --git a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp index 3aab1693fa8b..1ab73d50c306 100644 --- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp @@ -23,6 +23,7 @@ namespace clang { namespace tidy { namespace modernize { +namespace { /// \brief Matches move-constructible classes. /// /// Given @@ -44,6 +45,7 @@ AST_MATCHER(CXXRecordDecl, isMoveConstructible) { } return false; } +} // namespace static TypeMatcher constRefType() { return lValueReferenceType(pointee(isConstQualified())); diff --git a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp index c4b371fcdf5c..04ecf2128735 100644 --- a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp @@ -21,6 +21,7 @@ namespace clang { namespace tidy { namespace modernize { +namespace { static const char AutoPtrTokenId[] = "AutoPrTokenId"; static const char AutoPtrOwnershipTransferId[] = "AutoPtrOwnershipTransferId"; @@ -69,6 +70,8 @@ AST_MATCHER(Decl, isFromStdNamespace) { return (Info && Info->isStr("std")); } +} // namespace + ReplaceAutoPtrCheck::ReplaceAutoPtrCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context),