itiviti-cpp-analyzer (or ICA) is a Clang plugin, which brings several static analysis checks (listed here).
If you want to contribute to the project, see CONTRIBUTING.md.
You need Clang and CMake to build the plugin. Also you need libclang-10-dev
and libclang-cpp10-dev
packages. Optionally, you may need Boost 1.68+ headers (it can be downloaded during the build instead).
Currently, ICA only works with clang-10
[ ! -d build ] && mkdir build
cd build
cmake \
-DGCC_TOOLCHAIN=<path/to/gcc/toolchain (probably, /usr/lib)> \
-DBOOST_FROM_INTERNET=ON \
-DTARGET_COMPILER=clang++-10 \
../
cmake --build . --parallel
BOOST_FROM_INTERNET
is only needed if you haven't Boost headersBOOST_ROOT
can be specified insteadTARGET_COMPILER
is the compiler used for tests. Specify if you don't useclang-10
for compilation
The built plugin will be in ./build/libica-plugin.so
You need libica-plugin.so
and clang-10
A comma separated list of checks with optionally specified emit levels
Check names are listed here. Alias to list all the checks - all
Emit levels:
- nothing -
none
- check is disabled - warning -
warn
- default - error -
err
Example:
all=warn,-redundant-noexcept,erase-in-loop=err
will enable all
checks with warning level, disable redundant-noexcept
and set error level for erase-in-loop
check
You need additional flags:
-load path/to/libica-plugin.so
-add-plugin ica-plugin
-plugin-arg-ica-plugin checks=$CHECKS
-plugin-arg-ica-plugin no-url
- optionally disable integrating url to the check info
CHECKS
is the check list
Every argument for the compiler frontend is passed with -Xclang
, so the final list looks like that:
-Xclang -load -Xclang ../build/libica-plugin.so \
-Xclang -add-plugin -Xclang ica-plugin \
-Xclang -plugin-arg-ica-plugin -Xclang checks=$CHECKS
If you have a CMake project, there are options to use ICA easily, either as an external project or a subdirectory in your workspace.
First you need to have your ICA built (see) and installed:
cd build && cmake --install --install-prefix /path/to/ica/installation/
And add this to your CMakeLists.txt
# If ICA is installed in unusual location
list(APPEND CMAKE_PREFIX_PATH "/path/to/ica/installation")
find_package(ICA CONFIG REQUIRED)
ica_set_checks(<your checks list>)
target_link_libraries(<your target> ICA::ICAChecks)
Add ICA sources as subdirectory to your project (probably through git submodule) and add this to your CMakeLists.txt
# Set any other cache variables here: GCC_TOOLCHAIN, LLVM_ROOT, ...
set(BOOST_FROM_INTERNET ON)
add_subdirectory(itiviti-cpp-analyzer)
ica_set_checks(<your checks list>)
target_link_libraries(<your target> ICAChecks)
// NOLINT
comment will suppress any warning on the line
map.emplace(0, std::string{}); // NOLINT
emplace-default-value check will be suppressed here