clang-tidy
clang-tidy is a free, open-source Clang-based linter for C++ that diagnoses programming errors, style violations, interface misuse, and bugs detectable throu…
What clang-tidy is
clang-tidy is a free, open-source Clang-based linter for C++ that diagnoses programming errors, style violations, interface misuse, and bugs detectable through static analysis. Its checks cover bug-prone code, CERT secure coding, the C++ Core Guidelines, performance, portability, and readability; it can also run Clang Static Analyzer checks. Developers choose checks with the `-checks=` option, which accepts comma-separated positive and negative globs. The `-fix` flag applies corrections when the relevant checks support them. Settings can be stored in `.clang-tidy` files, including check selections, check-specific options, and custom checks based on Clang-Query syntax. clang-tidy uses LibTooling and works with a compilation database such as `compile_commands.json`, or compiler options supplied on the command line. Its `run-clang-tidy.py` script analyzes files concurrently. `clang-tidy-diff.py` filters displayed diagnostics to changed lines, but still analyzes whole files and may miss issues outside those lines. Developers can write custom checks using preprocessor callbacks or AST matchers. Integrations include clangd, CLion, KDevelop, Qt Creator, Visual Studio tools, Vim, and Emacs Flycheck.
Good
- Checks cover security, performance, portability, and readability.
- Applies supported automatic fixes.
- Supports custom checks and configuration files.
- Can analyze files concurrently.
Watch out
- Changed-line filtering still analyzes whole files.
- Diff filtering may miss issues outside changed lines.
- Some builds omit analyzer and MPI checks.
Who it suits
clang-tidy suits C++ developers who want configurable linting and static analysis in a build or editor workflow. It also supports teams creating custom checks or analyzing CUDA source.
Verdict
clang-tidy offers configurable C++ diagnostics, supported autofixes, and editor integrations. Its changed-line workflow limits displayed diagnostics rather than the scope of analysis, and analyzer checks depend on build configuration.
Plans and prices
From clang-tidy's own pricing page, checked 11 Oct 2001.
| Plan | Price | What it gives you |
|---|---|---|
| clang-tidy | Free | No paid plans or usage limits stated |
The facts
Each one read from clang-tidy's own pages, with the date it was checked.
What it does
- Automatic fixes
- The -fix option applies suggested fixes when supported by the corresponding checks.checked 11 Oct 2001
- Build integration
- clang-tidy can use a compile command database, which CMake can generate with CMAKE_EXPORT_COMPILE_COMMANDS=ON.checked 11 Oct 2001
- Build options
- If built with `CLANG_TIDY_ENABLE_STATIC_ANALYZER=NO`, clang-tidy does not include support for `clang-analyzer-*` or `mpi-*` checks.checked 11 Oct 2001
- Changed-line analysis
- `clang-tidy-diff.py` filters reported diagnostics to changed lines, but still analyzes the entire file and does not improve analysis performance.checked 11 Oct 2001
- Check categories
- Its check groups include bug-prone code, CERT guidelines, C++ Core Guidelines, performance, portability, and readability checks.checked 11 Oct 2001
- Checks
- It provides its own checks and can also run Clang Static Analyzer checks.checked 11 Oct 2001
- Check selection
- Checks can be selected with the `-checks=` option, which accepts comma-separated positive and negative globs.checked 11 Oct 2001
- clangd support
- The Clang team recommends clangd, which integrates clang-tidy and is available in major editors through plugins including Vim, Emacs, Visual Studio Code, and Sublime Text.checked 11 Oct 2001
- Configuration
- Checks can be selected with comma-separated positive and negative globs, and configuration can be read from a .clang-tidy file.checked 11 Oct 2001
- CUDA support
- clang-tidy supports CUDA source analysis, with the CUDA toolkit path specified using --cuda-path for correct header resolution.checked 11 Oct 2001
- Custom checks
- The tool provides an interface for writing custom checks, which can use preprocessor callbacks or AST matchers and attach fix-it hints to diagnostics.checked 11 Oct 2001
- Diff workflow
- clang-tidy-diff.py filters diagnostics to changed lines, but still analyzes the entire file and may miss issues reported outside those lines.checked 11 Oct 2001
- Extensible checks
- The tool is modular and provides a framework for writing new checks.checked 11 Oct 2001
- IDE/editor integrations
- The documentation links to a Clang-tidy IDE/Editor Integrations page.checked 11 Oct 2001
- IDE integrations
- The documentation lists integrations including clangd, CLion, KDevelop, Qt Creator, Visual Studio tools, Vim plugins, and Emacs Flycheck.checked 11 Oct 2001
- License
- The LLVM project states that its code is licensed under the Apache 2.0 License with LLVM exceptions.checked 11 Oct 2001
- Parallel analysis
- The included `run-clang-tidy.py` script runs analysis over files in a compilation database concurrently.checked 11 Oct 2001
- Parallel runs
- The included run-clang-tidy.py script runs analysis concurrently across files in a compilation database or specified path.checked 11 Oct 2001
- Project setup
- clang-tidy is based on LibTooling and works with a compilation database such as `compile_commands.json`; compiler options can also be supplied on the command line.checked 11 Oct 2001
- Purpose
- clang-tidy is a Clang-based C++ linter for diagnosing and fixing typical programming errors, including style violations, interface misuse, and bugs detectable by static analysis.checked 11 Oct 2001
- Security checks
- The documented check groups include CERT secure coding checks and Clang Static Analyzer checks, among other categories.checked 11 Oct 2001
- Static analysis
- clang-tidy includes its own checks and can also run Clang Static Analyzer checks.checked 11 Oct 2001
The company
- Maker
- LLVM describes itself as a collection of modular and reusable compiler and toolchain technologies, and identifies clang-tidy as an LLVM project tool.checked 11 Oct 2001
Alternatives to clang-tidy
- 1
Flake8
Free planOpen sourceAPILinuxmacOSSelf-hosted7.3Free plan - 2
PMD
Free planLinuxmacOSSelf-hostedWindows6.8Free plan - 3
SwiftLint
Free planLinuxmacOSWindows6.6Free plan - 4

Ruff
Free planWebLinuxmacOSSelf-hosted6.5Free plan - 5

Biome
Free planWebExtensionLinuxmacOS6.4Free plan - 6

Cppcheck
Free planLinuxmacOSSelf-hostedWindows6.4Free plan
