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 `HeaderFileExtensions` option (see below).
19 * ``const`` or ``constexpr`` variables, since they already have implicit internal
39 .. option:: HeaderFileExtensions
41 Note: this option is deprecated, it will be removed in :program:`clang-tidy`
42 version 19. Please use the global configuration option
43 `HeaderFileExtensions`.
45 A semicolon-separated list of filename extensions of header files (the filename
46 extensions should not include "." prefix). Default is ";h;hh;hpp;hxx".
47 For extension-less header files, using an empty string or leaving an
48 empty string between ";" if there are other filename extensions.
50 [1] `Undeprecating static <https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1012>`_