You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -122,13 +125,13 @@ Typically a `compile_commands.json` contains absolute paths. However no matter i
122
125
* a file with relative path `src/test2.c` can be checked.
123
126
* a file with relative path `src/test3.cpp` is not checked.
124
127
125
-
### Excluding a file or folder from checking
128
+
### Ignore files matching a given pattern
126
129
127
-
The option `-i` specifies a pattern to files/folders to exclude. With this command no files in `src/c` are checked:
130
+
With `-i <str>` you can configure filename/directory patterns that should be ignored.
128
131
129
-
cppcheck -isrc/c src
132
+
A file that is ignored will not be checked directly (the complete translation unit is skipped). Any header #include'd from a source file which is not ignored is checked indirectly, regardless if the header is ignored.
130
133
131
-
The `-i` option is not used during preprocessing, it can't be used to exclude headers that are included.
134
+
> *Note*: If you want to filter out warnings for a header file then `-i` will not work. Use suppressions instead.
132
135
133
136
You can use `**`, `*` and `?` in the pattern to specify excluded folders/files.
134
137
`**`: matches zero or more characters, including path separators
@@ -149,8 +152,8 @@ By default Cppcheck uses an internal C/C++ parser. However there is an experimen
149
152
150
153
Install `clang`. Then use Cppcheck option `--clang`.
151
154
152
-
Technically, Cppcheck will execute `clang` with its `-ast-dump` option. The Clang output is then imported and converted into
153
-
the normal Cppcheck format. And then normal Cppcheck analysis is performed on that.
155
+
Cppcheck executes clang with the -ast-dump option, imports the output, converts it to Cppcheck's internal format, and then
156
+
performs standard analysis.
154
157
155
158
You can also pass a custom Clang executable to the option by using for example `--clang=clang-10`. You can also pass it
156
159
with a path. On Windows it will append the `.exe` extension unless you use a path.
@@ -190,9 +193,8 @@ be improved.
190
193
191
194
Cppcheck instantiates the templates in your code.
192
195
193
-
If your templates are recursive this can lead to slow analysis that uses a lot
194
-
of memory. Cppcheck will write information messages when there are potential
195
-
problems.
196
+
If your templates are recursive, this can lead to slow analysis and high memory usage. Cppcheck will write information
197
+
messages when there are potential problems.
196
198
197
199
Example code:
198
200
@@ -249,7 +251,7 @@ Using a Cppcheck build folder is not mandatory but it is recommended.
249
251
250
252
Cppcheck save analyzer information in that folder.
251
253
252
-
The advantages are;
254
+
The advantages are:
253
255
254
256
- It speeds up the analysis as it makes incremental analysis possible. Only changed files are analyzed when you recheck.
255
257
- Whole program analysis also when multiple threads are used.
@@ -285,7 +287,7 @@ To ignore certain folders in the project you can use `-i`. This will skip the an
285
287
286
288
## CMake
287
289
288
-
Generate a compile database:
290
+
Generate a compile database (a JSON file containing compilation commands for each source file):
289
291
290
292
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
291
293
@@ -368,9 +370,12 @@ Here is a file that has 3 bugs (when x,y,z are assigned).
368
370
#error C must be defined
369
371
#endif
370
372
373
+
The flag `-D` tells Cppcheck that a name is defined. Cppcheck will only analyze configurations that
374
+
contain this define.
375
+
376
+
The flag `-U` tells Cppcheck that a name is not defined. Cppcheck will only analyze configurations
377
+
that does not contain this define.
371
378
372
-
The flag `-D` tells Cppcheck that a name is defined. There will be no Cppcheck analysis without this define.
373
-
The flag `-U` tells Cppcheck that a name is not defined. There will be no Cppcheck analysis with this define.
374
379
The flag `--force` and `--max-configs` is used to control how many combinations are checked. When `-D` is used,
375
380
Cppcheck will only check 1 configuration unless these are used.
376
381
@@ -476,7 +481,8 @@ build dir. For instance, the unusedFunction warnings require whole program analy
476
481
477
482
If you want to filter out certain errors from being generated, then it is possible to suppress these.
478
483
479
-
If you encounter a false positive, then please report it to the Cppcheck team so that it can be fixed.
484
+
If you encounter a false positive, please report it to the Cppcheck team so that the issue can be
485
+
fixed.
480
486
481
487
## Plain text suppressions
482
488
@@ -1034,7 +1040,7 @@ Example configuration of naming conventions:
1034
1040
1035
1041
### y2038.py
1036
1042
1037
-
[y2038.py](https://github.com/danmar/cppcheck/blob/main/addons/y2038.py) checks Linux systems for [year 2038 problem](https://en.wikipedia.org/wiki/Year_2038_problem) safety. This required [modified environment](https://github.com/3adev/y2038). See complete description [here](https://github.com/danmar/cppcheck/blob/main/addons/doc/y2038.txt).
1043
+
[y2038.py](https://github.com/danmar/cppcheck/blob/main/addons/y2038.py) checks source code for [year 2038 problem](https://en.wikipedia.org/wiki/Year_2038_problem) safety.
1038
1044
1039
1045
## Running Addons
1040
1046
@@ -1073,6 +1079,7 @@ Cppcheck already contains configurations for several libraries. They can be load
1073
1079
## Using a .cfg file
1074
1080
1075
1081
To use a .cfg file shipped with cppcheck, pass the `--library=<lib>` option. The table below shows the currently existing libraries:
0 commit comments