1 .. title:: clang-tidy - misc-use-anonymous-namespace
3 misc-use-anonymous-namespace
4 ============================
6 Finds instances of ``static`` functions or variables declared at global scope
7 that could instead be moved into an anonymous namespace.
9 Anonymous namespaces are the "superior alternative" according to the C++
10 Standard. ``static`` was proposed for deprecation, but later un-deprecated to
11 keep C compatibility [1]. ``static`` is an overloaded term with different meanings in
12 different contexts, so it can create confusion.
14 The following uses of ``static`` will *not* be diagnosed:
16 * Functions or variables in header files, since anonymous namespaces in headers
17 is considered an antipattern. Allowed header file extensions can be configured
18 via the global option `HeaderFileExtensions`.
19 * ``const`` or ``constexpr`` variables, since they already have implicit internal
36 [1] `Undeprecating static <https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1012>`_