| 1 |
.. title:: clang-tidy - modernize-deprecated-headers |
| 2 |
|
| 3 |
modernize-deprecated-headers |
| 4 |
============================ |
| 5 |
|
| 6 |
Some headers from C library were deprecated in C++ and are no longer welcome in |
| 7 |
C++ codebases. Some have no effect in C++. For more details refer to the C++14 |
| 8 |
Standard [depr.c.headers] section. |
| 9 |
|
| 10 |
This check replaces C standard library headers with their C++ alternatives and |
| 11 |
removes redundant ones. |
| 12 |
|
| 13 |
.. code-block:: c++ |
| 14 |
|
| 15 |
// C++ source file... |
| 16 |
#include <assert.h> |
| 17 |
#include <stdbool.h> |
| 18 |
|
| 19 |
// becomes |
| 20 |
|
| 21 |
#include <cassert> |
| 22 |
// No 'stdbool.h' here. |
| 23 |
|
| 24 |
Important note: the Standard doesn't guarantee that the C++ headers declare all |
| 25 |
the same functions in the global namespace. The check in its current form can |
| 26 |
break the code that uses library symbols from the global namespace. |
| 27 |
|
| 28 |
* `<assert.h>` |
| 29 |
* `<complex.h>` |
| 30 |
* `<ctype.h>` |
| 31 |
* `<errno.h>` |
| 32 |
* `<fenv.h>` // deprecated since C++11 |
| 33 |
* `<float.h>` |
| 34 |
* `<inttypes.h>` |
| 35 |
* `<limits.h>` |
| 36 |
* `<locale.h>` |
| 37 |
* `<math.h>` |
| 38 |
* `<setjmp.h>` |
| 39 |
* `<signal.h>` |
| 40 |
* `<stdarg.h>` |
| 41 |
* `<stddef.h>` |
| 42 |
* `<stdint.h>` |
| 43 |
* `<stdio.h>` |
| 44 |
* `<stdlib.h>` |
| 45 |
* `<string.h>` |
| 46 |
* `<tgmath.h>` // deprecated since C++11 |
| 47 |
* `<time.h>` |
| 48 |
* `<uchar.h>` // deprecated since C++11 |
| 49 |
* `<wchar.h>` |
| 50 |
* `<wctype.h>` |
| 51 |
|
| 52 |
If the specified standard is older than C++11 the check will only replace |
| 53 |
headers deprecated before C++11, otherwise -- every header that appeared in |
| 54 |
the previous list. |
| 55 |
|
| 56 |
These headers don't have effect in C++: |
| 57 |
|
| 58 |
* `<iso646.h>` |
| 59 |
* `<stdalign.h>` |
| 60 |
* `<stdbool.h>` |
| 61 |
|
| 62 |
The checker ignores `include` directives within `extern "C" { ... }` blocks, |
| 63 |
since a library might want to expose some API for C and C++ libraries. |
| 64 |
|
| 65 |
.. code-block:: c++ |
| 66 |
|
| 67 |
// C++ source file... |
| 68 |
extern "C" { |
| 69 |
#include <assert.h> // Left intact. |
| 70 |
#include <stdbool.h> // Left intact. |
| 71 |
} |
| 72 |
|
| 73 |
Options |
| 74 |
------- |
| 75 |
|
| 76 |
.. option:: CheckHeaderFile |
| 77 |
|
| 78 |
`clang-tidy` cannot know if the header file included by the currently |
| 79 |
analyzed C++ source file is not included by any other C source files. |
| 80 |
Hence, to omit false-positives and wrong fixit-hints, we ignore emitting |
| 81 |
reports into header files. One can set this option to `true` if they know |
| 82 |
that the header files in the project are only used by C++ source file. |
| 83 |
Default is `false`. |