I use cppcheck on a project using the boost library. The headers in this library contain a huge amount of macro that I don't even use in my sources. Nevertheless, cppcheck explore paths depending on these macros that I think useless. Is there a way to tell cppcheck to ignore all macros unless it's defined in a source code using a #define?
Asked
Active
Viewed 1.1k times
4 Answers
6
Here is the the necessary part from cppcheck documentation:
-D<ID> Define preprocessor symbol. Unless --max-configs or
--force is used, Cppcheck will only check the given
configuration when -D is used.
Example: '-DDEBUG=1 -D__cplusplus'.
-U<ID> Undefine preprocessor symbol. Use -U to explicitly
hide certain #ifdef <ID> code paths from checking.
Example: '-UDEBUG'
You are able to define (-D) or undefine (-U) custom preprocesser symbols with these options.
Another option that is potentially interesting is
-f, --force Force checking of all configurations in files. If used
together with '--max-configs=', the last option is the
one that is effective.
and
--max-configs=<limit>
Maximum number of configurations to check in a file
before skipping it. Default is '12'. If used together
with '--force', the last option is the one that is
effective.
This means the following:
cppcheck --force <PATH_TO_YOUR_CODE>
Cppcheck verifies all combinations of preprocessor paths, which could lead to long checking times on large code bases.
The corresponding documentation can be found here.

orbitcowboy
- 1,438
- 13
- 25
5
Not exactly what you want, but you can specify define
to cppcheck so it evaluates only one branch:
see -D
/-U
options.

Jarod42
- 203,559
- 14
- 181
- 302
-
so if I have 10 macros, and if I define 3 of them (when compiling or in my source), do I need to undef the 7 others? – Brahim Nov 02 '15 at 09:26
-
@Brahim: if you have something like `#ifdef UNSET_MACRO1`, yes to avoid to check both paths. – Jarod42 Nov 02 '15 at 10:18
3
One option is to ignore lines with missing macros by putting this comment above the offending line:
// cppcheck-suppress unknownMacro

nnnmmm
- 7,964
- 4
- 22
- 41
0
Use --config-exclude= to exclude the directories that contain unmanageable configurations. It only excludes header files.

Bee
- 1