CLion 2020.1 Help

Clang-Tidy Integration

Clang-Tidy is a popular clang-based tool for static code analysis. CLion shows Clang-Tidy checks the same way as it shows its own built-in code inspections, and quick-fixes for them are available via the the Yellow bulb icon-button or Alt+Enter:

General Clang-Tidy settings

Clang-Tidy checks are enabled by default and you can see them as warnings (or messages of other severity level) in the editor. Here you can find details of 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 Settings/Preferences | Editor | Inspections, C/C++ | General | Clang-Tidy:

Settings for Clang-Tidy checks

To enable/disable particular checks, use the Clang-Tidy command line format which specifies a comma-separated list of positive and negative globs. Positive globs add subsets of checks, and negative (prefixed with "-") globs remove them.

For example, the following command line will disable all default checks -* and enable all clang-analyzer-* checks except for the clang-analyzer-cplusplus* ones:

-*,clang-analyzer-*,-clang-analyzer-cplusplus*

Also, you can set the desired severity level and scope for all the Clang-Tidy checks by selecting from the drop-down lists.

Options for particular checks

Some Clang-Tidy checks have options, either additional or substantial for a check (like those for readability-identifier-naming).

To configure options for particular checks, use the Configure Clang-Tidy Checks Options dialog. For example, you can force the modernize-use-nullptr check to replace any NULL-like macros with nullptr:

Options for checks

Tuning checks from the editor

Besides the Inspections Settings dialog, certain configurations are accessible from the editor: you can disable a single check, a group of checks, or the whole Clang-Tidy inspection. These actions respectively update the Clang-Tidy command line.

Configuring checks from the context menu

To suppress a Clang-Tidy check for a particular line, use the Suppress "check_name" for line option. CLion will add a // NOLINT comment at the end of the selected line.

Configuration files

By default, if a .clang-tidy configuration file is detected in your project, CLion turns off the IDE settings and uses the .clang-tidy file instead. To change this behavior, clear the Prefer .clang-tidy files over IDE settings checkbox in Settings/Preferences | Editor | Inspections, C/C++ | General | Clang-Tidy.

With .clang-tidy files, you can set per-directory configurations: for each source file, Clang-Tidy will attempt to read configuration from a .clang-tidy file located in the closest parent directory.

.clang-tidy files are in YAML format. For the syntax example, let's enable all of the Clang-Tidy checks and provide the additional option to modernize-use-nullptr:

Checks: '*' CheckOptions: - key: modernize-use-nullptr.NullMacros value: NULL,CUSTOM_NULL

Custom Clang-Tidy executable

You can work with your own Clang-Tidy executable instead of the bundled one (for example, in order to create your custom checks and use them in CLion).

Provide the path to your custom Clang-Tidy binary in Settings/Preferences | Languages & Frameworks | C/C++ (or click Specify Clang-Tidy executable in the Inspections Settings dialog).

Custom Clang-Tidy binary

This setting is IDE-wide: your custom Clang-Tidy binary will be used for all projects.

Last modified: 11 June 2020