CLion 2018.2 Help

Clang-Tidy Integration

Basics

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

How to configure the Clang-Tidy profile

General settings

Clang-Tidy checks are enabled by default in CLion and you can see them as warnings or messages of other severity levels 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 the Inspections Settings dialog (File | Settings | Editor | Inspections (or CLion | Preferences | Editor | Inspections for macOS users), select C/C++ | General | Clang-Tidy:

Settings for Clang-Tidy checks

To configure the list of enabled/disabled 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 clang-analyzer-cplusplus* ones:

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

Next, you can set up the desired Severity level and Scope for all the checks by selecting from the drop-down lists.

Options for particular checks

Some Clang-Tidy checks have options, which may be additional or substantial for the check (like those for readability-identifier-naming).

To configure options for particular checks, use the pop-up dialog Configure Clang-Tidy checks and options.

For example, you can force the modernize-use-nullptr check to replace any NULL-like macros with nullptr:

Tuning checks from the editor

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

Configuring checks from the context menu

From here you can also suppress the Clang-Tidy inspection for a particular line. In this case, CLion will add a comment // NOLINT at the end of the specified line.

Configuration files

To use .clang-tidy configuration files instead of CLion settings, clear the Use IDE settings checkbox in the Inspections Settings dialog.

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

Clang-Tidy executable

You can work with your own Clang-Tidy executable instead of the bundled one (for example, to integrate your custom checks into CLion). Simply provide a path to the 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

Last modified: 27 November 2018

See Also

External Links: