with the boost headers installed under /usr/include. Note that we are using -I instead of -isystem due to a bug in our build system.
>cppcheck--versionCppcheck2.17dev>cppcheck--project=compile_commands.json--enable=warning--library=boostCheckingTest.cxx.../usr/include/boost/config/requires_threads.hpp:86:0:error:#error"Compiler threading support is not turned on. Please consult your compiler's documentation for the appropriate options to use"[preprocessorErrorDirective]#error"Compiler threading support is not turned on. Please consult your compiler's documentation for the appropriate options to use"^
The #error is triggered by not having BOOST_HAS_THREADS defined but adding -DBOOST_HAS_THREADS to the compile command or directly on the command line has no effect.
Now remove the #include <boost/thread/tss.hpp> and you will see the expected defect:
In our case, the apparent parsing error was completely hidden because we usually suppress 3rd party libraries with --suppress="*:/usr/include/boost/*". In which case, the user does not see any error and assumes there are no defects.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Could you give a few more details how this should be done in practice? We are running cppcheck as part of our cmake build. So we don't have control over which headers cppcheck gets to see.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The way cppcheck treat the "#include" pragma in preprocessing is as follows:
1. If the header is found in the relative or the include paths with the "-I" flag, then cppcheck includes it
2. Otherwise, it ignores this line and continues.
The design of cppcheck as a textual checker, is that intentionally it doesn't want the user to specify the "-I" flag for the std and boost libraries, but rather use the "packaged library" flags, that is enabled by default to std, but is needed to be explicitly given for boost with the cppcheck flag --library=boost
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
We came across a case where parsing a Boost header seems to completely hide valid defects.
Consider the following test case:
and this
compile_commands.json
:with the boost headers installed under /usr/include. Note that we are using
-I
instead of-isystem
due to a bug in our build system.The
#error
is triggered by not havingBOOST_HAS_THREADS
defined but adding-DBOOST_HAS_THREADS
to the compile command or directly on the command line has no effect.Now remove the
#include <boost/thread/tss.hpp>
and you will see the expected defect:In our case, the apparent parsing error was completely hidden because we usually suppress 3rd party libraries with
--suppress="*:/usr/include/boost/*"
. In which case, the user does not see any error and assumes there are no defects.Boost headers should not be visible to cppcheck. Please pass
--library=boost
instead.Could you give a few more details how this should be done in practice? We are running cppcheck as part of our cmake build. So we don't have control over which headers cppcheck gets to see.
The way cppcheck treat the "#include" pragma in preprocessing is as follows:
1. If the header is found in the relative or the include paths with the "-I" flag, then cppcheck includes it
2. Otherwise, it ignores this line and continues.
The design of cppcheck as a textual checker, is that intentionally it doesn't want the user to specify the "-I" flag for the std and boost libraries, but rather use the "packaged library" flags, that is enabled by default to std, but is needed to be explicitly given for boost with the cppcheck flag
--library=boost
Maybe
-i/usr/include/boost
can be added to the cppcheck command line? Haven't tested this though.