Clang-Tidy usage
The syntax of using the tool
clang-tidy [options] <source0> [... <sourceN>]
Compilation options can be specified on the command line after --
. For example -D<macro>
, -I<dir>
, -Werror
. etc.
clang-tidy test.cpp -- -Imy_project/include -DMY_DEFINES ...
Additionally if the list of options and source files are too long, it can be stored in a parameter file and put after clang-tidy
command
clang-tidy @parameters_file
Several checks can be performed with the tool. The following commands list the enabled and all available checks.
clang-tidy --list-checks -checks=
clang-tidy --list-checks -checks=*
Selecting the needed checks can be done with the command below.
clang-tidy --list-checks -checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus*,-clang-analyzer-unix*
-
-checks=-*
disables all default checks -
clang-analyzer-*
enables all checks with prefix clang-analyzer- -
-clang-analyzer-cplusplus*
disables the cplusplus related checks -
-clang-analyzer-unix*
disables the unix related checks
remark: clang-analyzer-core checks can not be disabled.
All checks are listed at https://clang.llvm.org/extra/clang-tidy/checks/list.html. Each check has a short description with example codes to show when the check is triggered and gives a warning.
For example if more details are necessary about the clang-analyzer-core, navigate to the https://clang.llvm.org/docs/analyzer/checkers.html website and search for core.
Description of core checks which is copied from the website:
Models core language features and contains general-purpose checkers such as division by zero, null pointer dereference, usage of uninitialized values, etc. These checkers must be always switched on as other checker rely on them