| 1 |
.. title:: clang-tidy - readability-redundant-preprocessor |
| 2 |
|
| 3 |
readability-redundant-preprocessor |
| 4 |
================================== |
| 5 |
|
| 6 |
Finds potentially redundant preprocessor directives. At the moment the |
| 7 |
following cases are detected: |
| 8 |
|
| 9 |
* `#ifdef` .. `#endif` pairs which are nested inside an outer pair with the |
| 10 |
same condition. For example: |
| 11 |
|
| 12 |
.. code-block:: c++ |
| 13 |
|
| 14 |
#ifdef FOO |
| 15 |
#ifdef FOO // inner ifdef is considered redundant |
| 16 |
void f(); |
| 17 |
#endif |
| 18 |
#endif |
| 19 |
|
| 20 |
* Same for `#ifndef` .. `#endif` pairs. For example: |
| 21 |
|
| 22 |
.. code-block:: c++ |
| 23 |
|
| 24 |
#ifndef FOO |
| 25 |
#ifndef FOO // inner ifndef is considered redundant |
| 26 |
void f(); |
| 27 |
#endif |
| 28 |
#endif |
| 29 |
|
| 30 |
* `#ifndef` inside an `#ifdef` with the same condition: |
| 31 |
|
| 32 |
.. code-block:: c++ |
| 33 |
|
| 34 |
#ifdef FOO |
| 35 |
#ifndef FOO // inner ifndef is considered redundant |
| 36 |
void f(); |
| 37 |
#endif |
| 38 |
#endif |
| 39 |
|
| 40 |
* `#ifdef` inside an `#ifndef` with the same condition: |
| 41 |
|
| 42 |
.. code-block:: c++ |
| 43 |
|
| 44 |
#ifndef FOO |
| 45 |
#ifdef FOO // inner ifdef is considered redundant |
| 46 |
void f(); |
| 47 |
#endif |
| 48 |
#endif |
| 49 |
|
| 50 |
* `#if` .. `#endif` pairs which are nested inside an outer pair with the same |
| 51 |
condition. For example: |
| 52 |
|
| 53 |
.. code-block:: c++ |
| 54 |
|
| 55 |
#define FOO 4 |
| 56 |
#if FOO == 4 |
| 57 |
#if FOO == 4 // inner if is considered redundant |
| 58 |
void f(); |
| 59 |
#endif |
| 60 |
#endif |
| 61 |
|