[clang-tools-extra] d3c3de6 - [clang-tidy][NFC] Simply match processing in misc-use-anonymous-namespace
Carlos Galvez via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 12 06:05:43 PST 2022
Author: Carlos Galvez
Date: 2022-12-12T14:05:19Z
New Revision: d3c3de63ce8416ab2dee7f784e54b00a2aa8ed85
URL: https://github.com/llvm/llvm-project/commit/d3c3de63ce8416ab2dee7f784e54b00a2aa8ed85
DIFF: https://github.com/llvm/llvm-project/commit/d3c3de63ce8416ab2dee7f784e54b00a2aa8ed85.diff
LOG: [clang-tidy][NFC] Simply match processing in misc-use-anonymous-namespace
No need for the templated function "processMatch", since
we can infer the type with llvm:isa.
Added:
Modified:
clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
index 878cba31eb2ab..fdf7828c8c0fd 100644
--- a/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
@@ -31,33 +31,26 @@ AST_MATCHER(Decl, isInAnonymousNamespace) {
}
} // namespace
-template <typename T>
-void UseAnonymousNamespaceCheck::processMatch(const T *MatchedDecl) {
- StringRef Type = llvm::isa<VarDecl>(MatchedDecl) ? "variable" : "function";
- diag(MatchedDecl->getLocation(),
- "%0 %1 declared 'static', move to anonymous namespace instead")
- << Type << MatchedDecl;
-}
-
void UseAnonymousNamespaceCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
functionDecl(isStatic(),
unless(anyOf(isInAnonymousNamespace(), isMemberFunction())))
- .bind("func"),
+ .bind("x"),
this);
Finder->addMatcher(
varDecl(isStatic(), unless(anyOf(isInAnonymousNamespace(),
isStaticLocal(), isStaticDataMember())))
- .bind("var"),
+ .bind("x"),
this);
}
void UseAnonymousNamespaceCheck::check(const MatchFinder::MatchResult &Result) {
- if (const auto *MatchedDecl = Result.Nodes.getNodeAs<FunctionDecl>("func"))
- processMatch(MatchedDecl);
-
- if (const auto *MatchedDecl = Result.Nodes.getNodeAs<VarDecl>("var"))
- processMatch(MatchedDecl);
+ if (const auto *MatchedDecl = Result.Nodes.getNodeAs<NamedDecl>("x")) {
+ StringRef Type = llvm::isa<VarDecl>(MatchedDecl) ? "variable" : "function";
+ diag(MatchedDecl->getLocation(),
+ "%0 %1 declared 'static', move to anonymous namespace instead")
+ << Type << MatchedDecl;
+ }
}
} // namespace misc
diff --git a/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h b/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
index 59c48029711e0..19d76bfc19f63 100644
--- a/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
@@ -29,9 +29,6 @@ class UseAnonymousNamespaceCheck : public ClangTidyCheck {
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
-
-private:
- template <typename T> void processMatch(const T *MatchedDecl);
};
} // namespace misc
More information about the cfe-commits
mailing list