Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use cppcheck without defining all the macros

Tags:

c++

cppcheck

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?

like image 826
Brahim Avatar asked Nov 02 '15 09:11

Brahim


2 Answers

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.

like image 68
orbitcowboy Avatar answered Sep 23 '22 03:09

orbitcowboy


Not exactly what you want, but you can specify define to cppcheck so it evaluates only one branch:

see -D/-U options.

like image 28
Jarod42 Avatar answered Sep 23 '22 03:09

Jarod42