aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/clang-tidy/llvm/PreferStaticOverAnonymousNamespaceCheck.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-07-12[clang-tidy] Use lexical anon-ns matcher in ↵Baranov Victor1-3/+14
llvm-prefer-static-over-anonymous-namespace (#148357) When having this code: ```cpp namespace { class MyClassOutOfAnon { public: MyClassOutOfAnon(); } // namespace MyClassOutOfAnon::MyClassOutOfAnon() {} ``` `MyClassOutOfAnon::MyClassOutOfAnon` is located in anonymous namespace in `DeclContext` but outside anonymous namespace in `LexicalDeclContext`. For this check to work correctly, we need to check if definition is located inside `LexicalDeclContext`.
2025-07-12[clang-tidy] Add new check `llvm-prefer-static-over-anonymous-namespace` ↵Baranov Victor1-0/+100
(#142839) Finds function and variable declarations inside anonymous namespace and suggests replacing them with ``static`` declarations. The check will enforce that [restrict-visibility](https://llvm.org/docs/CodingStandards.html#restrict-visibility) rule in LLVM Coding Standards is followed correctly (by adding `static` to functions instead of putting them in anonimous namespace). The check has additional levels of "strictness" represented by Options. By default, the check works in the most relaxed way by giving warning only for methods and functions defined in anonymous namespaces. Also, It finds `static` functions that are placed inside anonymous namespace - there is no point in keeping them inside.