Clang Tidy Clion

Tidy

I confirm that I get some processes in the background while I type, including clang-tidy and other clion/.jar related processes. They show up and disappear but it's not a big deal when my CPUs are not saturated. You may also verify that you do not run out of clion-allocated memory: there is a memory meter in the bottom-right corner. There are dozens of refactorings, code analysis (including Data Flow Analysis and Clang-Tidy integration) and integration with GDB and LLDB. CLion uses the well-known CMake build system, supports Google test, Boost.Test, and Catch unit testing.

Clang Tidy Configuration

Contents

  • Clang-Tidy

See also:

clang-tidy is a clang-based C++ “linter” tool. Its purpose is toprovide an extensible framework for diagnosing and fixing typical programmingerrors, like style violations, interface misuse, or bugs that can be deduced viastatic analysis. clang-tidy is modular and provides a convenientinterface for writing new checks.

clang-tidy is a LibTooling-based tool, and it’s easier to workwith if you set up a compile command database for your project (for an exampleof how to do this see How To Setup Tooling For LLVM). You can also specifycompilation options on the command line after --:

clang-tidy has its own checks and can also run Clang static analyzerchecks. Each check has a name and the checks to run can be chosen using the-checks= option, which specifies a comma-separated list of positive andnegative (prefixed with -) globs. Positive globs add subsets of checks,negative globs remove them. For example,

will disable all default checks (-*) and enable all clang-analyzer-*checks except for clang-analyzer-cplusplus* ones.

The -list-checks option lists all the enabled checks. When used without-checks=, it shows checks enabled by default. Use -checks=* to see allavailable checks or with any other value of -checks= to see which checks areenabled by this value.

There are currently the following groups of checks:

Clang tidy checks
Name prefixDescription
abseil-Checks related to Abseil library.
altera-Checks related to OpenCL programming for FPGAs.
android-Checks related to Android.
boost-Checks related to Boost library.
bugprone-Checks that target bugprone code constructs.
cert-Checks related to CERT Secure Coding Guidelines.
clang-analyzer-Clang Static Analyzer checks.
concurrency-Checks related to concurrent programming (includingthreads, fibers, coroutines, etc.).
cppcoreguidelines-Checks related to C++ Core Guidelines.
darwin-Checks related to Darwin coding conventions.
fuchsia-Checks related to Fuchsia coding conventions.
google-Checks related to Google coding conventions.
hicpp-Checks related to High Integrity C++ Coding Standard.
linuxkernel-Checks related to the Linux Kernel coding conventions.
llvm-Checks related to the LLVM coding conventions.
llvmlibc-Checks related to the LLVM-libc coding standards.
misc-Checks that we didn’t have a better category for.
modernize-Checks that advocate usage of modern (currently “modern”means “C++11”) language constructs.
mpi-Checks related to MPI (Message Passing Interface).
objc-Checks related to Objective-C coding conventions.
openmp-Checks related to OpenMP API.
performance-Checks that target performance-related issues.
portability-Checks that target portability-related issues that don’trelate to any particular coding style.
readability-Checks that target readability-related issues that don’trelate to any particular coding style.
zircon-Checks related to Zircon kernel coding conventions.

Clang diagnostics are treated in a similar way as check diagnostics. Clangdiagnostics are displayed by clang-tidy and can be filtered out using-checks= option. However, the -checks= option does not affectcompilation arguments, so it can not turn on Clang warnings which are notalready turned on in build configuration. The -warnings-as-errors= optionupgrades any warnings emitted under the -checks= flag to errors (but itdoes not enable any checks itself).

Clang Tidy Suppress Warning

Clang diagnostics have check names starting with clang-diagnostic-.Diagnostics which have a corresponding warning option, are namedclang-diagnostic-<warning-option>, e.g. Clang warning controlled by-Wliteral-conversion will be reported with check nameclang-diagnostic-literal-conversion.

The -fix flag instructs clang-tidyThe Other Side of the Night PDF Free download. to fix found errors ifsupported by corresponding checks.

Clang Tidy Checks

An overview of all the command-line options:

clang-tidy diagnostics are intended to call out code that does notadhere to a coding standard, or is otherwise problematic in some way. However,if the code is known to be correct, it may be useful to silence the warning.Some clang-tidy checks provide a check-specific way to silence the diagnostics,e.g. bugprone-use-after-move can besilenced by re-initializing the variable after it has been moved out,bugprone-string-integer-assignment can be suppressed byexplicitly casting the integer to char,readability-implicit-bool-conversion can also be suppressed byusing explicit casts, etc.

If a specific suppression mechanism is not available for a certain warning, orits use is not desired for some reason, clang-tidy has a genericmechanism to suppress diagnostics using NOLINT or NOLINTNEXTLINEcomments.

The NOLINT comment instructs clang-tidy to ignore warnings on thesame line (it doesn’t apply to a function, a block of code or any otherlanguage construct, it applies to the line of code it is on). If introducing thecomment in the same line would change the formatting in undesired way, theNOLINTNEXTLINE comment allows to suppress clang-tidy warnings on the nextline.

Clang Tidy Options

Both comments can be followed by an optional list of check names in parentheses(see below for the formal syntax).

For example:

The formal syntax of NOLINT/NOLINTNEXTLINE is the following:

Note that whitespaces between NOLINT/NOLINTNEXTLINE and the openingparenthesis are not allowed (in this case the comment will be treated just asNOLINT/NOLINTNEXTLINE), whereas in check names list (inside theparenthesis) whitespaces can be used and will be ignored.