cppcheck
Static analysis tool for C/C++
TLDR
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--project=file
Use compile database (compile_commands.json) or Visual Studio project file--check-level=level
Check level: normal (default), exhaustive (deeper analysis), reduced (faster)--cppcheck-build-dir=dir
Build directory for faster rechecking and whole-program analysis--platform=type
Target platform: unix32, unix64, win32A, win32W, win64, native--template=format
Custom error message format (e.g., gcc, vs, {file}:{line}: {message})--max-configs=n
Maximum configurations to check per file (default: 12)-q, --quiet
Suppress progress output
CHECK TYPES
error: Bugs and undefined behaviorwarning: Defensive coding issuesstyle: Code style issuesperformance: Optimization suggestionsportability: 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)
