cppcheck
Static analysis tool for C/C++
TLDR
Check single file
SYNOPSIS
cppcheck [options] path...
DESCRIPTION
cppcheck performs static analysis on C/C++ source code to detect bugs, undefined behavior, and dangerous coding patterns without executing the program. It focuses on maintaining a low false positive rate, making warnings actionable and trustworthy.
The tool analyzes code for memory leaks, null pointer dereferences, buffer overflows, uninitialized variables, and many other issues. It supports C++11 through C++20 standards and can check both individual files and entire project directories.
Unlike compiler warnings, cppcheck performs deeper analysis including flow-sensitive checks and interprocedural analysis. It can detect issues that compilers typically miss while being faster and simpler to configure than comprehensive tools like Clang Static Analyzer.
PARAMETERS
--enable=checks
Enable checks: all, warning, style, performance, portability, information, unusedFunction--std=standard
C/C++ standard: c89, c99, c11, c++03, c++11, c++14, c++17, c++20-j n
Use n threads--xml
Output as XML--suppress=id
Suppress warning type--suppressions-list=file
Suppress from file-I dir
Include directory-D name
Define preprocessor symbol--force
Check all configurations--inconclusive
Report uncertain results-q, --quiet
Suppress progress output
CHECK TYPES
error: Bugs and undefined behavior
warning: Defensive coding issues
style: Code style issues
performance: Optimization suggestions
portability: Cross-platform issues
CAVEATS
Cannot analyze included headers without proper include paths. Use with clang-tidy for comprehensive analysis.
SEE ALSO
clang-tidy(1), cpplint(1), gcc(1)
