| 1 |
.. title:: clang-tidy - misc-use-internal-linkage |
| 2 |
|
| 3 |
misc-use-internal-linkage |
| 4 |
========================= |
| 5 |
|
| 6 |
Detects variables and functions that can be marked as static or moved into |
| 7 |
an anonymous namespace to enforce internal linkage. |
| 8 |
|
| 9 |
Static functions and variables are scoped to a single file. Marking functions |
| 10 |
and variables as static helps to better remove dead code. In addition, it gives |
| 11 |
the compiler more information and allows for more aggressive optimizations. |
| 12 |
|
| 13 |
Example: |
| 14 |
|
| 15 |
.. code-block:: c++ |
| 16 |
|
| 17 |
int v1; // can be marked as static |
| 18 |
|
| 19 |
void fn1(); // can be marked as static |
| 20 |
|
| 21 |
namespace { |
| 22 |
// already in anonymous namespace |
| 23 |
int v2; |
| 24 |
void fn2(); |
| 25 |
} |
| 26 |
// already declared as extern |
| 27 |
extern int v2; |
| 28 |
|
| 29 |
Options |
| 30 |
------- |
| 31 |
|
| 32 |
.. option:: FixMode |
| 33 |
|
| 34 |
Selects what kind of a fix the check should provide. The default is `UseStatic`. |
| 35 |
|
| 36 |
``None`` |
| 37 |
Don't fix automatically. |
| 38 |
|
| 39 |
``UseStatic`` |
| 40 |
Add ``static`` for internal linkage variable and function. |