xref: /llvm-project/clang-tools-extra/docs/clang-tidy/checks/llvmlibc/restrict-system-libc-headers.rst (revision 6e566bc5523f743bc34a7e26f050f1f2b4d699a8)
1.. title:: clang-tidy - llvmlibc-restrict-system-libc-headers
2
3llvmlibc-restrict-system-libc-headers
4=====================================
5
6Finds includes of system libc headers not provided by the compiler within
7llvm-libc implementations.
8
9.. code-block:: c++
10
11   #include <stdio.h>            // Not allowed because it is part of system libc.
12   #include <stddef.h>           // Allowed because it is provided by the compiler.
13   #include "internal/stdio.h"   // Allowed because it is NOT part of system libc.
14
15
16This check is necessary because accidentally including system libc headers can
17lead to subtle and hard to detect bugs. For example consider a system libc
18whose ``dirent`` struct has slightly different field ordering than llvm-libc.
19While this will compile successfully, this can cause issues during runtime
20because they are ABI incompatible.
21
22Options
23-------
24
25.. option:: Includes
26
27   A string containing a comma separated glob list of allowed include
28   filenames. Similar to the -checks glob list for running clang-tidy itself,
29   the two wildcard characters are `*` and `-`, to include and exclude globs,
30   respectively. The default is `-*`, which disallows all includes.
31
32   This can be used to allow known safe includes such as Linux development
33   headers. See :doc:`portability-restrict-system-includes
34   <../portability/restrict-system-includes>` for more
35   details.
36