cppcheck

cppcheck-opensourceGPL-3.0活跃维护

C/C++ 静态代码分析工具,不用编译就能扫出内存泄漏、越界、未初始化变量等缺陷,适合接入 CI 做代码质量把关。

static analysis of C/C++ code

2.22.0发布于 2026-09-19 18:47 UTC6,792star1,607fork同步于 2026-11-10 05:33 UTC

怎么上手

从 README 代码块原样提取,可能是其中一种安装方式
pip install -r tools/donate-cpu-requirements.txt
硬件要求

README 没有说明硬件要求。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

这个项目的说明还在生成中,先参考下面「最近发版」和 README。

最近发版

5 个版本2.22.0
  1. 2.22.0cppcheck 2.22.0最新正式版2026-09-19 · 2026-09-19 18:47 UTC

    Release Notes for Cppcheck 2.22

    Major bug fixes & crashes:

    • Fixed a large number of fuzzer-found crashes and hangs in the tokenizer and template simplifier, e.g. TemplateSimplifier::expandTemplate() (bb630c244, 3f2d60c4b), Tokenizer::simplifyTypedef() (71de6753d, 3deb36d1f, 592e7b7c2), Tokenizer::simplifyUsing() (9162aa7fb, 7d5a54cc6), Tokenizer::findGarbageCode() (08db3048d) and ReverseTraversal::traverse() (3a3184de2, 5aa31d0da).
    • 6d2b6f4a5 Fix #14974 [regression] inline suppression does not work with build dir anymore.
    • 9a500c866 Fix #14972 [regression] Syntax Error: AST broken, '!' doesn't have an operand.

    New checks:

    • 0d7884dad Warn when feof() is used as a while loop condition (wrongfeofUsage).
    • 04091bd59 ftell() result is unspecified when file is opened in mode "t".
    • 3d88880e8 Detect when an STL algorithm such as std::copy, std::equal, std::transform, etc. accesses more elements through an iterator than are available in the container (algorithmOutOfBounds).
    • f695ade7f Detect switch cases that cannot be selected when the switch condition has a known value (unreachableSwitchCase).

    C/C++ support:

    • b878dc223 Support C++23 'if consteval' / 'if !consteval'.
    • 7a8c67ab4 Fix #15007 isAttributeNoreturn not set for _Noreturn.

    GUI:

    • f81f6f0e7 Fix #14829 Platform configuration mismatch between UI selection and analysis log.
    • 9f74c2db8 Fix #14813 crash: recheck in GUI sometimes crashes.
    • 550189be6 Fix #14738 GUI recheck of files not working properly when importing compile_commands.json.
    • 8f7666dd3 Fix #14983 GUI: exclude file with relative path.
    • 6640862c9 Fix #14933 each GUI log entry line should be output on a separate line.
    • 5799d47ee Removed GUI compliance report instructions (feature removed).

    Suppressions:

    • 93546a2bc XML suppression file: added macro attribute for specifying macro name.
    • fecb3496f Fix #14959 Warning hash for token-based warnings.
    • f6fff71c1 Fix #15013 Calculate warning hash for CTU warnings.
    • 0b5998407 Baseline functionality (script and documentation).
    • 637d5be67 Suppression file name cache. (performance)
    • c976cac0e ErrorLogger: do not open and read from files unless necessary (performance).

    Import project:

    • d32c01d1b Added support for Folders in slnx project files, skip non-C++ projects.
    • 9408a1d22 Added support for vcxproj ExcludedFromBuild.
    • bf099d1d1 Import project: handle forced include files from compilation database projects.
    • 3a9750e31 Flexible handling of -isystem, --sysroot and -I flags in compile_commands.json through the script tweak-compile_commands.py.

    Infrastructure & dependencies:

    • 4e62f0cca Fix #14614 Optionally provide comments in preprocessor output (BuildCache).
    • ff4d7ce36 Fix #14987 Update simplecpp to 1.9.1.

    Other:

    • 1fb66305f Added configuration file for Microsoft.GSL (Guideline Support Library).
    • 167f49dce, 5aec67c33, 767ace640 man/checkers: documented remaining checkers and fixed guideline classifications for MISRA C++.
  2. 2.21.0Cppcheck-2.21.02026-06-04 · 2026-06-04 11:36 UTC
    查看更新说明

    Release Notes for Cppcheck 2.21

    Major bug fixes & crashes:

    • Fixed potential crash with incomplete preprocessor directive
    • Fixed hang in createAst
    • Fixed invalid AST for braced initialization and references/pointers
    • Fixed cppcheckError with array typedef
    • Fixed recheck which now correctly excludes non selected files
    • Fixed potential crash when rechecking files in gui

    New checks:

    • MISRA C 2012 rule 10.3 now warns on assigning integer literals 0 and 1 to bool in C99 and later while preserving the existing C89 behavior.
    • funcArgNamesDifferentUnnamed warns on function declarations/definitions where a parameter in either location is unnamed
    • uninitMemberVarNoCtor warns on user-defined types where (1) some but not all members requiring initialization have in-class initializers or (2) there is a mixture of members which do/do not require initialization.
    • fcloseInLoopCondition warns when fclose() is used as a while loop condition, which may skip the loop body or double-close the file handle.

    C/C++ support:

    • import project: include path in compile_commands.json now handled correctly

    GUI:

    • Removed handling of Cppcheck Premium LOC license

    Other:

    • Make it possible to specify the regular expression engine using the engine element in a rule XML.
    • Added CLI option --exitcode-suppress to specify an error ID which should not result in a non-zero exitcode.
    • Moved source code from https://github.com/danmar/cppcheck to https://github.com/cppcheck-opensource/cppcheck
    • The official Windows binary is now built with Visual Studio 2026.
    • Updated simplecpp to 1.7.0.
  3. 2.20.0Cppcheck-2.20.02026-03-02 · 2026-03-02 17:42 UTC
    查看更新说明

    Release Notes for Cppcheck 2.20

    GUI:

    • Fix: The Misra C checkbox in "Edit Project" dialog is unchecked after reloading project.
    • Fix: In the Misra Report, use proper icons according to misra classifications
    • Fix: The platform files are not shown in the dropdown in ProjectFileDialog
    • Troubleshooting: detailed progress view that shows what files the threads are working on

    Changed interface:

    • removed CMake option "DISABLE_CRTDBG_MAP_ALLOC"
    • CMake option "BUILD_TESTS" has been deprecated and will be removed in Cppcheck 2.22 - use "BUILD_TESTING" instead

    Other:

    • The built-in "win*" and "unix*" platforms will now default to signed char type instead of unknown signedness. If you require unsigned chars please specify "--funsigned-char"
    • bumped minimum required CMake version to 3.22
    • Support inline polyspace suppressions
  4. 2.19.02025-12-21 · 2025-12-21 18:04 UTC
    查看更新说明

    Release Notes for Cppcheck 2.19

    Major bug fixes & crashes:

    • Crash in CheckClass::checkConst()
    • fuzzing crash (assert) in Token::update_property_info()
    • Crash in checkConstVariable()
    • Crash in valueFlowLifetimeClassConstructor()
    • GUI: scratch pad crash
    • Assert failure in getParentValueTypes()
    • Crash in simplecpp::Macro::expand()
    • crash in Tokenizer::simplifyCPPAttribute()

    New checks:

    • Detect zero initialization of unions in which its largest member is not declared as the first one. Depending on the compiler, there's no guarantee that the complete union will be zero initialized in such scenarios leading to potential access of uninitialized memory.
    • Added warning when main() throws an exception

    C/C++ support:

    • Fixed syntax error for C++23 lambda without parameter clause
    • Added support for typeof and __typeof operators

    GUI:

    • Fix bug: checks multiple configurations even though user provides defines

    Changed interface:

    • some preprocessorErrorDirective and syntaxError errors got more specific error IDs.
    • Removed deprecated platforms unix32-unsigned and unix64-unsigned
    • Improve progress value
    • Added float bits support in platform configuration
    • Fixed --showtime not accounting for addons

    Performance:

    • Introduced cache for followAllReferences() calls

    Infrastructure & dependencies:

    • Removed deprecated support for builds with Qt5.
    • Added make variables CXXOPTS and LDOPTS to extend existing CXXFLAGS and LDFLAGS.
    • Added make variables CPPOPTS to extend existing CPPFLAGS.
    • CPPFLAGS are not longer being passed to the linker command for cppcheck and testrunner.
    • Updated Qt to 6.10.0 (official Windows release only).
    • The official Windows binary is now built against Boost 1.89 for increased performance.
    • Updated to simplecpp 1.6.2
    • The Visual Studio builds not longer set the WIN32 define.
    • Added DISALLOW_PROCESS_EXECUTOR for building without fork().

    The changes focus heavily on stability (crash fixes), C/C++ compatibility, reducing false positives, and improving performance.

  5. 2.18.0Cppcheck-2.18.02025-07-20 · 2025-07-20 12:25 UTC
    查看更新说明

    Release Notes for Cppcheck 2.18

    Changed interface:

    • Updated path matching syntax for -i, --file-filter, suppressions, GUI excludes, and project file excludes. Old patterns that use a * may need to use ** instead if it is intended to match path separators. More details can be seen in the manual.

    Deprecations:

    • Support for building with Qt 5 will be removed in Cppcheck 2.19.
    • The platform 'unix32-unsigned' has been deprecated and will be removed in Cppcheck 2.19. Please use '--platform=unix32 --funsigned-char' instead.
    • The platform 'unix64-unsigned' has been deprecated and will be removed in Cppcheck 2.19. Please use '--platform=unix64 --funsigned-char' instead.

    Other:

    • Updated Qt to 6.9.1 (official Windows release only).
    • added CMake target run-clang-tidy-csa to run Clang Static Analyzer
    • added CMake option ENABLE_CSA_ALPHA to enable the Clang Static Analyzer alpha checkers
    • Updated TinyXML-2 to v11.0.0
    • The minimum supported Python version has been bumped to 3.7.
    • CMake will now unconditionally use Boost.Containers if available. If CMake option USE_BOOST is specified it will now bail out when it is not found.
    • Fix checking a project that contains several project file entries for the same file.
    • Fixed --file-filter matching of looked up files in provided paths.
    • Split up cstyleCast checker; dangerous casts produce portability/warning reports, safe casts produce style reports.
    • Removed deprecated '--showtime=' value 'top5'. Please use 'top5_file' or 'top5_summary' instead.

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Cppcheck

    NOTE: This repository was recently moved from https://github.com/danmar/cppcheck to https://github.com/cppcheck-opensource/cppcheck. Please make sure to update all your references to it accordingly.

    release-windowsOSS-FuzzCoverity Scan Build Statusinclude-what-you-useLicense
    release-windowsOSS-FuzzCoverity Scan Build Statusinclude-what-you-useLicense

    About the name

    The original name of this program was "C++check", but it was later changed to "Cppcheck".

    Despite the name, Cppcheck is designed for both C and C++.

    Manual

    A manual is available online.

    Donate CPU

    Cppcheck is a hobby project with limited resources. You can help us by donating CPU (1 core, which is the default, or as many as you like. Use the -j flag to use more cores). It is simple:

    1. Download (and extract) Cppcheck source code.

    2. Run (Linux/MacOS example):

      cd cppcheck/
      python3 -m venv .venv
      source .venv/bin/activate
      
      pip install -r tools/donate-cpu-requirements.txt
      ./tools/donate-cpu.py
      

    The script will analyse Debian source code and upload the results to a Cppcheck server. We need these results both to improve Cppcheck and to detect regressions.

    You can stop the script whenever you like with Ctrl+C.

    Compiling

    Cppcheck requires a C++ compiler with (partial) C++11 support. Minimum required versions are GCC 5.1 / Clang 3.5 / AppleClang 6.0 / Visual Studio 2015.

    To build the GUI application, you need to use the CMake build system.

    When building the command line tool, PCRE is optional. It is used if you build with rules.

    There are multiple compilation choices:

    • CMake - cross platform build tool
    • (Windows) Visual Studio
    • (Windows) Qt Creator + MinGW
    • GNU compilers - via make or directly

    The minimum required Python version is 3.7.

    CMake

    The minimum required version is CMake 3.22.

    Example, compiling Cppcheck with cmake:

    cmake -S . -B build
    cmake --build build
    

    If you want to compile the GUI you can use the flag. -DBUILD_GUI=ON

    For rules support (requires pcre) use the flag. -DHAVE_RULES=ON

    For release builds it is recommended that you use: -DUSE_MATCHCOMPILER=ON

    For building the tests use the flag. -DBUILD_TESTING=ON

    Using CMake you can generate project files for Visual Studio, XCode, etc.

    Building a specific configuration

    For single-configuration generators (like "Unix Makefiles") you can generate and build a specific configuration (e.g. "RelWithDebInfo") using:

    cmake -S . -B build_RelWithDebInfo -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
    cmake --build build_RelWithDebInfo --config RelWithDebInfo
    

    For multi-configuration generators (like "Visual Studio 17 2022") the same is achieved using:

    cmake -S . -B build
    cmake --build build --config RelWithDebInfo
    

    Visual Studio

    Use the cppcheck.sln file. The file is configured for Visual Studio 2019, but the platform toolset can be changed easily to older or newer versions. The solution contains platform targets for both x86 and x64.

    To compile with rules, select "Release-PCRE" or "Debug-PCRE" configuration. pcre.lib (pcre64.lib for x64 builds) and pcre.h are expected to be in /externals then. A current version of PCRE for Visual Studio can be obtained using vcpkg.

    Visual Studio (from command line)

    If you do not wish to use the Visual Studio IDE, you can compile Cppcheck from the command line the following command.

    msbuild cppcheck.sln
    

    VS Code

    Cppcheck Official is an extension officially supported by the cppcheck team allowing you to easily use cppcheck in VS Code. You can find it in VS Code Marketplace through the extension tab in your IDE. For instructions on how to set it up and use it, see the readme on the github page: https://github.com/cppchecksolutions/vscode-cppcheck-official

    Qt Creator + MinGW

    The PCRE dll is needed to build the CLI. It can be downloaded here: http://software-download.name/pcre-library-windows/

    GNU compilers

    GNU make

    Simple, unoptimized build (no dependencies):

    make
    

    You can use CXXOPTS, CPPOPTS and LDOPTS to append to the existing CXXFLAGS, CPPFLAGS and LDFLAGS instead of overriding them.

    The recommended release build is:

    make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes CXXOPTS="-O2" CPPOPTS="-DNDEBUG"
    
    g++ (for experts)

    If you just want to build Cppcheck without dependencies then you can use this command:

    g++ -o cppcheck -std=c++11 -Iexternals -Iexternals/simplecpp -Iexternals/tinyxml2 -Iexternals/picojson -Ilib -Ifrontend frontend/*.cpp cli/*.cpp lib/*.cpp externals/simplecpp/simplecpp.cpp externals/tinyxml2/tinyxml2.cpp
    
    Flags
    • MATCHCOMPILER=yes Several Token matching patterns are converted into more efficient C++ code at compile time (requires Python to be installed).

    • FILESDIR=/usr/share/cppcheck Specifies the folder where Cppcheck files (addons, cfg, platform) are installed to.

    • HAVE_RULES=yes Enables rules (requires PCRE to be installed).

    • CXXOPTS="-O2" Enables most compiler optimizations.

    • CPPOPTS="-DNDEBUG" Disables assertions.

    • HAVE_BOOST=yes Enables usage of more efficient container from Boost (requires Boost to be installed).

    MinGW

    mingw32-make
    

    If you encounter the following error with MATCHCOMPILER=yes you need to specify your Python interpreter via PYTHON_INTERPRETER.

    process_begin: CreateProcess(NULL, which python3, ...) failed.
    makefile:24: pipe: No error
    process_begin: CreateProcess(NULL, which python, ...) failed.
    makefile:27: pipe: No error
    makefile:30: *** Did not find a Python interpreter.  Stop.
    

    Other compiler/IDE

    1. Create an empty project file / makefile.
    2. Add all cpp files in the Cppcheck cli and lib folders to the project file / makefile.
    3. Add all cpp files in the externals folders to the project file / makefile.
    4. Compile.

    Cross compiling Win32 (CLI) version of Cppcheck in Linux

    sudo apt-get install mingw32
    make CXX=i586-mingw32msvc-g++ LDFLAGS="-lshlwapi" RDYNAMIC=""
    mv cppcheck cppcheck.exe
    

    Packages

    Besides building yourself on the platform of your choice there are also several ways to obtain pre-built packages.

    Official

    Official packages are maintained by the Cppcheck team.

    • (Windows) An official Windows installer is available via the official Cppcheck SourceForge page: https://cppcheck.sourceforge.io.
    • (Windows) Official builds of the current development versions are available via the release-windows workflow. They are built nightly for the main branch and for each commit for release branches. As these are development versions please refrain from using these in production environments!
      • A portable package (i.e. does not require installation) is available as the portable artifact. This is still a work-in-progress - see https://trac.cppcheck.net/ticket/10771 for details.
      • An installer is available via the installer artifact.
    • (Multi-Platform) A premium version with additional features provided by the original author of Cppcheck is available for purchase via https://www.cppcheck.com.

    Third-party

    Third-party packages are not maintained by the Cppcheck team but their respective packagers.

    Note: The following list is purely informational and listed in no particular order.

    Note: Please always try to obtain the package from the primary official source of your operating system/distro first and make sure you are getting the latest released/tagged version (see https://github.com/cppcheck-opensource/cppcheck/tags). Some packages might not carry the latest patch version though.

    Note: Some issues might be related to additional patches carried by the builds in these packages or by the packaging itself. Please try to verify the issue with an official build before reporting it upstream. Otherwise you might need toreport it to the respective maintainer of the package.

    Webpage

    https://cppcheck.sourceforge.io/