Using Clang Tools | Qt Creator Manual

Qt Creator Manual | Using Clang Tools

Qt Creator Manual 4.7.1

Running Valgrind Tools on External Applications ◦ Detecting Memory Leaks with Heob

# Using Clang Tools

Qt Creator integrates the following Clang tools for finding problems in C, C++, and Objective-C source code by using static analysis:

- Clang-Tidy, which provides diagnostics and fixes for typical programming errors, such as style violations or interface misuse.
- Clazy, which helps Clang understand Qt semantics. It displays Qt related compiler warnings, ranging from unnecessary memory allocation to misuse of API and provides refactoring actions for fixing some of the issues.

Note: The Clang static analyzer checks are a part of Clang-Tidy. To use the checks you must create a custom configuration for the Clang tools and enable them for Clang-Tidy.

Clang tools are delivered and installed with Qt Creator, and therefore you do not need to set them up separately.

## Running Clang Tools

To run the Clang tools to analyze an open project:

1. Select Analyze > Clang-Tidy and Clazy.

2. In the Diagnostic Configuration group, select a Clang configuration in the list of pre-defined configurations (1). For more information about creating a custom configuration, see Configuring Clang Tools.
3. In the Files to Analyze group, select the files to apply the checks to.
4. Select Analyze to start the checks.

If you select Debug in the mode selector to open the Debug mode and then select Clang-Tidy and Clazy, you must select the (Start) button to open the Analyzer Configuration dialog.

The found issues are displayed in the Clang-Tidy and Clazy view:

Select the link in the Location column to move to the location where the issue appears in the code editor.

In the Fixit Status column, select issues that you want to apply refactoring actions to, and then select Apply Fixits. The status of the issues is updated in the Fixit Status column.

## Configuring Clang Tools

To configure Clang diagnostics globally for Clang tools:

- Select Tools > Options > Analyzer > Clang Tools.

- To build the project before running the Clang tools, select the Build the project before analysis check box. The Clang tools do not require the project to be built before analysis, but they might display misleading warnings about files missing that are generated during the build. For big projects, not building the project might save some time.
- In the Simultaneous processes field, select the number of processes to run simultaneously to make the analysis faster on multi-core processors.
- In the Diagnostic Configuration group, select Manage to create or edit a custom configuration.
- Select Copy to create a custom Clang configuration.

- In the Diagnostic configuration name field, give the configuration a name, and then select OK.
- In the Clang-Tidy tab, select the checks to perform.

- To edit the selected check as plain text, select Edit Checks as String.
- In the Clazy tab, select the level of Clazy checks to perform.

To suppress diagnostics, select Suppress This Diagnostic in the context menu. To view the suppression list for a project and to remove diagnostics from it, select Projects > Project Settings > Clang Tools.

### Selecting Clazy Check Levels

The Clazy checks are divided into levels from 0 to 3. Each level adds checks to the previous level. The checks at level 0 are very stable and provide hardly any false positives, while the checks at level 3 can be considered experimental.

For more information about the checks run at each level, see List of Checks in the Clazy documentation.

Running Valgrind Tools on External Applications ◦ Detecting Memory Leaks with Heob