[clang-tools-extra] [clang-tidy] Use lexical anon-ns matcher in llvm-prefer-static-over-anonymous-namespace (PR #148357)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 12 04:09:09 PDT 2025
================
@@ -21,6 +21,17 @@ AST_MATCHER(NamedDecl, isInMacro) {
AST_MATCHER(VarDecl, isLocalVariable) { return Node.isLocalVarDecl(); }
+AST_MATCHER(Decl, isLexicallyInAnonymousNamespace) {
+ for (const DeclContext *DC = Node.getLexicalDeclContext(); DC != nullptr;
+ DC = DC->getLexicalParent()) {
+ if (const auto *ND = dyn_cast<NamespaceDecl>(DC))
+ if (ND->isAnonymousNamespace())
+ return true;
+ }
+
+ return false;
+}
----------------
vbvictor wrote:
This code is the same as
https://github.com/llvm/llvm-project/blob/b71756852f5a41b35a74918374a11ae00365ee04/clang/lib/AST/DeclBase.cpp#L421-L429
But with change `getDeclContext` to `getLexicalDeclContext`
https://github.com/llvm/llvm-project/pull/148357
More information about the cfe-commits
mailing list