CLion 2017.3 Help

Clang-Tidy Integration

Basics

Clang-Tidy is a popular clang-based tool for static code analysis. CLion supports Clang-Tidy in the same way as its own code analysis tool.

How to configure Clang-Tidy profile

General configuration

Clang-Tidy checks are enabled by default in CLion and you can see them as the warnings or messages of other severity levels in the editor. Here you can find the details on the Clang-Tidy default configuration in CLion. Note, that not all the checks are enabled by default.
You can change the Clang-Tidy configuration in Inspections Settings dialog (File | Settings | Editor | Inspections (or CLion | Preferences | Editor | Inspections for macOS users), select C/C++ | General | Clang-Tidy.
To configure the list of checks to enable / disable in text form, use the Clang-Tidy command line format (see example below).
To set up the desired severity level and scope for all the checks select the values from the drop-down lists of the Inspections Settings dialog.
If you need to switch Clang-Tidy checks off completely, unselect the corresponding check-box (the right column) or select this check-box to enable Clang-Tidy checks support again.

Per check configurations

You can disable a particular Clang-Tidy check from the CLion context menu, as follows:

/help/img/idea/2017.3/cl_ClangTidyDisableCheck.gif
This action will update the list of enabled/disable checks in Settings/Preferences | Editor | Inspections | C/C++ | General | Clang-Tidy:
/help/img/idea/2017.3/cl_ClangTidyListChecks.png
In this context menu you can also find an option to suppress Clang-Tidy check for a particular line via // NOLINT.

Clang-Tidy executable

You can use bundled or your own Clang-Tidy in CLion, at your choice. If you prefer the latter you shall provide a path to the Clang-Tidy binary in File | Settings | Languages & Frameworks | C/C++ (or CLion | Preferences | Languages & Frameworks | C/C++ if you are macOS user):

/help/img/idea/2017.3/cl_ownClangTidy.png

Example

Let's run the C++ Core Guidelines checks on the project. To do that, open the Settings dialog (see above) and pass the following line -*,cppcoreguidelines-*:

/help/img/idea/2017.3/cl_ClangTidySettings.png
As the result, only C++ Core Guidelines checks are running on the project:
The same, pass -*,clang-analyzer-* line to run the Clang Static Analyzer checks or -*,modernize-* for modernize checks.

Last modified: 24 October 2017

See Also

External Links: