LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

clang-tidy

Clang-based C++ linter and static analyzer

TLDR

Run checks on file
$ clang-tidy [file.cpp] -- -I[include/path]
copy
List enabled checks
$ clang-tidy --list-checks
copy
List all available checks
$ clang-tidy --list-checks -checks='*'
copy
Run specific checks
$ clang-tidy -checks='-*,modernize-*' [file.cpp]
copy
Apply automatic fixes
$ clang-tidy --fix [file.cpp]
copy
Export fixes to file
$ clang-tidy --export-fixes=[fixes.yaml] [file.cpp]
copy
Dump configuration
$ clang-tidy --dump-config
copy

SYNOPSIS

clang-tidy [options] file [-- compileoptions_]

DESCRIPTION

clang-tidy is a clang-based C++ linter tool for diagnosing and fixing typical programming errors including style violations, interface misuse, and bugs detectable via static analysis. It is part of the LLVM/Clang extra tools.The tool provides hundreds of checks organized into categories such as bugprone, modernize, performance, readability, and cppcoreguidelines. Many checks can automatically apply fixes to source code, making it useful for large-scale code modernization (e.g., migrating to modern C++ idioms).clang-tidy uses a .clang-tidy configuration file for project-level settings and supports inline suppression with NOLINT comments. For large projects, run-clang-tidy.py provides parallel execution across multiple files.

PARAMETERS

-checks=list

Comma-separated list of checks (+/- prefixed globs)
--list-checks
List enabled checks
--fix
Apply suggested fixes
--fix-errors
Apply fixes even if errors occur
--export-fixes=file
Write fixes to YAML file
--dump-config
Dump configuration to stdout
--warnings-as-errors=list
Treat specified warnings as errors
-p path
Path to compilation database
--config-file=file
Path to .clang-tidy config
--format-style=style
Format style for applied fixes (none, file, llvm, google, webkit, mozilla)
--extra-arg=arg
Additional argument to append to the compiler command line
--fix-notes
Apply fixes from diagnostic notes (implies --fix)
--allow-no-checks
Allow empty enabled checks without error

CONFIGURATION

Create .clang-tidy in project root:

$ Checks: '-*,modernize-*,bugprone-*'
WarningsAsErrors: '*'
copy

CHECK CATEGORIES

bugprone-*

Bug-prone patterns
modernize-*
C++ modernization
performance-*
Performance issues
readability-*
Code readability
cppcoreguidelines-*
C++ Core Guidelines
clang-analyzer-*
Clang Static Analyzer checks
misc-*
Miscellaneous checks
cert-*
CERT secure coding standard

SUPPRESSION

Use comments: NOLINT, NOLINTNEXTLINE, NOLINTBEGIN/NOLINTEND

CAVEATS

Requires compilation database for complex projects. Use run-clang-tidy.py for parallel execution.

SEE ALSO

Copied to clipboard
Kai