From 3a4850cefdb2b5e00bdedaec8be3b7aa933596d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 2 Mar 2026 14:05:57 +0100 Subject: [PATCH 001/168] releasenotes.txt: clear notes (#8289) --- releasenotes.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/releasenotes.txt b/releasenotes.txt index fe530b2121e..f80ee8dc42d 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -1,5 +1,5 @@ -Release Notes for Cppcheck 2.20 +Release Notes for Cppcheck 2.21 Major bug fixes & crashes: - @@ -14,14 +14,10 @@ GUI: - 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 - Infrastructure & dependencies: - 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 - From b672d762eb3c0340c188e1ca2f0608274b860d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Mon, 2 Mar 2026 19:02:10 +0100 Subject: [PATCH 002/168] removed unnecessary CMake generator parameters from CI (#8286) --- .github/workflows/CI-unixish-docker.yml | 2 +- .github/workflows/CI-unixish.yml | 40 ++++++++++++------------- .github/workflows/clang-tidy.yml | 2 +- .github/workflows/iwyu.yml | 4 +-- .github/workflows/selfcheck.yml | 12 ++++---- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/.github/workflows/CI-unixish-docker.yml b/.github/workflows/CI-unixish-docker.yml index e254c1e986f..083bb7b7651 100644 --- a/.github/workflows/CI-unixish-docker.yml +++ b/.github/workflows/CI-unixish-docker.yml @@ -57,7 +57,7 @@ jobs: - name: Run CMake run: | - cmake -S . -B cmake.output -Werror=dev -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + cmake -S . -B cmake.output -Werror=dev -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - name: CMake build (with GUI) run: | diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index fabe0832f4b..8f355644bc2 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -58,13 +58,13 @@ jobs: - name: CMake build on ubuntu (with GUI / system tinyxml2) if: contains(matrix.os, 'ubuntu') run: | - cmake -S . -B cmake.output.tinyxml2 -Werror=dev -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DUSE_BUNDLED_TINYXML2=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + cmake -S . -B cmake.output.tinyxml2 -Werror=dev -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DUSE_BUNDLED_TINYXML2=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache cmake --build cmake.output.tinyxml2 -- -j$(nproc) - name: CMake build on macos (with GUI / system tinyxml2) if: contains(matrix.os, 'macos') run: | - cmake -S . -B cmake.output.tinyxml2 -Werror=dev -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DUSE_BUNDLED_TINYXML2=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DQt6_DIR=$(brew --prefix qt@6)/lib/cmake/Qt6 + cmake -S . -B cmake.output.tinyxml2 -Werror=dev -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DUSE_BUNDLED_TINYXML2=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DQt6_DIR=$(brew --prefix qt@6)/lib/cmake/Qt6 cmake --build cmake.output.tinyxml2 -- -j$(nproc) - name: Run CMake test (system tinyxml2) @@ -127,12 +127,12 @@ jobs: - name: Run CMake on ubuntu (with GUI) if: contains(matrix.os, 'ubuntu') run: | - cmake -S . -B cmake.output -Werror=dev -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_INSTALL_PREFIX=cppcheck-cmake-install + cmake -S . -B cmake.output -Werror=dev -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_INSTALL_PREFIX=cppcheck-cmake-install - name: Run CMake on macos (with GUI) if: contains(matrix.os, 'macos') run: | - cmake -S . -B cmake.output -Werror=dev -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_INSTALL_PREFIX=cppcheck-cmake-install -DQt6_DIR=$(brew --prefix qt@6)/lib/cmake/Qt6 + cmake -S . -B cmake.output -Werror=dev -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_INSTALL_PREFIX=cppcheck-cmake-install -DQt6_DIR=$(brew --prefix qt@6)/lib/cmake/Qt6 - name: Run CMake build run: | @@ -154,13 +154,13 @@ jobs: - name: Run CMake on ubuntu (no CLI) if: matrix.os == 'ubuntu-22.04' run: | - cmake -S . -B cmake.output_nocli -Werror=dev -G "Unix Makefiles" -DBUILD_TESTING=Off -DBUILD_CLI=Off + cmake -S . -B cmake.output_nocli -Werror=dev -DBUILD_TESTING=Off -DBUILD_CLI=Off - name: Run CMake on ubuntu (no CLI / with tests) if: matrix.os == 'ubuntu-22.04' run: | # the test and CLI code are too intertwined so for now we need to reject that - if cmake -S . -B cmake.output_nocli_tests -Werror=dev -G "Unix Makefiles" -DBUILD_TESTING=On -DBUILD_CLI=Off; then + if cmake -S . -B cmake.output_nocli_tests -Werror=dev -DBUILD_TESTING=On -DBUILD_CLI=Off; then exit 1 else exit 0 @@ -169,18 +169,18 @@ jobs: - name: Run CMake on ubuntu (no CLI / with GUI) if: matrix.os == 'ubuntu-22.04' run: | - cmake -S . -B cmake.output_nocli_gui -Werror=dev -G "Unix Makefiles" -DBUILD_TESTING=Off -DBUILD_CLI=Off -DBUILD_GUI=On + cmake -S . -B cmake.output_nocli_gui -Werror=dev -DBUILD_TESTING=Off -DBUILD_CLI=Off -DBUILD_GUI=On - name: Run CMake on ubuntu (no GUI) if: matrix.os == 'ubuntu-22.04' run: | - cmake -S . -B cmake.output_nogui -Werror=dev -G "Unix Makefiles" -DBUILD_TESTING=Off -DBUILD_GUI=Off + cmake -S . -B cmake.output_nogui -Werror=dev -DBUILD_TESTING=Off -DBUILD_GUI=Off - name: Run CMake on ubuntu (no GUI / with triage) if: matrix.os == 'ubuntu-22.04' run: | # cannot build triage without GUI - if cmake -S . -B cmake.output_nogui_triage -Werror=dev -G "Unix Makefiles" -DBUILD_TESTING=Off -DBUILD_GUI=Off -DBUILD_TRIAGE=On; then + if cmake -S . -B cmake.output_nogui_triage -Werror=dev -DBUILD_TESTING=Off -DBUILD_GUI=Off -DBUILD_TRIAGE=On; then exit 1 else exit 0 @@ -189,7 +189,7 @@ jobs: - name: Run CMake on ubuntu (no CLI / no GUI) if: matrix.os == 'ubuntu-22.04' run: | - cmake -S . -B cmake.output_nocli_nogui -Werror=dev -G "Unix Makefiles" -DBUILD_TESTING=Off -DBUILD_GUI=Off + cmake -S . -B cmake.output_nocli_nogui -Werror=dev -DBUILD_TESTING=Off -DBUILD_GUI=Off build_cmake_cxxstd: @@ -243,12 +243,12 @@ jobs: - name: Run CMake on ubuntu (with GUI) if: contains(matrix.os, 'ubuntu') run: | - cmake -S . -B cmake.output -Werror=dev -G "Unix Makefiles" -DCMAKE_CXX_STANDARD=${{ matrix.cxxstd }} -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + cmake -S . -B cmake.output -Werror=dev -DCMAKE_CXX_STANDARD=${{ matrix.cxxstd }} -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - name: Run CMake on macos (with GUI) if: contains(matrix.os, 'macos') run: | - cmake -S . -B cmake.output -Werror=dev -G "Unix Makefiles" -DCMAKE_CXX_STANDARD=${{ matrix.cxxstd }} -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DQt6_DIR=$(brew --prefix qt@6)/lib/cmake/Qt6 + cmake -S . -B cmake.output -Werror=dev -DCMAKE_CXX_STANDARD=${{ matrix.cxxstd }} -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DQt6_DIR=$(brew --prefix qt@6)/lib/cmake/Qt6 - name: Run CMake build run: | @@ -373,7 +373,7 @@ jobs: run: | # make sure we fail when Boost is requested and not available. # will fail because no package configuration is available. - if cmake -S . -B cmake.output.boost-force-noavail -Werror=dev -G "Unix Makefiles" -DBUILD_TESTING=Off -DUSE_BOOST=On; then + if cmake -S . -B cmake.output.boost-force-noavail -Werror=dev -DBUILD_TESTING=Off -DUSE_BOOST=On; then exit 1 else exit 0 @@ -386,12 +386,12 @@ jobs: - name: Run CMake on macOS (force Boost) run: | - cmake -S . -B cmake.output.boost-force -Werror=dev -G "Unix Makefiles" -DBUILD_TESTING=Off -DUSE_BOOST=On + cmake -S . -B cmake.output.boost-force -Werror=dev -DBUILD_TESTING=Off -DUSE_BOOST=On - name: Run CMake on macOS (no Boost) run: | # make sure Boost is not used when disabled even though it is available - cmake -S . -B cmake.output.boost-no -Werror=dev -G "Unix Makefiles" -DBUILD_TESTING=Off -DUSE_BOOST=Off + cmake -S . -B cmake.output.boost-no -Werror=dev -DBUILD_TESTING=Off -DUSE_BOOST=Off if grep -q '\-DHAVE_BOOST' ./cmake.output.boost-no/compile_commands.json; then exit 1 else @@ -400,7 +400,7 @@ jobs: - name: Run CMake on macOS (with Boost) run: | - cmake -S . -B cmake.output.boost -Werror=dev -G "Unix Makefiles" -DBUILD_TESTING=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + cmake -S . -B cmake.output.boost -Werror=dev -DBUILD_TESTING=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache grep -q '\-DHAVE_BOOST' ./cmake.output.boost/compile_commands.json - name: Build with CMake on macOS (with Boost) @@ -436,12 +436,12 @@ jobs: - name: Run CMake (without GUI) run: | export PATH=cmake-${{ env.CMAKE_VERSION_FULL }}-linux-x86_64/bin:$PATH - cmake -S . -B cmake.output -Werror=dev -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTING=On + cmake -S . -B cmake.output -Werror=dev -DHAVE_RULES=On -DBUILD_TESTING=On - name: Run CMake (with GUI) run: | export PATH=cmake-${{ env.CMAKE_VERSION_FULL }}-linux-x86_64/bin:$PATH - cmake -S . -B cmake.output.gui -Werror=dev -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On + cmake -S . -B cmake.output.gui -Werror=dev -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On build: @@ -596,7 +596,7 @@ jobs: - name: Test Signalhandler run: | - cmake -S . -B build.cmake.signal -Werror=dev -G "Unix Makefiles" -DBUILD_TESTING=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On + cmake -S . -B build.cmake.signal -Werror=dev -DBUILD_TESTING=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On cmake --build build.cmake.signal --target test-signalhandler -- -j$(nproc) # TODO: how to run this without copying the file? cp build.cmake.signal/bin/test-s* . @@ -607,7 +607,7 @@ jobs: - name: Test Stacktrace if: contains(matrix.os, 'ubuntu') run: | - cmake -S . -B build.cmake.stack -Werror=dev -G "Unix Makefiles" -DBUILD_TESTING=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On + cmake -S . -B build.cmake.stack -Werror=dev -DBUILD_TESTING=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On cmake --build build.cmake.stack --target test-stacktrace -- -j$(nproc) # TODO: how to run this without copying the file? cp build.cmake.stack/bin/test-s* . diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 540e5770382..c4f8cc0cf6b 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -61,7 +61,7 @@ jobs: - name: Prepare CMake run: | - cmake -S . -B cmake.output -Werror=dev -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_COMPILE_WARNING_AS_ERROR=On + cmake -S . -B cmake.output -Werror=dev -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_COMPILE_WARNING_AS_ERROR=On env: CC: clang-22 CXX: clang++-22 diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml index 9ac43313671..fa9be0cbba8 100644 --- a/.github/workflows/iwyu.yml +++ b/.github/workflows/iwyu.yml @@ -128,7 +128,7 @@ jobs: - name: Prepare CMake run: | - cmake -S . -B cmake.output -Werror=dev -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCPPCHK_GLIBCXX_DEBUG=Off -DUSE_MATCHCOMPILER=Off -DEXTERNALS_AS_SYSTEM=On -DUSE_LIBCXX=${{ matrix.stdlib == 'libc++' }} + cmake -S . -B cmake.output -Werror=dev -DCMAKE_BUILD_TYPE=Release -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCPPCHK_GLIBCXX_DEBUG=Off -DUSE_MATCHCOMPILER=Off -DEXTERNALS_AS_SYSTEM=On -DUSE_LIBCXX=${{ matrix.stdlib == 'libc++' }} env: CC: clang CXX: clang++ @@ -236,7 +236,7 @@ jobs: - name: Prepare CMake run: | - cmake -S . -B cmake.output -Werror=dev -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCPPCHK_GLIBCXX_DEBUG=Off -DUSE_MATCHCOMPILER=Off -DEXTERNALS_AS_SYSTEM=On -DUSE_LIBCXX=${{ matrix.use_libcxx }} + cmake -S . -B cmake.output -Werror=dev -DCMAKE_BUILD_TYPE=Release -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCPPCHK_GLIBCXX_DEBUG=Off -DUSE_MATCHCOMPILER=Off -DEXTERNALS_AS_SYSTEM=On -DUSE_LIBCXX=${{ matrix.use_libcxx }} env: CC: clang-22 CXX: clang++-22 diff --git a/.github/workflows/selfcheck.yml b/.github/workflows/selfcheck.yml index aa5b61d859b..ec52b15f939 100644 --- a/.github/workflows/selfcheck.yml +++ b/.github/workflows/selfcheck.yml @@ -64,7 +64,7 @@ jobs: # unusedFunction - start - name: CMake run: | - cmake -S . -B cmake.output -Werror=dev -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=ON -DWITH_QCHART=ON -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCPPCHK_GLIBCXX_DEBUG=Off + cmake -S . -B cmake.output -Werror=dev -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=ON -DWITH_QCHART=ON -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCPPCHK_GLIBCXX_DEBUG=Off - name: Generate dependencies run: | @@ -90,7 +90,7 @@ jobs: # unusedFunction notest - start - name: CMake (no test) run: | - cmake -S . -B cmake.output.notest -Werror=dev -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTING=Off -DBUILD_GUI=ON -DBUILD_TRIAGE=On -DWITH_QCHART=ON -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCPPCHK_GLIBCXX_DEBUG=Off + cmake -S . -B cmake.output.notest -Werror=dev -DHAVE_RULES=On -DBUILD_TESTING=Off -DBUILD_GUI=ON -DBUILD_TRIAGE=On -DWITH_QCHART=ON -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCPPCHK_GLIBCXX_DEBUG=Off - name: Generate dependencies (no test) run: | @@ -112,7 +112,7 @@ jobs: # unusedFunction notest nogui - start - name: CMake (no test / no gui) run: | - cmake -S . -B cmake.output.notest_nogui -Werror=dev -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTING=Off -DENABLE_CHECK_INTERNAL=On -DCPPCHK_GLIBCXX_DEBUG=Off + cmake -S . -B cmake.output.notest_nogui -Werror=dev -DHAVE_RULES=On -DBUILD_TESTING=Off -DENABLE_CHECK_INTERNAL=On -DCPPCHK_GLIBCXX_DEBUG=Off - name: Generate dependencies (no test / no gui) run: | @@ -131,7 +131,7 @@ jobs: # unusedFunction notest nocli - start - name: CMake (no test / no cli) run: | - cmake -S . -B cmake.output.notest_nocli -Werror=dev -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTING=Off -DBUILD_CLI=Off -DBUILD_GUI=ON -DWITH_QCHART=ON -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCPPCHK_GLIBCXX_DEBUG=Off + cmake -S . -B cmake.output.notest_nocli -Werror=dev -DHAVE_RULES=On -DBUILD_TESTING=Off -DBUILD_CLI=Off -DBUILD_GUI=ON -DWITH_QCHART=ON -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCPPCHK_GLIBCXX_DEBUG=Off - name: Generate dependencies (no test / no cli) run: | @@ -154,7 +154,7 @@ jobs: # unusedFunction notest nocli nogui - start - name: CMake (no test / no cli / no gui) run: | - cmake -S . -B cmake.output.notest_nocli_nogui -Werror=dev -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTING=Off -DBUILD_CLI=Off -DBUILD_GUI=Off -DENABLE_CHECK_INTERNAL=On -DCPPCHK_GLIBCXX_DEBUG=Off + cmake -S . -B cmake.output.notest_nocli_nogui -Werror=dev -DHAVE_RULES=On -DBUILD_TESTING=Off -DBUILD_CLI=Off -DBUILD_GUI=Off -DENABLE_CHECK_INTERNAL=On -DCPPCHK_GLIBCXX_DEBUG=Off - name: Generate dependencies (no test / no cli / no gui) run: | @@ -177,7 +177,7 @@ jobs: - name: CMake (corpus / no test) run: | - cmake -S cppcheck-2.8 -B cmake.output.corpus -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTING=Off -DBUILD_GUI=ON -DUSE_QT6=On -DWITH_QCHART=ON -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_POLICY_VERSION_MINIMUM=3.5 + cmake -S cppcheck-2.8 -B cmake.output.corpus -DHAVE_RULES=On -DBUILD_TESTING=Off -DBUILD_GUI=ON -DUSE_QT6=On -DWITH_QCHART=ON -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_POLICY_VERSION_MINIMUM=3.5 - name: Generate dependencies (corpus) run: | From 0c3d74f449a4ccf2ff89aa616513cedaceea892a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 2 Mar 2026 20:17:23 +0100 Subject: [PATCH 003/168] daca@home: update OLD_VERSION and SERVER_VERSION [skip ci] (#8294) --- tools/donate-cpu-server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/donate-cpu-server.py b/tools/donate-cpu-server.py index d8afaba2be3..6f44ea679a7 100755 --- a/tools/donate-cpu-server.py +++ b/tools/donate-cpu-server.py @@ -26,10 +26,10 @@ # Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/ # Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic # changes) -SERVER_VERSION = "1.3.67" +SERVER_VERSION = "1.3.68" # TODO: fetch from GitHub tags -OLD_VERSION = '2.19.0' +OLD_VERSION = '2.20.0' HEAD_MARKER = 'head results:' INFO_MARKER = 'info messages:' From da110ba0b12cf20fcf712865c2f4686ceca02c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Tue, 3 Mar 2026 15:59:56 +0100 Subject: [PATCH 004/168] bumped version to 2.20.99/2.21 (#8293) --- CMakeLists.txt | 2 +- cli/main.cpp | 2 +- lib/version.h | 4 ++-- man/manual.md | 2 +- man/reference-cfg-format.md | 2 +- man/writing-addons.md | 2 +- win_installer/productInfo.wxi | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e41d81029ae..b32fc90811b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.22) -project(Cppcheck VERSION 2.18.99 LANGUAGES CXX) +project(Cppcheck VERSION 2.20.99 LANGUAGES CXX) include(cmake/options.cmake) diff --git a/cli/main.cpp b/cli/main.cpp index 1c39ab14544..9bea4336c84 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -20,7 +20,7 @@ /** * * @mainpage Cppcheck - * @version 2.18.99 + * @version 2.20.99 * * @section overview_sec Overview * Cppcheck is a simple tool for static analysis of C/C++ code. diff --git a/lib/version.h b/lib/version.h index 4828a568104..2a64885ffa8 100644 --- a/lib/version.h +++ b/lib/version.h @@ -20,8 +20,8 @@ #ifndef versionH #define versionH -#define CPPCHECK_VERSION_STRING "2.19 dev" -#define CPPCHECK_VERSION 2,18,99,0 +#define CPPCHECK_VERSION_STRING "2.21 dev" +#define CPPCHECK_VERSION 2,20,99,0 #define LEGALCOPYRIGHT L"Copyright (C) 2007-2026 Cppcheck team." diff --git a/man/manual.md b/man/manual.md index 1a4e4002f10..dc07026dc2b 100644 --- a/man/manual.md +++ b/man/manual.md @@ -1,6 +1,6 @@ --- title: Cppcheck manual -subtitle: Version 2.19 dev +subtitle: Version 2.21 dev author: Cppcheck team lang: en documentclass: report diff --git a/man/reference-cfg-format.md b/man/reference-cfg-format.md index 7a9e3b6dee7..3067d0a8f2c 100644 --- a/man/reference-cfg-format.md +++ b/man/reference-cfg-format.md @@ -1,6 +1,6 @@ --- title: Cppcheck .cfg format -subtitle: Version 2.19 dev +subtitle: Version 2.21 dev author: Cppcheck team lang: en documentclass: report diff --git a/man/writing-addons.md b/man/writing-addons.md index da21ea513ad..e593c2e9cce 100644 --- a/man/writing-addons.md +++ b/man/writing-addons.md @@ -1,6 +1,6 @@ --- title: Writing addons -subtitle: Version 2.19 dev +subtitle: Version 2.21 dev author: Cppcheck team lang: en documentclass: report diff --git a/win_installer/productInfo.wxi b/win_installer/productInfo.wxi index d07ce1136c9..f89e956dbb8 100644 --- a/win_installer/productInfo.wxi +++ b/win_installer/productInfo.wxi @@ -1,8 +1,8 @@ - + - + From 0e0f9de835b394532edb2f54e4af84ee9b144cd8 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 4 Mar 2026 12:39:34 +0100 Subject: [PATCH 005/168] Refs #13771, #13776: No AST for function declarations (#8222) Co-authored-by: chrchr-github --- lib/symboldatabase.cpp | 2 +- lib/tokenlist.cpp | 7 ++++--- test/testtokenize.cpp | 31 +++++++++++++++++++++++-------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 4dc75ba8c1f..3bde7a71e19 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -713,7 +713,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() } // function prototype? else if (declEnd && declEnd->str() == ";") { - if (tok->astParent() && tok->astParent()->str() == "::" && + if ((Token::simpleMatch(tok->tokAt(-1), "::") || (tok->tokAt(-1) && Token::simpleMatch(tok->tokAt(-2), ":: ~"))) && Token::Match(declEnd->previous(), "default|delete")) { addClassFunction(scope, tok, argStart); continue; diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index d5b48ceab22..0ffcf7e37e4 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1787,8 +1787,9 @@ static Token * createAstAtToken(Token *tok) } } - if (Token::Match(tok, "%type% %name%|*|&|&&|::") && !Token::Match(tok, "return|new|delete")) { - int typecount = 0; + if ((Token::Match(tok, "%type% %name%|*|&|&&|::") && !Token::Match(tok, "return|new|delete")) || + (Token::Match(tok, ":: %type%") && !tok->next()->isKeyword())) { + int typecount = tok->str() == "::" ? 1 : 0; Token *typetok = tok; while (Token::Match(typetok, "%type%|::|*|&|&&|<")) { if (typetok->isName() && !Token::simpleMatch(typetok->previous(), "::")) @@ -1811,7 +1812,7 @@ static Token * createAstAtToken(Token *tok) !Token::Match(tok, "return|throw") && Token::Match(typetok->previous(), "%name% ( !!*") && typetok->previous()->varId() == 0 && - !typetok->previous()->isKeyword() && + (!typetok->previous()->isKeyword() || typetok->previous()->isOperatorKeyword()) && (skipMethodDeclEnding(typetok->link()) || Token::Match(typetok->link(), ") ;|{"))) return typetok; } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index a698a3c20bf..e59f7b3be62 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -427,6 +427,7 @@ class TestTokenizer : public TestFixture { TEST_CASE(astorkeyword); TEST_CASE(astenumdecl); TEST_CASE(astcompound); + TEST_CASE(astfuncdecl); TEST_CASE(startOfExecutableScope); @@ -6415,8 +6416,13 @@ class TestTokenizer : public TestFixture { Z3 }; + enum class ListSimplification : std::uint8_t { + Partial, + Full + }; + template - std::string testAst(const char (&data)[size], AstStyle style = AstStyle::Simple) { + std::string testAst(const char (&data)[size], AstStyle style = AstStyle::Simple, ListSimplification ls = ListSimplification::Partial) { // tokenize given code.. TokenList tokenlist{settings0, Standards::Language::CPP}; tokenlist.appendFileIfNew("test.cpp"); @@ -6424,13 +6430,17 @@ class TestTokenizer : public TestFixture { return "ERROR"; TokenizerTest tokenizer(std::move(tokenlist), *this); - tokenizer.combineStringAndCharLiterals(); - tokenizer.combineOperators(); - tokenizer.simplifySpaceshipOperator(); - tokenizer.createLinks(); - tokenizer.createLinks2(); - tokenizer.simplifyCAlternativeTokens(); - tokenizer.list.front()->assignIndexes(); + if (ls == ListSimplification::Partial) { + tokenizer.combineStringAndCharLiterals(); + tokenizer.combineOperators(); + tokenizer.simplifySpaceshipOperator(); + tokenizer.createLinks(); + tokenizer.createLinks2(); + tokenizer.simplifyCAlternativeTokens(); + tokenizer.list.front()->assignIndexes(); + } else { // Full + tokenizer.simplifyTokens1(""); + } // set varid.. for (Token *tok = tokenizer.list.front(); tok; tok = tok->next()) { @@ -7428,6 +7438,11 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("s(sstrlens(0:?,{(return", testAst("return (struct Str) { (unsigned char*)s, s ? strlen(s) : 0 };")); } + void astfuncdecl() { + ASSERT_EQUALS("", testAst("bool operator==(const S& a, const S& b);", AstStyle::Simple, ListSimplification::Full)); + ASSERT_EQUALS("", testAst("::int32_t f();")); + } + #define isStartOfExecutableScope(offset, code) isStartOfExecutableScope_(offset, code, __FILE__, __LINE__) template bool isStartOfExecutableScope_(int offset, const char (&code)[size], const char* file, int line) { From 2dac535684fd2c05d39905e7ed113e69787601c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Wed, 4 Mar 2026 13:38:17 +0100 Subject: [PATCH 006/168] Fix #14478: FN autoVariables for array of structs (#8247) --- lib/checkautovariables.cpp | 12 +++++++++--- test/testautovariables.cpp | 10 ++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index d867930f517..387e3fd3c2d 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -265,11 +265,17 @@ static bool hasOverloadedAssignment(const Token* tok, bool& inconclusive) static bool isMemberAssignment(const Token* tok, const Token*& rhs, const Settings& settings) { - if (!Token::Match(tok, "[;{}] %var% . %var%")) - return false; + const Token *endBracket = nullptr; + if (!Token::Match(tok, "[;{}] %var% . %var%")) { + if (!Token::Match(tok, "[;{}] %var% [")) + return false; + endBracket = tok->linkAt(2); + if (!Token::Match(endBracket, "] . %var%")) + return false; + } if (!isPtrArg(tok->next())) return false; - const Token* assign = tok->tokAt(2)->astParent(); + const Token* assign = (endBracket ? endBracket->next() : tok->tokAt(2))->astParent(); while (Token::simpleMatch(assign, "[")) assign = assign->astParent(); if (!Token::simpleMatch(assign, "=")) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 560220f8c9e..bcdba7ca0dc 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -69,6 +69,7 @@ class TestAutoVariables : public TestFixture { TEST_CASE(testautovar15); // ticket #6538 TEST_CASE(testautovar16); // ticket #8114 TEST_CASE(testautovar17); + TEST_CASE(testautovar18); TEST_CASE(testautovar_array1); TEST_CASE(testautovar_array2); TEST_CASE(testautovar_array3); @@ -516,6 +517,15 @@ class TestAutoVariables : public TestFixture { ASSERT_EQUALS("", errout_str()); } + void testautovar18() { + check("struct S { int* p; };\n" + "void foo(struct S* s) {\n" + " int x;\n" + " s[2].p = &x;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); + } + void testautovar_array1() { check("void func1(int* arr[2])\n" "{\n" From 6a14618aa9a418bebe7b9a2d32a0cbf739099f8d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 9 Mar 2026 21:04:50 +0100 Subject: [PATCH 007/168] Workaround for broken apt.llvm.org repo (revert to clang 21) (#8312) Co-authored-by: chrchr-github --- .clang-tidy | 7 ++----- .github/workflows/asan.yml | 6 +++--- .github/workflows/clang-tidy.yml | 10 +++++----- .github/workflows/tsan.yml | 6 +++--- .github/workflows/ubsan.yml | 6 +++--- cmake/clang_tidy.cmake | 3 --- 6 files changed, 16 insertions(+), 22 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 8c30f2c602b..91173d82e10 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -23,14 +23,12 @@ Checks: > google-explicit-constructor, -bugprone-assignment-in-if-condition, -bugprone-branch-clone, - -bugprone-command-processor, -bugprone-easily-swappable-parameters, -bugprone-empty-catch, -bugprone-macro-parentheses, -bugprone-narrowing-conversions, -bugprone-signed-char-misuse, -bugprone-switch-missing-default-case, - -bugprone-throwing-static-initialization, -bugprone-unchecked-optional-access, -clang-analyzer-*, -concurrency-mt-unsafe, @@ -39,6 +37,7 @@ Checks: > -misc-non-private-member-variables-in-classes, -misc-throw-by-value-catch-by-reference, -misc-use-anonymous-namespace, + -misc-use-internal-linkage, -modernize-avoid-c-arrays, -modernize-deprecated-ios-base-aliases, -misc-include-cleaner, @@ -70,7 +69,7 @@ Checks: > -readability-implicit-bool-conversion, -readability-isolate-declaration, -readability-magic-numbers, - -readability-redundant-parentheses, + -readability-math-missing-parentheses, -readability-suspicious-call-argument, -readability-uppercase-literal-suffix, -readability-use-concise-preprocessor-directives, @@ -85,5 +84,3 @@ CheckOptions: value: '0' - key: modernize-use-trailing-return-type.TransformFunctions value: false - - key: misc-override-with-different-visibility.DisallowedVisibilityChange - value: widening diff --git a/.github/workflows/asan.yml b/.github/workflows/asan.yml index 38e90cb760a..977d3f05337 100644 --- a/.github/workflows/asan.yml +++ b/.github/workflows/asan.yml @@ -54,7 +54,7 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 22 + sudo ./llvm.sh 21 - name: Install Qt ${{ env.QT_VERSION }} uses: jurplel/install-qt-action@v4 @@ -76,8 +76,8 @@ jobs: run: | cmake -S . -B cmake.output -Werror=dev -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DUSE_MATCHCOMPILER=Verify -DANALYZE_ADDRESS=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DFILESDIR= -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache env: - CC: clang-22 - CXX: clang++-22 + CC: clang-21 + CXX: clang++-21 - name: Build cppcheck run: | diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index c4f8cc0cf6b..00a4ee7d332 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -43,8 +43,8 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 22 - sudo apt-get install -y clang-tidy-22 + sudo ./llvm.sh 21 + sudo apt-get install -y clang-tidy-21 - name: Install Qt ${{ env.QT_VERSION }} uses: jurplel/install-qt-action@v4 @@ -57,14 +57,14 @@ jobs: - name: Verify clang-tidy configuration run: | - clang-tidy-22 --verify-config + clang-tidy-21 --verify-config - name: Prepare CMake run: | cmake -S . -B cmake.output -Werror=dev -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_COMPILE_WARNING_AS_ERROR=On env: - CC: clang-22 - CXX: clang++-22 + CC: clang-21 + CXX: clang++-21 - name: Prepare CMake dependencies run: | diff --git a/.github/workflows/tsan.yml b/.github/workflows/tsan.yml index 72b1764d11d..0e78566faae 100644 --- a/.github/workflows/tsan.yml +++ b/.github/workflows/tsan.yml @@ -53,7 +53,7 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 22 + sudo ./llvm.sh 21 - name: Install Qt ${{ env.QT_VERSION }} uses: jurplel/install-qt-action@v4 @@ -75,8 +75,8 @@ jobs: run: | cmake -S . -B cmake.output -Werror=dev -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DUSE_MATCHCOMPILER=Verify -DANALYZE_THREAD=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=Off -DDISABLE_DMAKE=On -DFILESDIR= -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache env: - CC: clang-22 - CXX: clang++-22 + CC: clang-21 + CXX: clang++-21 - name: Build cppcheck run: | diff --git a/.github/workflows/ubsan.yml b/.github/workflows/ubsan.yml index 5afc5feb1f9..66c56b6966a 100644 --- a/.github/workflows/ubsan.yml +++ b/.github/workflows/ubsan.yml @@ -53,7 +53,7 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 22 + sudo ./llvm.sh 21 - name: Install Qt ${{ env.QT_VERSION }} uses: jurplel/install-qt-action@v4 @@ -75,8 +75,8 @@ jobs: run: | cmake -S . -B cmake.output -Werror=dev -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DUSE_MATCHCOMPILER=Verify -DANALYZE_UNDEFINED=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DFILESDIR= -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache env: - CC: clang-22 - CXX: clang++-22 + CC: clang-21 + CXX: clang++-21 - name: Build cppcheck run: | diff --git a/cmake/clang_tidy.cmake b/cmake/clang_tidy.cmake index fe0efbbe32f..486c560f1f5 100644 --- a/cmake/clang_tidy.cmake +++ b/cmake/clang_tidy.cmake @@ -25,9 +25,6 @@ if(RUN_CLANG_TIDY_NAMES) endif() message(STATUS "NPROC=${NPROC}") - # TODO: introduced in run-clang-tidy-22 - set(CLANG_TIDY_CONFIG "-enable-check-profile") - # most of these are disabled because they are too noisy in our code # clang-analyzer-core.CallAndMessage # clang-analyzer-core.NonNullParamChecker From 3744a3ab598db5b1cf07fb7e4a5188d142cc97ff Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 9 Mar 2026 23:54:38 +0100 Subject: [PATCH 008/168] Fix #14578 using-declarations not simplified with --std=c++03 (#8308) Co-authored-by: chrchr-github --- lib/tokenize.cpp | 2 +- test/testsimplifyusing.cpp | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 984269d07e8..193fa5bbb4d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2890,7 +2890,7 @@ static const Token* skipConstVolatileBackwards(const Token* tok) { bool Tokenizer::simplifyUsing() { - if (!isCPP() || mSettings.standards.cpp < Standards::CPP11) + if (!isCPP()) return false; // simplify using N::x; to using x = N::x; diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index 8eba2142913..58af4c972bc 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -75,6 +75,7 @@ class TestSimplifyUsing : public TestFixture { TEST_CASE(simplifyUsing36); TEST_CASE(simplifyUsing37); TEST_CASE(simplifyUsing38); + TEST_CASE(simplifyUsing39); TEST_CASE(simplifyUsing8970); TEST_CASE(simplifyUsing8971); @@ -106,12 +107,14 @@ class TestSimplifyUsing : public TestFixture { Platform::Type type = Platform::Type::Native; bool debugwarnings = true; bool preprocess = false; + Standards::cppstd_t cppstd = Standards::CPPLatest; }; #define tok(...) tok_(__FILE__, __LINE__, __VA_ARGS__) template std::string tok_(const char* file, int line, const char (&code)[size], const TokOptions& options = make_default_obj()) { - const Settings settings = settingsBuilder(settings0).certainty(Certainty::inconclusive).debugwarnings(options.debugwarnings).platform(options.type).build(); + const Settings settings = settingsBuilder(settings0).certainty(Certainty::inconclusive).debugwarnings(options.debugwarnings) + .platform(options.type).cpp(options.cppstd).build(); if (options.preprocess) { SimpleTokenizer2 tokenizer(settings, *this, code, "test.cpp"); @@ -925,6 +928,16 @@ class TestSimplifyUsing : public TestFixture { ASSERT_EQUALS("", errout_str()); } + void simplifyUsing39() { + const char code[] = "using std::wstring;\n" // #14578 + "std::wstring ws;"; + const char expected[] = "std :: wstring ws ;"; + ASSERT_EQUALS(expected, tok(code)); + ASSERT_EQUALS("", errout_str()); + ASSERT_EQUALS(expected, tok(code, dinit(TokOptions, $.cppstd = Standards::CPP03))); + ASSERT_EQUALS("", errout_str()); + } + void simplifyUsing8970() { const char code[] = "using V = std::vector;\n" "struct A {\n" From 26f128783bab394be540baaa7f8931fa686fd25f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Gr=C3=BCninger?= Date: Tue, 10 Mar 2026 00:20:50 +0100 Subject: [PATCH 009/168] [gui] Prevent detaching from Q containers in range-based for loop (#8311) Use utils::as_const Found by Clazy (range-loop-detach). --- gui/checkthread.cpp | 4 ++-- gui/codeeditor.cpp | 5 +++-- gui/compliancereportdialog.cpp | 3 ++- gui/helpdialog.cpp | 3 ++- gui/librarydialog.cpp | 4 ++-- gui/projectfile.cpp | 12 ++++++------ gui/projectfiledialog.cpp | 2 +- gui/resultsview.cpp | 2 +- gui/threaddetails.cpp | 4 +++- gui/threadhandler.cpp | 5 +++-- 10 files changed, 25 insertions(+), 19 deletions(-) diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp index 81471638e62..fa5d68ba6d6 100644 --- a/gui/checkthread.cpp +++ b/gui/checkthread.cpp @@ -190,7 +190,7 @@ void CheckThread::run() void CheckThread::runAddonsAndTools(const Settings& settings, const FileSettings *fileSettings, const QString &fileName) { - for (const QString& addon : mAddonsAndTools) { + for (const QString& addon : utils::as_const(mAddonsAndTools)) { if (addon == CLANG_ANALYZER || addon == CLANG_TIDY) { if (!fileSettings) continue; @@ -303,7 +303,7 @@ void CheckThread::runAddonsAndTools(const Settings& settings, const FileSettings { const QString cmd(clangTidyCmd()); QString debug(cmd.contains(" ") ? ('\"' + cmd + '\"') : cmd); - for (const QString& arg : args) { + for (const QString& arg : utils::as_const(args)) { if (arg.contains(" ")) debug += " \"" + arg + '\"'; else diff --git a/gui/codeeditor.cpp b/gui/codeeditor.cpp index 98886716556..d6c8c1c4071 100644 --- a/gui/codeeditor.cpp +++ b/gui/codeeditor.cpp @@ -19,6 +19,7 @@ #include "codeeditor.h" #include "codeeditorstyle.h" +#include "utils.h" #include #include @@ -133,7 +134,7 @@ Highlighter::Highlighter(QTextDocument *parent, << "volatile" << "wchar_t" << "while"; - for (const QString &pattern : keywordPatterns) { + for (const QString &pattern : utils::as_const(keywordPatterns)) { rule.pattern = QRegularExpression("\\b" + pattern + "\\b"); rule.format = mKeywordFormat; rule.ruleRole = RuleRole::Keyword; @@ -216,7 +217,7 @@ void Highlighter::setStyle(const CodeEditorStyle &newStyle) void Highlighter::highlightBlock(const QString &text) { - for (const HighlightingRule &rule : mHighlightingRulesWithSymbols) { + for (const HighlightingRule &rule : utils::as_const(mHighlightingRulesWithSymbols)) { QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text); while (matchIterator.hasNext()) { QRegularExpressionMatch match = matchIterator.next(); diff --git a/gui/compliancereportdialog.cpp b/gui/compliancereportdialog.cpp index ae903f47dc4..c61299e6e3c 100644 --- a/gui/compliancereportdialog.cpp +++ b/gui/compliancereportdialog.cpp @@ -25,6 +25,7 @@ #include "filesettings.h" #include "importproject.h" #include "projectfile.h" +#include "utils.h" #include #include @@ -191,7 +192,7 @@ void ComplianceReportDialog::save() QSet allFiles; for (const QString &sourcefile: fileList.getFileList()) addHeaders(sourcefile, allFiles); - for (const QString& fileName: allFiles) { + for (const QString& fileName: utils::as_const(allFiles)) { QFile f(fileName); if (f.open(QFile::ReadOnly)) { QCryptographicHash hash(QCryptographicHash::Algorithm::Md5); diff --git a/gui/helpdialog.cpp b/gui/helpdialog.cpp index db1125339b9..0768318531c 100644 --- a/gui/helpdialog.cpp +++ b/gui/helpdialog.cpp @@ -19,6 +19,7 @@ #include "helpdialog.h" #include "common.h" +#include "utils.h" #include "ui_helpdialog.h" @@ -65,7 +66,7 @@ static QString getHelpFile() paths << (filesdir + "/help") << filesdir; #endif - for (const QString &p: paths) { + for (const QString &p: utils::as_const(paths)) { QString filename = p + "/online-help.qhc"; if (QFileInfo::exists(filename)) return filename; diff --git a/gui/librarydialog.cpp b/gui/librarydialog.cpp index 15572813c81..f38b64bdedc 100644 --- a/gui/librarydialog.cpp +++ b/gui/librarydialog.cpp @@ -292,11 +292,11 @@ void LibraryDialog::filterFunctions(const QString& filter) QList allItems = mUi->functions->findItems(QString(), Qt::MatchContains); if (filter.isEmpty()) { - for (QListWidgetItem *item : allItems) { + for (QListWidgetItem *item : utils::as_const(allItems)) { item->setHidden(false); } } else { - for (QListWidgetItem *item : allItems) { + for (QListWidgetItem *item : utils::as_const(allItems)) { item->setHidden(!item->text().startsWith(filter)); } } diff --git a/gui/projectfile.cpp b/gui/projectfile.cpp index 9001b6ad604..b807723ceeb 100644 --- a/gui/projectfile.cpp +++ b/gui/projectfile.cpp @@ -892,7 +892,7 @@ bool ProjectFile::write(const QString &filename) if (!mIncludeDirs.isEmpty()) { xmlWriter.writeStartElement(CppcheckXml::IncludeDirElementName); - for (const QString& incdir : mIncludeDirs) { + for (const QString& incdir : utils::as_const(mIncludeDirs)) { xmlWriter.writeStartElement(CppcheckXml::DirElementName); xmlWriter.writeAttribute(CppcheckXml::DirNameAttrib, incdir); xmlWriter.writeEndElement(); @@ -902,7 +902,7 @@ bool ProjectFile::write(const QString &filename) if (!mDefines.isEmpty()) { xmlWriter.writeStartElement(CppcheckXml::DefinesElementName); - for (const QString& define : mDefines) { + for (const QString& define : utils::as_const(mDefines)) { xmlWriter.writeStartElement(CppcheckXml::DefineName); xmlWriter.writeAttribute(CppcheckXml::DefineNameAttrib, define); xmlWriter.writeEndElement(); @@ -924,7 +924,7 @@ bool ProjectFile::write(const QString &filename) if (!mPaths.isEmpty()) { xmlWriter.writeStartElement(CppcheckXml::PathsElementName); - for (const QString& path : mPaths) { + for (const QString& path : utils::as_const(mPaths)) { xmlWriter.writeStartElement(CppcheckXml::PathName); xmlWriter.writeAttribute(CppcheckXml::PathNameAttrib, path); xmlWriter.writeEndElement(); @@ -934,7 +934,7 @@ bool ProjectFile::write(const QString &filename) if (!mExcludedPaths.isEmpty()) { xmlWriter.writeStartElement(CppcheckXml::ExcludeElementName); - for (const QString& path : mExcludedPaths) { + for (const QString& path : utils::as_const(mExcludedPaths)) { xmlWriter.writeStartElement(CppcheckXml::ExcludePathName); xmlWriter.writeAttribute(CppcheckXml::ExcludePathNameAttrib, path); xmlWriter.writeEndElement(); @@ -949,7 +949,7 @@ bool ProjectFile::write(const QString &filename) if (!mSuppressions.isEmpty()) { xmlWriter.writeStartElement(CppcheckXml::SuppressionsElementName); - for (const SuppressionList::Suppression &suppression : mSuppressions) { + for (const SuppressionList::Suppression &suppression : utils::as_const(mSuppressions)) { xmlWriter.writeStartElement(CppcheckXml::SuppressionElementName); if (!suppression.fileName.empty()) xmlWriter.writeAttribute("fileName", QString::fromStdString(suppression.fileName)); @@ -1169,7 +1169,7 @@ QString ProjectFile::getAddonFilePath(QString filesDir, const QString &addon) #endif ; - for (const QString& path : searchPaths) { + for (const QString& path : utils::as_const(searchPaths)) { QString f = path + addon + ".py"; if (QFile(f).exists()) return f; diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp index d1ddfc13200..21618dbb017 100644 --- a/gui/projectfiledialog.cpp +++ b/gui/projectfiledialog.cpp @@ -194,7 +194,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi } libs.sort(); mUI->mLibraries->clear(); - for (const QString &lib : libs) { + for (const QString &lib : utils::as_const(libs)) { auto* item = new QListWidgetItem(lib, mUI->mLibraries); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); // set checkable flag item->setCheckState(Qt::Unchecked); // AND initialize check state diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 8183214bb27..c6c54a2fd85 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -423,7 +423,7 @@ void ResultsView::readErrorsXml(const QString &filename) msgBox.exec(); } - for (const ErrorItem& item : errors) { + for (const ErrorItem& item : utils::as_const(errors)) { handleCriticalError(item); mUI->mTree->addErrorItem(item); } diff --git a/gui/threaddetails.cpp b/gui/threaddetails.cpp index 9036c18305d..1fcb97772ef 100644 --- a/gui/threaddetails.cpp +++ b/gui/threaddetails.cpp @@ -1,4 +1,6 @@ #include "threaddetails.h" +#include "utils.h" + #include "ui_threaddetails.h" #include @@ -43,7 +45,7 @@ void ThreadDetails::updateUI() { QString text("Thread\tStart time\tFile/Progress\n"); { QMutexLocker locker(&mMutex); - for (const auto& td: mThreadDetails) { + for (const auto& td: utils::as_const(mThreadDetails)) { auto& timeProgress = mProgress[td.file]; if (timeProgress.first.isEmpty() && !timeProgress.second.isEmpty()) timeProgress.first = QTime::currentTime().toString(Qt::TextDate); diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index 74735a9b666..3f89d58b558 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -23,6 +23,7 @@ #include "filesettings.h" #include "resultsview.h" #include "settings.h" +#include "utils.h" #include #include @@ -161,7 +162,7 @@ void ThreadHandler::createThreads(const int count) void ThreadHandler::removeThreads() { - for (CheckThread* thread : mThreads) { + for (CheckThread* thread : utils::as_const(mThreads)) { if (thread->isRunning()) { thread->stop(); thread->wait(); @@ -216,7 +217,7 @@ void ThreadHandler::stop() mCheckStartTime = QDateTime(); mAnalyseWholeProgram = false; mCtuInfo.clear(); - for (CheckThread* thread : mThreads) { + for (CheckThread* thread : utils::as_const(mThreads)) { thread->stop(); } } From 5aa8739595cabcbbefc31884968bc3a1031f2418 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 10 Mar 2026 08:50:15 +0100 Subject: [PATCH 010/168] Fix #14566 FP variableScope (variable used in loop) (#8296) --- lib/checkother.cpp | 2 +- test/testother.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 32dedf8f374..bbc6bdb90d0 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1337,7 +1337,7 @@ static bool isOnlyUsedInCurrentScope(const Variable* var, const Token *tok, cons return true; if (tok->scope()->type == ScopeType::eSwitch) return false; - return !Token::findmatch(tok->scope()->bodyEnd, "%varid%", scope->bodyEnd, var->declarationId()); + return !Token::findmatch(tok->scope()->bodyEnd, "%varid%", var->scope()->bodyEnd, var->declarationId()); } bool CheckOther::checkInnerScope(const Token *tok, const Variable* var, bool& used) const diff --git a/test/testother.cpp b/test/testother.cpp index 53f14c2a31d..88c83eba4b1 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2026,6 +2026,20 @@ class TestOther : public TestFixture { " }\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("void f(int& r) {\n" // #14566 + " int i = 0;\n" + " while (g()) {\n" + " {\n" + " if (g()) {\n" + " i = 0;" + " std::swap(i, r);\n" + " }\n" + " }\n" + " }\n" + " use(i);" + "}\n"); + ASSERT_EQUALS("", errout_str()); } #define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__) From 13f7e534f2cdac37abdcc4be2a2105187980d9ea Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 10 Mar 2026 11:18:54 +0100 Subject: [PATCH 011/168] Fix test for #14578 (#8317) --- test/testsimplifyusing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index 58af4c972bc..8e27bdc12d4 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -930,7 +930,7 @@ class TestSimplifyUsing : public TestFixture { void simplifyUsing39() { const char code[] = "using std::wstring;\n" // #14578 - "std::wstring ws;"; + "wstring ws;"; const char expected[] = "std :: wstring ws ;"; ASSERT_EQUALS(expected, tok(code)); ASSERT_EQUALS("", errout_str()); From c364e626bac4056e52b0103f28df46657bfb400d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 11 Mar 2026 08:41:49 +0100 Subject: [PATCH 012/168] Fix #14575 FN constVariablePointer with std::wstring (#8301) --- cfg/std.cfg | 17 +++++++++++++++++ test/cfg/std.cpp | 16 +++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/cfg/std.cfg b/cfg/std.cfg index 6cd0c371a5e..70e9cc17746 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -7130,6 +7130,16 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun false + + + + + + + + + false + @@ -7137,6 +7147,13 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun false + + + + + + false + diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 8a9976a94ae..7e406ca2187 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -5166,6 +5166,20 @@ void constVariablePointer_push_back(std::vector& d, const std::vector& s } } +struct S_constVariablePointer_wstring { // #14575 + std::wstring m; + const std::wstring& get() const { return m; } +}; + +S_constVariablePointer_wstring* g_constVariablePointer_wstring(); + +void h_constVariablePointer_wstring(const wchar_t*); + +void f_constVariablePointer_wstring() { + S_constVariablePointer_wstring* s = g_constVariablePointer_wstring(); // cppcheck-suppress constVariablePointer + h_constVariablePointer_wstring(s->get().c_str()); +} + std::streampos constParameterPointer_istream_tellg(std::istream* p) { // #13801 return p->tellg(); } @@ -5318,4 +5332,4 @@ int containerOutOfBounds_std_initializer_list() { // #14340 // cppcheck-suppress derefInvalidIterator int i = *x.end(); return i + containerOutOfBounds_std_initializer_list_access(x); -} \ No newline at end of file +} From 929f95cb0b286b734144f66c61735b674ce88a1a Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 11 Mar 2026 09:21:51 +0100 Subject: [PATCH 013/168] Fix #13509 information: --check-library: There is no matching configuration for function T::cbegin() (#8319) --- lib/checkfunctions.cpp | 6 ++++++ test/testfunctions.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index 3d6ff2ce755..f6799d199e7 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -635,6 +635,12 @@ void CheckFunctions::checkLibraryMatchFunctions() if (!tok->scope() || !tok->scope()->isExecutable()) continue; + // skip uninstantiated templates + if (tok == tok->scope()->bodyStart && tok->scope()->function && tok->scope()->function->templateDef) { + tok = tok->link(); + continue; + } + if (tok->str() == "new") insideNew = true; else if (tok->str() == ";") diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 48516faf852..feb7f2a666f 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -2220,6 +2220,12 @@ class TestFunctions : public TestFixture { " return b;\n" "}\n", s); TODO_ASSERT_EQUALS("", "[test.cpp:6:5]: (debug) auto token with no type. [autoNoType]\n", errout_str()); + + check("template \n" // #13509 + "void f(const T& t) {\n" + " t.g();\n" + "}\n", s); + ASSERT_EQUALS("", errout_str()); } void checkUseStandardLibrary1() { From 04af809b2d65f1fc0c6387e594646d9d8a6accfa Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Wed, 11 Mar 2026 11:13:42 +0100 Subject: [PATCH 014/168] Fix #13685 FP uninitvar with nested compound statement scopes (#8300) PR #6714 introduced a regression in which variables initialized in nested compound statements are incorrectly flagged as uninitialized by uninitvar. Such scopes could be present due to usage of GNU compound statements. --- lib/symboldatabase.cpp | 14 +++++++++----- test/testsymboldatabase.cpp | 19 +++++++++++++++++++ test/testuninitvar.cpp | 12 ++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 3bde7a71e19..9748959ba53 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -160,6 +160,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() }; std::stack inIfCondition; + std::stack pendingIfScopes; auto addLambda = [this, &scope](const Token* tok, const Token* lambdaEndToken) -> const Token* { const Token* lambdaStartToken = lambdaEndToken->link(); @@ -766,13 +767,14 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() scopeList.emplace_back(*this, tok, scope, ScopeType::eSwitch, scopeStartTok); scope->nestedList.push_back(&scopeList.back()); - scope = &scopeList.back(); - if (scope->type == ScopeType::eFor) - scope->checkVariable(tok->tokAt(2), AccessControl::Local); // check for variable declaration and add it to new scope if found - else if (scope->type == ScopeType::eCatch) - scope->checkVariable(tok->tokAt(2), AccessControl::Throw); // check for variable declaration and add it to new scope if found + Scope* newScope = &scopeList.back(); + if (newScope->type == ScopeType::eFor) + newScope->checkVariable(tok->tokAt(2), AccessControl::Local); // check for variable declaration and add it to new scope if found + else if (newScope->type == ScopeType::eCatch) + newScope->checkVariable(tok->tokAt(2), AccessControl::Throw); // check for variable declaration and add it to new scope if found tok = tok->next(); inIfCondition.push(scopeStartTok); + pendingIfScopes.push(newScope); } else if (Token::Match(tok, "%var% {")) { endInitList.emplace(tok->linkAt(1), scope); tok = tok->next(); @@ -783,6 +785,8 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() endInitList.emplace(tok->link(), scope); } else if (!inIfCondition.empty() && tok == inIfCondition.top()) { inIfCondition.pop(); + scope = pendingIfScopes.top(); + pendingIfScopes.pop(); } else if (isExecutableScope(tok)) { scopeList.emplace_back(*this, tok, scope, ScopeType::eUnconditional, tok); scope->nestedList.push_back(&scopeList.back()); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 192c40f51e5..05dd0ab9b8f 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -441,6 +441,7 @@ class TestSymbolDatabase : public TestFixture { TEST_CASE(createSymbolDatabaseFindAllScopes8); // #12761 TEST_CASE(createSymbolDatabaseFindAllScopes9); TEST_CASE(createSymbolDatabaseFindAllScopes10); + TEST_CASE(createSymbolDatabaseFindAllScopes11); TEST_CASE(createSymbolDatabaseIncompleteVars); @@ -6110,6 +6111,24 @@ class TestSymbolDatabase : public TestFixture { } } + void createSymbolDatabaseFindAllScopes11() // #13685 + { + GET_SYMBOL_DB("int f() {\n" + " int x;\n" + " if (!({ int *p = &x; *p = 1; 1; }))\n" + " return 0;\n" + " return x;\n" + "}\n"); + ASSERT(db && db->scopeList.size() == 4); + + auto it = db->scopeList.begin(); + std::advance(it, 3); + const Scope& compoundScope = *it; + ASSERT_EQUALS_ENUM(ScopeType::eUnconditional, compoundScope.type); + ASSERT_EQUALS_ENUM(ScopeType::eFunction, compoundScope.nestedIn->type); + ASSERT_EQUALS("f", compoundScope.nestedIn->className); + } + void createSymbolDatabaseIncompleteVars() { { diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 554eaca1f11..62be497638a 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -76,6 +76,7 @@ class TestUninitVar : public TestFixture { TEST_CASE(uninitvar12); // #10218 - stream read TEST_CASE(uninitvar13); // #9772 TEST_CASE(uninitvar14); + TEST_CASE(uninitvar15); // #13685 TEST_CASE(uninitvar_unconditionalTry); TEST_CASE(uninitvar_funcptr); // #6404 TEST_CASE(uninitvar_operator); // #6680 @@ -3647,6 +3648,17 @@ class TestUninitVar : public TestFixture { (checkuninitvar.valueFlowUninit)(); } + void uninitvar15() { // #13685 + const char code[] = "int f() {\n" + " int x;\n" + " if (!({ int *p = &x; *p = 1; 1; }))\n" + " return 0;\n" + " return x;\n" + "}"; + valueFlowUninit(code, false); + ASSERT_EQUALS("", errout_str()); + } + void valueFlowUninit2_value() { valueFlowUninit("void f() {\n" From 018417d499ddde241db5aec6a1d32d460fc1a2ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 11 Mar 2026 13:01:12 +0100 Subject: [PATCH 015/168] Fix #14577 (Checkers report: unsigned integer overflow can lead to huge string) (#8306) --- Makefile | 4 +++ lib/checkersreport.cpp | 8 ++++- test/testcheckersreport.cpp | 58 +++++++++++++++++++++++++++++++++++++ test/testrunner.vcxproj | 1 + 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 test/testcheckersreport.cpp diff --git a/Makefile b/Makefile index 37156d357af..7dd1228a0d7 100644 --- a/Makefile +++ b/Makefile @@ -294,6 +294,7 @@ TESTOBJ = test/fixture.o \ test/testbufferoverrun.o \ test/testcharvar.o \ test/testcheck.o \ + test/testcheckersreport.o \ test/testclangimport.o \ test/testclass.o \ test/testcmdlineparser.o \ @@ -757,6 +758,9 @@ test/testcharvar.o: test/testcharvar.cpp lib/addoninfo.h lib/check.h lib/checker test/testcheck.o: test/testcheck.cpp lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/utils.h test/fixture.h $(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testcheck.cpp +test/testcheckersreport.o: test/testcheckersreport.cpp lib/addoninfo.h lib/check.h lib/checkers.h lib/checkersreport.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h + $(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testcheckersreport.cpp + test/testclangimport.o: test/testclangimport.cpp lib/addoninfo.h lib/check.h lib/checkers.h lib/clangimport.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h $(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testclangimport.cpp diff --git a/lib/checkersreport.cpp b/lib/checkersreport.cpp index 59b3cf99495..0bbe02f3d7b 100644 --- a/lib/checkersreport.cpp +++ b/lib/checkersreport.cpp @@ -209,13 +209,19 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const fout << title << std::endl; fout << std::string(title.size(), '-') << std::endl; + maxCheckerSize = 0; + for (const auto& checkReq: addonInfo.checkers) { + const std::string& checker = checkReq.first; + maxCheckerSize = std::max(checker.size(), maxCheckerSize); + } + for (const auto& checkReq: addonInfo.checkers) { const std::string& checker = checkReq.first; const bool active = mActiveCheckers.count(checkReq.first) > 0; const std::string& req = checkReq.second; fout << (active ? "Yes " : "No ") << checker; if (!active && !req.empty()) - fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << "require:" + req; + fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << "require:" << req; fout << std::endl; } } diff --git a/test/testcheckersreport.cpp b/test/testcheckersreport.cpp new file mode 100644 index 00000000000..2d539ee77cf --- /dev/null +++ b/test/testcheckersreport.cpp @@ -0,0 +1,58 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2025 Cppcheck team. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include "checkersreport.h" +#include "fixture.h" +#include "helpers.h" +#include "settings.h" + +#include + +class TestCheckersReport : public TestFixture { +public: + TestCheckersReport() : TestFixture("TestCheckersReport") {} + + + void run() final { + // AddonInfo::checkers + TEST_CASE(addonInfoCheckers); + } + + void addonInfoCheckers() const { + AddonInfo a; + a.name = "test"; + a.checkers["abcdefghijklmnopqrstuvwxyz::abcdefghijklmnopqrstuvwxyz"] = "123"; + Settings s; + s.addonInfos.emplace_back(a); + const std::set activeCheckers; + CheckersReport r(s, activeCheckers); + const std::string report = r.getReport(""); + const auto pos = report.rfind("\n\n"); + ASSERT(pos != std::string::npos); + + const char expected[] = + "test checkers\n" + "-------------\n" + "No abcdefghijklmnopqrstuvwxyz::abcdefghijklmnopqrstuvwxyz require:123\n"; + + ASSERT_EQUALS(expected, report.substr(pos+2)); + } +}; + +REGISTER_TEST(TestCheckersReport) diff --git a/test/testrunner.vcxproj b/test/testrunner.vcxproj index cd7a039c418..1c5230c5535 100755 --- a/test/testrunner.vcxproj +++ b/test/testrunner.vcxproj @@ -53,6 +53,7 @@ + From 2f1665b575530d37dc5dbdb8454fb34c1e686d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Gr=C3=BCninger?= Date: Wed, 11 Mar 2026 14:17:35 +0100 Subject: [PATCH 016/168] [utils] Add Doxygen comment for utils::as_const (#8320) Fix typos in Doxygen comment of splitString --- lib/utils.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/utils.h b/lib/utils.h index abe1477a2a8..5a6927a5d96 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -403,14 +403,18 @@ static inline T* empty_if_null(T* p) } /** - * Split string by given sperator. + * Split string by given separator. * @param str The string to split - * @param sep The seperator - * @return The list of seperate strings (including empty ones). The whole input string if no seperator found. + * @param sep The separator + * @return The list of separate strings (including empty ones). The whole input string if no separator found. */ CPPCHECKLIB std::vector splitString(const std::string& str, char sep); namespace utils { + /** + * Drop-in replacement for C++17's std::as_const + * @param t The function forms the lvalue reference to const type of this argument. + */ template constexpr typename std::add_const::type & as_const(T& t) noexcept { From e473adb8fefb0fff9035a8dbda39130b03adabe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Wed, 11 Mar 2026 14:36:06 +0100 Subject: [PATCH 017/168] iwyu.yml: reverted to Clang 21 for now [skip ci] (#8318) --- .github/workflows/iwyu.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml index fa9be0cbba8..7a7d5c8d500 100644 --- a/.github/workflows/iwyu.yml +++ b/.github/workflows/iwyu.yml @@ -217,13 +217,13 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 22 - sudo apt-get install -y clang-tools-22 + sudo ./llvm.sh 21 + sudo apt-get install -y clang-tools-21 - name: Install libc++ if: matrix.stdlib == 'libc++' run: | - sudo apt-get install -y libc++-22-dev + sudo apt-get install -y libc++-21-dev - name: Install Qt ${{ env.QT_VERSION }} uses: jurplel/install-qt-action@v4 @@ -238,8 +238,8 @@ jobs: run: | cmake -S . -B cmake.output -Werror=dev -DCMAKE_BUILD_TYPE=Release -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCPPCHK_GLIBCXX_DEBUG=Off -DUSE_MATCHCOMPILER=Off -DEXTERNALS_AS_SYSTEM=On -DUSE_LIBCXX=${{ matrix.use_libcxx }} env: - CC: clang-22 - CXX: clang++-22 + CC: clang-21 + CXX: clang++-21 - name: Prepare CMake dependencies run: | @@ -256,7 +256,7 @@ jobs: - name: clang-include-cleaner run: | # TODO: run multi-threaded - find $PWD/cli $PWD/lib $PWD/test $PWD/gui -maxdepth 1 -name "*.cpp" | xargs -t -n 1 clang-include-cleaner-22 --print=changes --extra-arg=-w --extra-arg=-stdlib=${{ matrix.stdlib }} -p cmake.output > clang-include-cleaner.log 2>&1 + find $PWD/cli $PWD/lib $PWD/test $PWD/gui -maxdepth 1 -name "*.cpp" | xargs -t -n 1 clang-include-cleaner-21 --print=changes --extra-arg=-w --extra-arg=-stdlib=${{ matrix.stdlib }} -p cmake.output > clang-include-cleaner.log 2>&1 - uses: actions/upload-artifact@v4 if: success() || failure() From 8c99f0ece6ec054cc8fd5c755f291914bc055656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Wed, 11 Mar 2026 14:36:22 +0100 Subject: [PATCH 018/168] gui/mainwindows.cpp: removed redundant `ResultsView::clear()` call (#8315) already done in `clearResults()` above --- gui/mainwindow.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index f4e1dc2af9b..63917bdc912 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -597,7 +597,6 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons enableProjectActions(false); } - mUI->mResults->clear(true); mUI->mResults->setResultsSource(ResultsTree::ResultsSource::Analysis); mThread->clearFiles(); From 54b436464696a4368b7e9b7eaf302220e36bd23c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Wed, 11 Mar 2026 14:36:32 +0100 Subject: [PATCH 019/168] testrunner: added option `-x` to exclude the specified tests (#8314) --- test/fixture.cpp | 23 +++++++++++++++-------- test/options.cpp | 6 ++++++ test/options.h | 3 +++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/test/fixture.cpp b/test/fixture.cpp index fb535b1a1d0..00c844815fa 100644 --- a/test/fixture.cpp +++ b/test/fixture.cpp @@ -346,7 +346,8 @@ void TestFixture::printHelp() " -q Do not print the test cases that have run.\n" " -h, --help Print this help.\n" " -n Print no summaries.\n" - " -d Do not execute the tests.\n"; + " -d Do not execute any tests (dry run).\n" + " -x Exclude the specified tests.\n"; } void TestFixture::run(const std::string &str) @@ -390,17 +391,23 @@ std::size_t TestFixture::runTests(const options& args) // TODO: bail out when given class/test is not found? for (std::string classname : args.which_test()) { std::string testname; - if (classname.find("::") != std::string::npos) { - testname = classname.substr(classname.find("::") + 2); - classname.erase(classname.find("::")); + const std::string::size_type pos = classname.find("::"); + if (pos != std::string::npos) { + // TODO: excluding indiviual tests is not supported yet + testname = classname.substr(pos + 2); + classname.erase(pos); } for (TestInstance * test : TestRegistry::theInstance().tests()) { - if (classname.empty() || test->classname == classname) { - TestFixture* fixture = test->create(); - fixture->processOptions(args); - fixture->run(testname); + if (!classname.empty()) { + const bool match = test->classname == classname; + if ((match && args.exclude_tests()) || (!match && !args.exclude_tests())) + continue; } + + TestFixture* fixture = test->create(); + fixture->processOptions(args); + fixture->run(testname); } } diff --git a/test/options.cpp b/test/options.cpp index e8b3be139ae..17e44eeb6bf 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -22,6 +22,7 @@ options::options(int argc, const char* const argv[]) ,mHelp(mWhichTests.count("-h") != 0 || mWhichTests.count("--help")) ,mSummary(mWhichTests.count("-n") == 0) ,mDryRun(mWhichTests.count("-d") != 0) + ,mExcludeTests(mWhichTests.count("-x") != 0) ,mExe(argv[0]) { for (auto it = mWhichTests.cbegin(); it != mWhichTests.cend();) { @@ -65,3 +66,8 @@ const std::string& options::exe() const { return mExe; } + +bool options::exclude_tests() const +{ + return mExcludeTests; +} diff --git a/test/options.h b/test/options.h index 18df1dd79b2..5be6ca34e61 100644 --- a/test/options.h +++ b/test/options.h @@ -37,6 +37,8 @@ class options { bool summary() const; /** Perform dry run. */ bool dry_run() const; + /** Exclude provided lists of tests. */ + bool exclude_tests() const; /** Which test should be run. Empty string means 'all tests' */ const std::set& which_test() const; @@ -52,6 +54,7 @@ class options { const bool mHelp; const bool mSummary; const bool mDryRun; + const bool mExcludeTests; std::string mExe; }; From 45e0eb04da128332a545a02c9439aff90b06f4ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Wed, 11 Mar 2026 14:37:14 +0100 Subject: [PATCH 020/168] refs #14579 / refs #10543 - fixed compilation on Alpine Linux / added checks for includes / added Alpine to CI (#8313) --- .github/workflows/CI-unixish-docker.yml | 35 ++++++++++++++++++++----- CMakeLists.txt | 1 + Makefile | 3 +++ cli/CMakeLists.txt | 1 - cmake/compilerDefinitions.cmake | 4 +++ cmake/includechecks.cmake | 8 ++++++ cmake/printInfo.cmake | 3 +++ lib/config.h | 8 +++++- tools/dmake/dmake.cpp | 4 +++ 9 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 cmake/includechecks.cmake diff --git a/.github/workflows/CI-unixish-docker.yml b/.github/workflows/CI-unixish-docker.yml index 083bb7b7651..a38feb452f0 100644 --- a/.github/workflows/CI-unixish-docker.yml +++ b/.github/workflows/CI-unixish-docker.yml @@ -20,7 +20,16 @@ jobs: strategy: matrix: - image: ["ubuntu:24.04", "ubuntu:25.10"] + include: + - image: "ubuntu:24.04" + with_gui: true + full_build: true + - image: "ubuntu:25.10" + with_gui: true + full_build: true + - image: "alpine:3.23" + with_gui: false # it appears FindQt6.cmake is not provided by any package + full_build: false # FIXME: test-signalhandler.cpp fails to build since feenableexcept() is missing fail-fast: false # Prefer quick result runs-on: ubuntu-22.04 @@ -45,9 +54,15 @@ jobs: apt-get install -y cmake g++ make libxml2-utils libpcre3-dev - name: Install missing software (gui) on latest ubuntu + if: contains(matrix.image, 'ubuntu') run: | apt-get install -y qt6-base-dev qt6-charts-dev qt6-tools-dev + - name: Install missing software on Alpine + if: contains(matrix.image, 'alpine') + run: | + apk add cmake make g++ pcre-dev + # needs to be called after the package installation since # - it doesn't call "apt-get update" - name: ccache @@ -57,9 +72,10 @@ jobs: - name: Run CMake run: | - cmake -S . -B cmake.output -Werror=dev -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + cmake -S . -B cmake.output -Werror=dev -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=${{ matrix.with_gui }} -DWITH_QCHART=On -DBUILD_TRIAGE=${{ matrix.with_gui }} -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - - name: CMake build (with GUI) + - name: CMake build + if: matrix.full_build run: | cmake --build cmake.output -- -j$(nproc) @@ -71,7 +87,7 @@ jobs: strategy: matrix: - image: ["ubuntu:24.04", "ubuntu:25.10"] + image: ["ubuntu:24.04", "ubuntu:25.10", "alpine:3.23"] fail-fast: false # Prefer quick result runs-on: ubuntu-22.04 @@ -90,6 +106,11 @@ jobs: apt-get update apt-get install -y g++ make python3 libxml2-utils libpcre3-dev + - name: Install missing software on Alpine + if: contains(matrix.image, 'alpine') + run: | + apk add make g++ pcre-dev bash python3 libxml2-utils + # needs to be called after the package installation since # - it doesn't call "apt-get update" - name: ccache @@ -97,14 +118,16 @@ jobs: with: key: ${{ github.workflow }}-${{ matrix.image }} + # /usr/lib/ccache/bin - Alpine Linux + - name: Build cppcheck run: | - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" + export PATH="/usr/lib/ccache/bin:/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" make -j$(nproc) HAVE_RULES=yes CXXOPTS="-Werror" - name: Build test run: | - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" + export PATH="/usr/lib/ccache/bin:/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" make -j$(nproc) HAVE_RULES=yes CXXOPTS="-Werror" testrunner - name: Run test diff --git a/CMakeLists.txt b/CMakeLists.txt index b32fc90811b..3c037a10b36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ include(cmake/compilerCheck.cmake) include(cmake/versions.cmake) include(cmake/findDependencies.cmake) include(cmake/compileroptions.cmake) +include(cmake/includechecks.cmake) include(cmake/compilerDefinitions.cmake) include(cmake/buildFiles.cmake) if(BUILD_GUI) diff --git a/Makefile b/Makefile index 7dd1228a0d7..da5d9e73dfa 100644 --- a/Makefile +++ b/Makefile @@ -155,6 +155,9 @@ else ifneq ($(HAVE_RULES),) $(error invalid HAVE_RULES value '$(HAVE_RULES)') endif +HAVE_EXECINFO_H=$(shell echo "\#include " | $(CXX) -c -xc - 2> /dev/null && echo "1" || echo "0") +override CPPFLAGS += -DHAVE_EXECINFO_H=$(HAVE_EXECINFO_H) + override CXXFLAGS += $(CXXOPTS) override CPPFLAGS += $(CPPOPTS) override LDFLAGS += $(LDOPTS) diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 2664a29a65d..f63f3291849 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -1,4 +1,3 @@ - file(GLOB hdrs "*.h") file(GLOB srcs "*.cpp") file(GLOB mainfile "main.cpp") diff --git a/cmake/compilerDefinitions.cmake b/cmake/compilerDefinitions.cmake index 4967c282336..a43073018e6 100644 --- a/cmake/compilerDefinitions.cmake +++ b/cmake/compilerDefinitions.cmake @@ -66,6 +66,10 @@ if(NO_WINDOWS_SEH) add_definitions(-DNO_WINDOWS_SEH) endif() +if(NOT MSVC) + add_definitions(-DHAVE_EXECINFO_H=${HAVE_EXECINFO_H}) +endif() + if(FILESDIR_DEF) file(TO_CMAKE_PATH "${FILESDIR_DEF}" _filesdir) add_definitions(-DFILESDIR="${_filesdir}") diff --git a/cmake/includechecks.cmake b/cmake/includechecks.cmake new file mode 100644 index 00000000000..b9cbbd03183 --- /dev/null +++ b/cmake/includechecks.cmake @@ -0,0 +1,8 @@ +include(CheckIncludeFileCXX) + +if(NOT MSVC) + check_include_file_cxx(execinfo.h HAVE_EXECINFO_H) + if(NOT HAVE_EXECINFO_H) + set(HAVE_EXECINFO_H 0) + endif() +endif() \ No newline at end of file diff --git a/cmake/printInfo.cmake b/cmake/printInfo.cmake index 97f0f7d2536..ec567c74c41 100644 --- a/cmake/printInfo.cmake +++ b/cmake/printInfo.cmake @@ -15,6 +15,9 @@ message(STATUS "C++ flags (RelWithDebInfo) = ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") message(STATUS "C++ flags (Debug) = ${CMAKE_CXX_FLAGS_DEBUG}") message(STATUS "CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}") message(STATUS "CPPCHK_GLIBCXX_DEBUG = ${CPPCHK_GLIBCXX_DEBUG}") +if(DEFINED HAVE_EXECINFO_H) + message(STATUS "HAVE_EXECINFO_H = ${HAVE_EXECINFO_H}") +endif() get_directory_property(DirCompileDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS) message(STATUS "COMPILE_DEFINITIONS (global) = ${DirCompileDefs}") get_directory_property(DirCompileOptions DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_OPTIONS) diff --git a/lib/config.h b/lib/config.h index a63cf773d54..ff289569045 100644 --- a/lib/config.h +++ b/lib/config.h @@ -206,9 +206,15 @@ #define USE_WINDOWS_SEH #endif -#if !defined(NO_UNIX_BACKTRACE_SUPPORT) && defined(__GNUC__) && !defined(__APPLE__) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__SVR4) && !defined(__QNX__) && !defined(_AIX) +#if !defined(NO_UNIX_BACKTRACE_SUPPORT) +#if defined(HAVE_EXECINFO_H) +#if HAVE_EXECINFO_H #define USE_UNIX_BACKTRACE_SUPPORT #endif +#elif defined(__GNUC__) && !defined(__APPLE__) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__SVR4) && !defined(__QNX__) && !defined(_AIX) +#define USE_UNIX_BACKTRACE_SUPPORT +#endif +#endif #if !defined(NO_UNIX_SIGNAL_HANDLING) && defined(__GNUC__) && !defined(__MINGW32__) && !defined(__OS2__) #define USE_UNIX_SIGNAL_HANDLING diff --git a/tools/dmake/dmake.cpp b/tools/dmake/dmake.cpp index f8869f2eba7..82754f1df11 100644 --- a/tools/dmake/dmake.cpp +++ b/tools/dmake/dmake.cpp @@ -771,6 +771,10 @@ int main(int argc, char **argv) << " $(error invalid HAVE_RULES value '$(HAVE_RULES)')\n" << "endif\n\n"; + // the # needs to be escaped on older make versions + fout << "HAVE_EXECINFO_H=$(shell echo \"\\#include \" | $(CXX) -c -xc - 2> /dev/null && echo \"1\" || echo \"0\")\n" + << "override CPPFLAGS += -DHAVE_EXECINFO_H=$(HAVE_EXECINFO_H)\n\n"; + fout << "override CXXFLAGS += $(CXXOPTS)\n"; fout << "override CPPFLAGS += $(CPPOPTS)\n"; fout << "override LDFLAGS += $(LDOPTS)\n\n"; From 1b9124e5d896b1336ee7153e2489a2658386a11a Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 11 Mar 2026 18:42:20 +0100 Subject: [PATCH 021/168] Fix #14533, #14536 FN stlcstrConcat, stlcstrAssignment, stlcstrConstructor (#8261) Co-authored-by: chrchr-github --- gui/librarydialog.cpp | 2 +- lib/checkstl.cpp | 61 ++++++++++++++++++++++++++++++++++++------- test/teststl.cpp | 39 +++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 11 deletions(-) diff --git a/gui/librarydialog.cpp b/gui/librarydialog.cpp index f38b64bdedc..3199af9a975 100644 --- a/gui/librarydialog.cpp +++ b/gui/librarydialog.cpp @@ -167,7 +167,7 @@ void LibraryDialog::saveCfg() void LibraryDialog::saveCfgAs() { const QString filter(tr("Library files (*.cfg)")); - const QString path = Path::getPathFromFilename(mFileName.toStdString()).c_str(); + const QString path = QString::fromStdString(Path::getPathFromFilename(mFileName.toStdString())); QString selectedFile = QFileDialog::getSaveFileName(this, tr("Save the library as"), path, diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index c4827157988..882f4588eeb 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1959,6 +1959,53 @@ static bool isLocal(const Token *tok) return var && !var->isStatic() && var->isLocal(); } +static bool isc_strCall(const Token* tok, const Library::Container* container) +{ + if (!Token::simpleMatch(tok, "(")) + return false; + const Token* dot = tok->astOperand1(); + if (!Token::simpleMatch(dot, ".")) + return false; + const Token* obj = dot->astOperand1(); + if (!obj || !obj->valueType()) + return false; + const Library::Container* objContainer = obj->valueType()->container; + if (!objContainer || !container || !objContainer->stdStringLike || (objContainer != container && !container->view)) + return false; + return Token::Match(dot->astOperand2(), "c_str|data ( )"); +} + +static bool isc_strConcat(const Token* tok) +{ + if (!tok->isBinaryOp() || !Token::simpleMatch(tok, "+")) + return false; + for (const Token* op : { tok->astOperand1(), tok->astOperand2() }) { // NOLINT(readability-use-anyofallof) + const Token* sibling = op->astSibling(); + if (!sibling->valueType()) + continue; + if (isc_strCall(op, sibling->valueType()->container)) + return true; + } + return false; +} + +static bool isc_strAssignment(const Token* tok) +{ + if (!Token::simpleMatch(tok, "=")) + return false; + const Token* strTok = tok->astOperand1(); + if (!strTok || !strTok->valueType()) + return false; + return isc_strCall(tok->astOperand2(), strTok->valueType()->container); +} + +static bool isc_strConstructor(const Token* tok) +{ + if (!tok->valueType() || !Token::Match(tok, "%var% (|{")) + return false; + return isc_strCall(tok->tokAt(1)->astOperand2(), tok->valueType()->container); +} + namespace { const std::set stl_string_stream = { "istringstream", "ostringstream", "stringstream", "wstringstream" @@ -2027,16 +2074,14 @@ void CheckStl::string_c_str() const Variable* var2 = tok->tokAt(2)->variable(); if (var->isPointer() && var2 && var2->isStlType(stl_string_stream)) string_c_strError(tok); + } else if (printPerformance && isc_strAssignment(tok->tokAt(1))) { + string_c_strAssignment(tok, tok->variable()->getTypeName()); } else if (Token::Match(tok->tokAt(2), "%name% (") && Token::Match(tok->linkAt(3), ") . c_str|data ( ) ;") && tok->tokAt(2)->function() && Token::Match(tok->tokAt(2)->function()->retDef, "std :: string|wstring %name%")) { const Variable* var = tok->variable(); if (var->isPointer()) string_c_strError(tok); - } else if (printPerformance && tok->tokAt(1)->astOperand2() && Token::Match(tok->tokAt(1)->astOperand2()->tokAt(-3), "%var% . c_str|data ( ) ;")) { - const Token* vartok = tok->tokAt(1)->astOperand2()->tokAt(-3); - if ((tok->variable()->isStlStringType() || tok->variable()->isStlStringViewType()) && vartok->variable() && vartok->variable()->isStlStringType()) - string_c_strAssignment(tok, tok->variable()->getTypeName()); } } else if (printPerformance && tok->function() && Token::Match(tok, "%name% ( !!)") && tok->str() != scope.className) { const auto range = c_strFuncParam.equal_range(tok->function()); @@ -2068,13 +2113,9 @@ void CheckStl::string_c_str() } } } - } else if (printPerformance && Token::Match(tok, "%var% (|{ %var% . c_str|data ( ) !!,") && - tok->variable() && (tok->variable()->isStlStringType() || tok->variable()->isStlStringViewType()) && - tok->tokAt(2)->variable() && tok->tokAt(2)->variable()->isStlStringType()) { + } else if (printPerformance && isc_strConstructor(tok)) { string_c_strConstructor(tok, tok->variable()->getTypeName()); - } else if (printPerformance && tok->next() && tok->next()->variable() && tok->next()->variable()->isStlStringType() && tok->valueType() && tok->valueType()->type == ValueType::CONTAINER && - ((Token::Match(tok->previous(), "%var% + %var% . c_str|data ( )") && tok->previous()->variable() && tok->previous()->variable()->isStlStringType()) || - (Token::Match(tok->tokAt(-5), "%var% . c_str|data ( ) + %var%") && tok->tokAt(-5)->variable() && tok->tokAt(-5)->variable()->isStlStringType()))) { + } else if (printPerformance && isc_strConcat(tok)) { string_c_strConcat(tok); } else if (printPerformance && Token::simpleMatch(tok, "<<") && tok->astOperand2() && Token::Match(tok->astOperand2()->astOperand1(), ". c_str|data ( )")) { const Token* str = tok->astOperand2()->astOperand1()->astOperand1(); diff --git a/test/teststl.cpp b/test/teststl.cpp index 9f25d29478b..2c88f17dd14 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -4680,6 +4680,45 @@ class TestStl : public TestFixture { " return s->x.c_str();\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("std::string f(const std::string& s) {\n" // #14533 + " auto x = std::string(\"abc\") + s.c_str();\n" + " auto y = s.c_str() + std::string(\"def\");\n" + " return x + y;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2:33]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\n" + "[test.cpp:3:24]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\n", + errout_str()); + + check("std::string get();\n" + "std::string f(const std::string& s) {\n" + " return get() + s.c_str();\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3:18]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\n", + errout_str()); + + check("std::string get();\n" // #14536 + " std::string f(const std::string& s) {\n" + " return s + get().c_str();\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\n", + errout_str()); + + check("std::string get();\n" + "std::string f(std::string & s) {\n" + " s = get().c_str();\n" + " std::string s2{ get().c_str() };\n" + " return s2;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3:5]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\n" + "[test.cpp:4:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\n", + errout_str()); + + check("void f() {\n" + " std::string s;\n" + " auto a = + s.c_str();\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void uselessCalls() { From 922bb96ad804e48c988746be95b5b218d2c9d6d8 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 12 Mar 2026 08:26:20 +0100 Subject: [PATCH 022/168] CheckUninitVar: avoid redundant find() (#8321) Co-authored-by: chrchr-github --- lib/checkuninitvar.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 7dc89eb398c..ecaed652c5e 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -304,7 +304,7 @@ static void conditionAlwaysTrueOrFalse(const Token *tok, const std::mapisName() || tok->str() == ".") { while (tok && tok->str() == ".") tok = tok->astOperand2(); - const auto it = utils::as_const(variableValue).find(tok ? tok->varId() : ~0U); + const auto it = tok ? variableValue.find(tok->varId()) : variableValue.end(); if (it != variableValue.end()) { *alwaysTrue = (it->second != 0LL); *alwaysFalse = (it->second == 0LL); @@ -330,7 +330,7 @@ static void conditionAlwaysTrueOrFalse(const Token *tok, const std::mapstr() == ".") vartok = vartok->astOperand2(); - const auto it = utils::as_const(variableValue).find(vartok ? vartok->varId() : ~0U); + const auto it = vartok ? variableValue.find(vartok->varId()) : variableValue.end(); if (it == variableValue.end()) return; From 649627340e36cda6e9fdca92aee172d6df378df7 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 13 Mar 2026 10:51:46 +0100 Subject: [PATCH 023/168] Fix #14560 FP constParameterPointer (bad configuration in windows.cfg) (#8325) --- cfg/windows.cfg | 6 +++--- test/cfg/windows.cpp | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cfg/windows.cfg b/cfg/windows.cfg index 7020162805a..d698f320d3f 100644 --- a/cfg/windows.cfg +++ b/cfg/windows.cfg @@ -3504,7 +3504,7 @@ HFONT CreateFont( - + @@ -3559,7 +3559,7 @@ HFONT CreateFont( - + @@ -4120,7 +4120,7 @@ HFONT CreateFont( - + diff --git a/test/cfg/windows.cpp b/test/cfg/windows.cpp index a07e1b09365..f92c9941d81 100644 --- a/test/cfg/windows.cpp +++ b/test/cfg/windows.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -1223,3 +1224,13 @@ void SEH_unusedLabel() { // #13233 __finally { } } + +HWND constParameterPointer_CreateWindow(void* param) { // #14560 + return CreateWindow(L"MessageWnd", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, param); +} + +void constParameterPointer_SetupDiGetDeviceInstanceId(HDEVINFO info, SP_DEVINFO_DATA *data) { + const DWORD buffer_size = 256; + TCHAR buffer[buffer_size]; + SetupDiGetDeviceInstanceId(info, data, buffer, buffer_size, NULL); +} From 951567b6457095f972a9000f7f740eace0975142 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 13 Mar 2026 11:20:08 +0100 Subject: [PATCH 024/168] Fix #14583 FP duplInheritedMember for uninstantiated template (#8326) --- lib/checkclass.cpp | 2 ++ test/testclass.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 2b972e221fc..8f3c3baa293 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -3127,6 +3127,8 @@ static std::vector getDuplInheritedMemberFunctionsRecursive( continue; if (classFuncIt.tokenDef->isExpandedMacro()) continue; + if (classFuncIt.templateDef) + continue; for (const Function& parentClassFuncIt : parentClassIt.type->classScope->functionList) { if (classFuncIt.name() == parentClassFuncIt.name() && (parentClassFuncIt.access != AccessControl::Private || !skipPrivate) && diff --git a/test/testclass.cpp b/test/testclass.cpp index 9698916c41a..96b348fd376 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -734,6 +734,13 @@ class TestClass : public TestFixture { " void Two() = delete;\n" "};\n"); ASSERT_EQUALS("", errout_str()); + + checkDuplInheritedMembers("struct B { void f(); };\n" // #14583 + "struct D : B {\n" + " template \n" + " void f();\n" + "};\n"); + ASSERT_EQUALS("", errout_str()); } #define checkCopyConstructor(...) checkCopyConstructor_( __FILE__, __LINE__, __VA_ARGS__) From 7d80f6411f04f953a65a752b511b4ba66fa3a053 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 13 Mar 2026 11:20:53 +0100 Subject: [PATCH 025/168] Fix #14581 FP missingOverride for uninstantiated template overload (#8322) --- lib/checkclass.cpp | 2 ++ test/testclass.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 8f3c3baa293..ebdb434bb24 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -3271,6 +3271,8 @@ void CheckClass::checkOverride() continue; if (func.tokenDef->isExpandedMacro()) continue; + if (func.templateDef) + continue; const Function *baseFunc = func.getOverriddenFunction(); if (baseFunc) overrideError(baseFunc, &func); diff --git a/test/testclass.cpp b/test/testclass.cpp index 96b348fd376..43ada536df2 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -8842,6 +8842,16 @@ class TestClass : public TestFixture { "};\n"); ASSERT_EQUALS("[test.cpp:2:14] -> [test.cpp:5:6]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\n", errout_str()); + + checkOverride("struct B {\n" // #14581 + " virtual void f();\n" + "};\n" + "struct D : B {\n" + " void f() override;\n" + " template \n" + " void f();\n" + "};\n"); + ASSERT_EQUALS("", errout_str()); } void overrideCVRefQualifiers() { From aeb2328a5116e547167182f2380ff1a8f4e27313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Sun, 15 Mar 2026 01:14:57 +0100 Subject: [PATCH 026/168] refs #14084 - fixed most uninitialized CMake variables (#8292) --- cmake/clang_tidy.cmake | 2 ++ cmake/findDependencies.cmake | 7 ++++++- cmake/printInfo.cmake | 20 ++++++++++++++------ lib/CMakeLists.txt | 3 +++ test/CMakeLists.txt | 2 +- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/cmake/clang_tidy.cmake b/cmake/clang_tidy.cmake index 486c560f1f5..a192fc13320 100644 --- a/cmake/clang_tidy.cmake +++ b/cmake/clang_tidy.cmake @@ -37,6 +37,8 @@ if(RUN_CLANG_TIDY_NAMES) set(CLANG_TIDY_CSA_CONFIG "-config={InheritParentConfig: true, Checks: '-*,clang-analyzer-*,-clang-analyzer-core.CallAndMessage,-clang-analyzer-core.NonNullParamChecker,-clang-analyzer-cplusplus.NewDeleteLeaks,-clang-analyzer-cplusplus.NewDelete,-clang-analyzer-core.NullDereference,-clang-analyzer-unix.Stream,-clang-analyzer-alpha.clone.CloneChecker,-clang-analyzer-alpha.webkit.*'}") if (ENABLE_CSA_ALPHA) set(CLANG_TIDY_CSA_ALPHA_OPTS "-allow-enabling-alpha-checkers" "-extra-arg=-Xclang" "-extra-arg=-analyzer-config" "-extra-arg=-Xclang" "-extra-arg=aggressive-binary-operation-simplification=true") + else() + set(CLANG_TIDY_CSA_ALPHA_OPTS "") endif() # TODO: exclude moc_*.cpp diff --git a/cmake/findDependencies.cmake b/cmake/findDependencies.cmake index f3d7b0b2fec..ddfef6718c2 100644 --- a/cmake/findDependencies.cmake +++ b/cmake/findDependencies.cmake @@ -34,6 +34,8 @@ if(HAVE_RULES) if(NOT PCRE_LIBRARY OR NOT PCRE_INCLUDE) message(FATAL_ERROR "pcre dependency for RULES has not been found") endif() +else() + set(PCRE_LIBRARY "") endif() set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -70,6 +72,9 @@ if(NOT USE_BUNDLED_TINYXML2) endif() find_package(Threads REQUIRED) +if(NOT DEFINED CMAKE_THREAD_LIBS_INIT) + set(CMAKE_THREAD_LIBS_INIT "") +endif() if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.30") # avoid legacy warning about Boost lookup in CMake @@ -90,7 +95,7 @@ if(USE_BOOST) endif() set(Boost_FOUND ON) set(Boost_INCLUDE_DIRS "${BOOST_INCLUDEDIR}") - # TODO: set Boost_VERSION_STRING + set(Boost_VERSION_STRING "") # TODO: set proper value elseif(USE_BOOST STREQUAL "Auto") find_package(Boost) else() diff --git a/cmake/printInfo.cmake b/cmake/printInfo.cmake index ec567c74c41..87c7e41f284 100644 --- a/cmake/printInfo.cmake +++ b/cmake/printInfo.cmake @@ -72,7 +72,9 @@ if(BUILD_GUI) message(STATUS "QT_VERSION = ${QT_VERSION}") message(STATUS "Qt6Core_LIBRARIES = ${Qt6Core_LIBRARIES}") message(STATUS "Qt6Core_INCLUDE_DIRS = ${Qt6Core_INCLUDE_DIRS}") - message(STATUS "QHELPGENERATOR = ${QHELPGENERATOR}") + if(BUILD_ONLINE_HELP) + message(STATUS "QHELPGENERATOR = ${QHELPGENERATOR}") + endif() endif() message(STATUS) message(STATUS "HAVE_RULES = ${HAVE_RULES}") @@ -86,16 +88,22 @@ message(STATUS "CMAKE_THREAD_LIBS_INIT = ${CMAKE_THREAD_LIBS_INIT}") message(STATUS) message(STATUS "USE_BUNDLED_TINYXML2 = ${USE_BUNDLED_TINYXML2}") if(NOT USE_BUNDLED_TINYXML2) - message(STATUS "tinyxml2_LIBRARIES = ${tinyxml2_LIBRARIES}") - message(STATUS "tinyxml2_INCLUDE_DIRS = ${tinyxml2_INCLUDE_DIRS}") + if(TARGET tinyxml2::tinyxml2) + # TODO: print libraries and include dirs + else() + message(STATUS "tinyxml2_LIBRARIES = ${tinyxml2_LIBRARIES}") + message(STATUS "tinyxml2_INCLUDE_DIRS = ${tinyxml2_INCLUDE_DIRS}") + endif() endif() message(STATUS) message(STATUS "USE_BOOST = ${USE_BOOST}") if(USE_BOOST) message(STATUS "Boost_FOUND = ${Boost_FOUND}") - message(STATUS "Boost_VERSION_STRING = ${Boost_VERSION_STRING}") - message(STATUS "Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}") - message(STATUS "USE_BOOST_INT128 = ${USE_BOOST_INT128}") + if(Boost_FOUND) + message(STATUS "Boost_VERSION_STRING = ${Boost_VERSION_STRING}") + message(STATUS "Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}") + message(STATUS "USE_BOOST_INT128 = ${USE_BOOST_INT128}") + endif() endif() message(STATUS) message(STATUS "USE_LIBCXX = ${USE_LIBCXX}") diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index d7a94de352e..b826bc0b265 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -12,6 +12,8 @@ function(build_src output filename) set(${output} ${${output}} ${outfile} PARENT_SCOPE) if (USE_MATCHCOMPILER_OPT STREQUAL "Verify") set(verify_option "--verify") + else() + set(verify_option "") endif() add_custom_command( OUTPUT ${outfile} @@ -28,6 +30,7 @@ function(build_src output filename) endfunction() if (NOT USE_MATCHCOMPILER_OPT STREQUAL "Off") + set(srcs_build "") foreach(file ${srcs}) build_src(srcs_build ${file}) endforeach() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0462a65216e..14f3a8eac17 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -79,7 +79,7 @@ if (BUILD_TESTING) set(oneValueArgs PLATFORM NAME) set(multiValueArgs ADD_LIBRARY) - cmake_parse_arguments(PARSE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + cmake_parse_arguments(PARSE "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) get_filename_component(LIBRARY ${CFG_TEST} NAME_WE) # TODO: get rid of this if(PARSE_ADD_LIBRARY) From 391dd839587fe012f24c91fea287619e316922f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 15 Mar 2026 08:00:51 +0100 Subject: [PATCH 027/168] createrelease: tweak upload [skip ci] (#8339) --- createrelease | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/createrelease b/createrelease index 95eb0db7638..9dd79333119 100755 --- a/createrelease +++ b/createrelease @@ -150,9 +150,9 @@ rm -f cppcheck.cfg # TODO manual, update version on webpage # frs -git archive --format=tar --prefix=$releasename/ $tag | gzip > upload/$releasename.tar.gz -git archive --format=tar --prefix=$releasename/ $tag | bzip2 > upload/$releasename.tar.bz2 -git archive --format=zip -9 --prefix=$releasename/ $tag > upload/$releasename.zip +git archive --format=tar --prefix=$releasename/ $tag | gzip > upload/frs/$releasename.tar.gz +git archive --format=tar --prefix=$releasename/ $tag | bzip2 > upload/frs/$releasename.tar.bz2 +git archive --format=zip -9 --prefix=$releasename/ $tag > upload/frs/$releasename.zip cp releasenotes.txt upload/frs/README.md # TODO msi From fbf35b885c71a5a6a8af82e12b80ad248a8c459b Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Sun, 15 Mar 2026 08:43:22 +0100 Subject: [PATCH 028/168] Fix #14573 Only consider last NULL argument in varFuncNullUB (#8297) Resolving a FP in which the expanded macro ensures that the last variadic argument is not NULL. --- lib/checkother.cpp | 2 +- test/testother.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index bbc6bdb90d0..f051d231b69 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3557,7 +3557,7 @@ void CheckOther::checkVarFuncNullUB() for (const Scope * scope : symbolDatabase->functionScopes) { for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { // Is NULL passed to a function? - if (Token::Match(tok,"[(,] NULL [,)]")) { + if (Token::Match(tok,"[(,] NULL )")) { // Locate function name in this function call. const Token *ftok = tok; int argnr = 1; diff --git a/test/testother.cpp b/test/testother.cpp index 88c83eba4b1..ec09c9dda63 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -11309,6 +11309,12 @@ class TestOther : public TestFixture { check("void a(char *p, ...);\n" "void b() { a(NULL, 2); }"); ASSERT_EQUALS("", errout_str()); + + checkP("extern const int sentinel;\n" + "void a(int, ...);\n" + "#define b(x, ...) a((x), __VA_ARGS__, &sentinel)\n" + "void c() { b(1, NULL); }"); + ASSERT_EQUALS("", errout_str()); } void checkCastIntToCharAndBack() { // #160 From ade8582175248932a48b2b8314d9b7e93430b677 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sun, 15 Mar 2026 09:56:26 +0100 Subject: [PATCH 029/168] Fix #14582 FP uninitvar (array accessed via cast) (#8329) --- lib/astutils.cpp | 3 ++- test/testuninitvar.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 2d53ef0b0c1..aeee7a372e1 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2636,7 +2636,8 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, while ((tok2->astParent() && tok2->astParent()->isUnaryOp("*")) || (Token::simpleMatch(tok2->astParent(), ".") && !Token::Match(tok2->astParent()->astParent(), "[(,]")) || (tok2->astParent() && tok2->astParent()->isUnaryOp("&") && Token::simpleMatch(tok2->astParent()->astParent(), ".") && tok2->astParent()->astParent()->originalName()=="->") || - (Token::simpleMatch(tok2->astParent(), "[") && tok2 == tok2->astParent()->astOperand1())) { + (Token::simpleMatch(tok2->astParent(), "[") && tok2 == tok2->astParent()->astOperand1()) || + (Token::simpleMatch(tok2->astParent(), "(") && tok2->astParent()->isCast())) { if (tok2->astParent() && (tok2->astParent()->isUnaryOp("*") || (astIsLHS(tok2) && tok2->astParent()->originalName() == "->" && !hasOverloadedMemberAccess(tok2)))) derefs++; if (derefs > indirect) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 62be497638a..ecb467524c3 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -6696,6 +6696,18 @@ class TestUninitVar : public TestFixture { " return [&]() { return j; }();\n" "}\n"); ASSERT_EQUALS("[test.cpp:17:27]: (error) Uninitialized variable: j [uninitvar]\n", errout_str()); + + valueFlowUninit("int f() {\n" // #14582 + " int a[1];\n" + " static_cast(a)[0] = 0;\n" + " return a[0];\n" + "}\n" + "int g() {\n" + " int a[1];\n" + " ((int*)a)[0] = 0;\n" + " return a[0];\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value From 766c5b56480d76fab46ba0b29a317c6ec53cc352 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sun, 15 Mar 2026 09:57:45 +0100 Subject: [PATCH 030/168] Fix #14595 FN identicalInnerCondition in for loop (#8335) --- lib/checkcondition.cpp | 2 ++ test/testcondition.cpp | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 59aad6a9598..14fa900944d 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -619,6 +619,8 @@ static bool isNonConstFunctionCall(const Token *ftok, const Library &library) return false; if (ftok->function() && ftok->function()->isConst()) return false; + if (ftok->isControlFlowKeyword()) + return false; return true; } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index a592c489c59..241d0400099 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -2820,6 +2820,14 @@ class TestCondition : public TestFixture { " }\n" "}"); ASSERT_EQUALS("", errout_str()); + + check("void f(const int* p, const int* e) {\n" // #14595 + " for (; p;) {\n" + " if (p == e) {}\n" + " if (p) {}\n" + " }\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:4:13]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\n", errout_str()); } void identicalConditionAfterEarlyExit() { @@ -4675,7 +4683,7 @@ class TestCondition : public TestFixture { " }\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5:18]: (style) Condition 'S::s' is always true [knownConditionTrueFalse]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:5:18]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\n", errout_str()); check("void f() {\n" // #10811 " int i = 0;\n" @@ -4836,7 +4844,7 @@ class TestCondition : public TestFixture { " if (!b) {}\n" " if (a) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6:9] -> [test.cpp:9:9]: (style) Condition 'a' is always false [knownConditionTrueFalse]\n", + ASSERT_EQUALS("[test.cpp:6:9] -> [test.cpp:9:9]: (warning) Identical condition 'a', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); } From ca14dfa4db02cda39f9043875acc858710d41e16 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sun, 15 Mar 2026 10:00:28 +0100 Subject: [PATCH 031/168] Partial fix for #14523 FN knownConditionTrueFalse (brace-init in if, regression) (#8330) --- lib/vf_common.cpp | 2 +- test/testvalueflow.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/vf_common.cpp b/lib/vf_common.cpp index 78f44de6754..934757edea4 100644 --- a/lib/vf_common.cpp +++ b/lib/vf_common.cpp @@ -323,7 +323,7 @@ namespace ValueFlow if (!tok->isTemplateArg()) value.setKnown(); setTokenValue(tok->next(), std::move(value), settings); - } else if (Token::simpleMatch(tok, "= { } ;")) { + } else if (Token::simpleMatch(tok, "= { }")) { const Token* lhs = tok->astOperand1(); if (lhs && lhs->valueType() && (lhs->valueType()->isIntegral() || lhs->valueType()->pointer > 0)) { Value value(0); diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 00ebe7f694f..709be2a204f 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -6451,6 +6451,11 @@ class TestValueFlow : public TestFixture { " return x;\n" "}\n"; ASSERT_EQUALS(true, testValueOfXKnown(code, 5U, 0)); + + code = "void f() {\n" + " if (int* x = {}) {}\n" + "}\n"; + ASSERT_EQUALS(true, testKnownValueOfTok(code, "=", 0)); } static std::string isPossibleContainerSizeValue(std::list values, From dd26a1a33938696dbb5c937ef498e748cd2605d7 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sun, 15 Mar 2026 10:30:37 +0100 Subject: [PATCH 032/168] Fix #14571 FN constParameterPointer with reference to nested member (regression) (#8299) Co-authored-by: chrchr-github --- cli/signalhandler.cpp | 2 +- lib/astutils.cpp | 2 +- lib/valueflow.cpp | 2 +- test/testother.cpp | 12 ++++++++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cli/signalhandler.cpp b/cli/signalhandler.cpp index c87822454ae..88864efd743 100644 --- a/cli/signalhandler.cpp +++ b/cli/signalhandler.cpp @@ -108,7 +108,7 @@ static const Signalmap_t listofsignals = { * but when ending up here something went terribly wrong anyway. * And all which is left is just printing some information and terminate. */ -static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context) +static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context) // cppcheck-suppress constParameterCallback - info can be const { int type = -1; pid_t killid; diff --git a/lib/astutils.cpp b/lib/astutils.cpp index aeee7a372e1..b8e86b3e29d 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1084,7 +1084,7 @@ bool isAliasOf(const Token* tok, const Token* expr, nonneg int* indirect) r = findAstNode(expr, [&](const Token* childTok) { if (childTok->exprId() == 0) return false; - if (ref.token != tok && expr->exprId() == childTok->exprId()) { + if (ref.token != tok && expr->exprId() == childTok->exprId() && ref.token->isUnaryOp("*") && expr->exprId() == ref.token->astOperand1()->exprId()) { if (indirect) *indirect = 0; return true; diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index bf732566fff..f7e057da58f 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -4101,7 +4101,7 @@ static bool intersects(const C1& c1, const C2& c2) return false; } -static void valueFlowAfterAssign(TokenList &tokenlist, +static void valueFlowAfterAssign(const TokenList &tokenlist, const SymbolDatabase& symboldatabase, ErrorLogger &errorLogger, const Settings &settings, diff --git a/test/testother.cpp b/test/testother.cpp index ec09c9dda63..241a7512000 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4763,6 +4763,18 @@ class TestOther : public TestFixture { " return [](int* p) { return *p; }(&i);\n" "}\n"); ASSERT_EQUALS("[test.cpp:3:20]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); + + check("struct S {\n" // #14571 + " char* c;\n" + "};\n" + "struct T {\n" + " S s;\n" + "};\n" + "void f(std::string* p, T& t) {\n" + " S& r = t.s;\n" + " strcpy(r.c, p->c_str());\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:7:21]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); } void constArray() { From 4f31d0aa75c672a81c65aa37e586ce3ec7b0ee9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Sun, 15 Mar 2026 18:44:45 +0100 Subject: [PATCH 033/168] release-windows.yml: removed hardcoded aqt version [skip ci] (#8333) --- .github/workflows/release-windows.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/release-windows.yml b/.github/workflows/release-windows.yml index 20868c1c607..1caa87b61e5 100644 --- a/.github/workflows/release-windows.yml +++ b/.github/workflows/release-windows.yml @@ -65,14 +65,13 @@ jobs: # available modules: https://github.com/miurahr/aqtinstall/blob/master/docs/getting_started.rst#installing-modules # available tools: https://github.com/miurahr/aqtinstall/blob/master/docs/getting_started.rst#installing-tools - - name: Install Qt ${{ env.QT_VERSION }} + - name: Install Qt uses: jurplel/install-qt-action@v4 with: version: ${{ env.QT_VERSION }} modules: 'qtcharts' setup-python: 'false' tools: 'tools_opensslv3_x64' - aqtversion: '==3.1.*' # TODO: remove when aqtinstall 3.2.2 is available # TODO: build with multiple threads - name: Build x64 release GUI From d6ac48f6f7071d6411f99aa4b93e4867f7571112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Sun, 15 Mar 2026 18:45:17 +0100 Subject: [PATCH 034/168] fixed #14591 - store CTU function call information path with proper slashes (#8328) --- lib/ctu.cpp | 2 +- test/cli/other_test.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/ctu.cpp b/lib/ctu.cpp index 3f50dd1a485..d1be82b34fa 100644 --- a/lib/ctu.cpp +++ b/lib/ctu.cpp @@ -112,7 +112,7 @@ std::string CTU::FileInfo::FunctionCall::toXmlString() const out << ">\n"; for (const ErrorMessage::FileLocation &loc : callValuePath) out << " \n"; diff --git a/test/cli/other_test.py b/test/cli/other_test.py index ce4089c9ac4..7749ef18175 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -4234,3 +4234,41 @@ def run_and_assert_cppcheck(stdout_exp): # TODO: # - invalid error # - internalError + + +def test_ctu_function_call_path_slash(tmp_path): # #14591 + test_file = tmp_path / 'test.cpp' + with open(test_file, "w") as f: + f.write( +"""void g(T* p) +{ + *p = 0; +} + +void f(T* p) +{ + p = nullptr; + g(p); +} +""") + + build_dir = tmp_path / 'b1' + os.makedirs(build_dir) + + args = [ + '-q', + '--template=simple', + '--cppcheck-build-dir={}'.format(build_dir), + str(test_file) + ] + + exitcode, _, _ = cppcheck(args) + assert exitcode == 0 + + test_a1_file = build_dir / 'test.a1' + analyzerinfo = ElementTree.fromstring(test_a1_file.read_text()) + function_call_paths = analyzerinfo.findall('FileInfo/function-call/path') + assert len(function_call_paths) == 1 + file = function_call_paths[0].attrib['file'] + assert file + assert not '\\' in file # the path was incorrectly converted to native From 83a7e99c9a4f18b1f5ee4c0bc7bc179eb2c0a15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Sun, 15 Mar 2026 18:47:28 +0100 Subject: [PATCH 035/168] fixed #14584 - set minimum required AppleClang version to 6.0 / separated handling of `Clang` and `AppleClang` in CMake (#8257) --- cmake/compilerCheck.cmake | 8 +++++++- cmake/compilerDefinitions.cmake | 32 ++++++++++++++++++-------------- cmake/options.cmake | 4 ++++ lib/config.h | 2 ++ readme.md | 2 +- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/cmake/compilerCheck.cmake b/cmake/compilerCheck.cmake index 47c8fc1245e..c26bf9e336e 100644 --- a/cmake/compilerCheck.cmake +++ b/cmake/compilerCheck.cmake @@ -2,12 +2,18 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1) message(ERROR "GCC >= 5.1 required - detected ${CMAKE_CXX_COMPILER_VERSION} not supported") endif() -elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5) message(ERROR "Clang >= 3.5 required - detected ${CMAKE_CXX_COMPILER_VERSION} not supported") endif() +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0) + message(ERROR "AppleClang >= 6.0 required - detected ${CMAKE_CXX_COMPILER_VERSION} not supported") + endif() elseif(MSVC) if(MSVC_VERSION VERSION_LESS 1900) message(ERROR "Visual Studio >= 2015 (19.0) required - detected ${MSVC_VERSION} not supported") endif() +else() + message(WARNING "Unknown compiler ${CMAKE_CXX_COMPILER_ID}") endif() diff --git a/cmake/compilerDefinitions.cmake b/cmake/compilerDefinitions.cmake index a43073018e6..5f03b83dcee 100644 --- a/cmake/compilerDefinitions.cmake +++ b/cmake/compilerDefinitions.cmake @@ -8,26 +8,30 @@ if(MSVC) add_definitions(-DWIN32_LEAN_MEAN) endif() -# TODO: this should probably apply to the compiler and not the platform - I think it is only "broken" with MinGW -# TODO: AppleClang only has libc++ -# TODO: what about clang-cl and native Win32 clang? -if(CPPCHK_GLIBCXX_DEBUG AND UNIX AND CMAKE_BUILD_TYPE STREQUAL "Debug") - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - if(USE_LIBCXX) - if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18) - add_definitions(-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG) - else() - add_definitions(-D_LIBCPP_ENABLE_ASSERTIONS=1) - endif() - # TODO: also add _LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS? +# libstdc++-specific flags +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR (NOT USE_LIBCXX AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")) + if(CPPCHK_GLIBCXX_DEBUG AND CMAKE_BUILD_TYPE STREQUAL "Debug") + add_definitions(-D_GLIBCXX_DEBUG) + endif() +endif() + +# TODO: what about clang-cl? +# libc++-specific flags - AppleClang only has libc++ +if ((USE_LIBCXX AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + if(CPPCHK_GLIBCXX_DEBUG AND CMAKE_BUILD_TYPE STREQUAL "Debug") + # TODO: determine proper version for AppleClang - current value is based on the oldest version avaialble in CI + if((CMAKE_CXX_COMPILER_ID STREQUALS "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18) OR + (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 17)) + add_definitions(-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG) + else() + add_definitions(-D_LIBCPP_ENABLE_ASSERTIONS=1) endif() + # TODO: also add _LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS? else() # TODO: check if this can be enabled again for Clang - also done in Makefile add_definitions(-D_GLIBCXX_DEBUG) endif() -endif() -if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND USE_LIBCXX) add_definitions(-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) endif() diff --git a/cmake/options.cmake b/cmake/options.cmake index 07c6f8d771d..e728d809220 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -116,6 +116,10 @@ if (NOT USE_BOOST AND USE_BOOST_INT128) endif() option(USE_LIBCXX "Use libc++ instead of libstdc++" OFF) +if(USE_LIBCXX AND NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") + message(FATAL_ERROR "libc++ can only be used with a Clang-based compiler") +endif() + option(NO_UNIX_SIGNAL_HANDLING "Disable usage of Unix Signal Handling" OFF) option(NO_UNIX_BACKTRACE_SUPPORT "Disable usage of Unix Backtrace support" OFF) option(NO_WINDOWS_SEH "Disable usage of Windows SEH" OFF) diff --git a/lib/config.h b/lib/config.h index ff289569045..ca60904c5d9 100644 --- a/lib/config.h +++ b/lib/config.h @@ -96,6 +96,7 @@ # define UNUSED #endif +// TODO: AppleClang versions do not align with Clang versions - add check for proper version // warn_unused #if __has_cpp_attribute (gnu::warn_unused) || \ (defined(__clang__) && (__clang_major__ >= 15)) @@ -115,6 +116,7 @@ # define DEPRECATED #endif +// TODO: AppleClang versions do not align with Clang versions - add check for proper version // returns_nonnull #if __has_cpp_attribute (gnu::returns_nonnull) # define RET_NONNULL [[gnu::returns_nonnull]] diff --git a/readme.md b/readme.md index 9244243770a..a34dad2a57a 100644 --- a/readme.md +++ b/readme.md @@ -36,7 +36,7 @@ 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 / Visual Studio 2015. +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. From 68c91ae2c0c6a173ddf414309a920fcea1c9025f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Sun, 15 Mar 2026 18:48:06 +0100 Subject: [PATCH 036/168] fixed #14585 - store all errors in `AnalyzerInformation` even if suppressed (#8267) --- lib/cppcheck.cpp | 7 ++++++- test/cli/other_test.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 1154d55bd9f..5023a5e258e 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -177,6 +177,8 @@ class CppCheck::CppCheckLogger : public ErrorLogger // TODO: only convert if necessary const auto errorMessage = SuppressionList::ErrorMessage::fromErrorMessage(msg, macroNames); + bool suppressed = false; + if (mSuppressions.nomsg.isSuppressed(errorMessage, mUseGlobalSuppressions)) { // Safety: Report critical errors to ErrorLogger if (mSettings.safety && ErrorLogger::isCriticalErrorId(msg.id)) { @@ -193,7 +195,7 @@ class CppCheck::CppCheckLogger : public ErrorLogger mErrorLogger.reportErr(msg); } } - return; + suppressed = true; } // TODO: there should be no need for the verbose and default messages here @@ -210,6 +212,9 @@ class CppCheck::CppCheckLogger : public ErrorLogger if (mAnalyzerInformation) mAnalyzerInformation->reportErr(msg); + if (suppressed) + return; + if (!mSuppressions.nofail.isSuppressed(errorMessage) && !mSuppressions.nomsg.isSuppressed(errorMessage)) { mExitCode = 1; } diff --git a/test/cli/other_test.py b/test/cli/other_test.py index 7749ef18175..cc8b96badf1 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -3374,6 +3374,42 @@ def test_suppress_unmatched_wildcard(tmp_path): # #13660 ] +def test_suppress_unmatched_wildcard_cached(tmp_path): # #14585 + test_file = tmp_path / 'test.c' + with open(test_file, 'wt') as f: + f.write( +"""void f() +{ + (void)(*((int*)0)); +} +""") + + build_dir = tmp_path / 'b1' + os.makedirs(build_dir) + + # need to run in the temporary folder because the path of the suppression has to match + args = [ + '-q', + '--template=simple', + '--enable=information', + '--cppcheck-build-dir={}'.format(build_dir), + '--suppress=nullPointer:test*.c', + 'test.c' + ] + + stderr_exp = [] + + exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path) + assert exitcode == 0, stdout + assert stdout.splitlines() == [] + assert stderr.splitlines() == stderr_exp + + exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path) + assert exitcode == 0, stdout + assert stdout.splitlines() == [] + assert stderr.splitlines() == stderr_exp + + def test_suppress_unmatched_wildcard_unchecked(tmp_path): # make sure that unmatched wildcards suppressions are reported if files matching the expressions were processesd # but isSuppressed() has never been called (i.e. no findings in file at all) From 504b33381b1a325c64b1ff07b24c3455661fdbf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 16 Mar 2026 08:03:19 +0100 Subject: [PATCH 037/168] Fix #14567: internalAstError for requires expression with parameter list (#8309) --- lib/tokenlist.cpp | 5 ++++- test/testtokenize.cpp | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 0ffcf7e37e4..a46fad5d021 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1055,7 +1055,10 @@ static void compilePrecedence2(Token *&tok, AST_state& state) else compileUnaryOp(tok, state, compileExpression); tok = tok2->link()->next(); - } else if (Token::simpleMatch(tok->previous(), "requires {")) { + } else if (Token::simpleMatch(tok->previous(), "requires {") + || (Token::simpleMatch(tok->previous(), ")") + && tok->linkAt(-1) + && Token::simpleMatch(tok->linkAt(-1)->previous(), "requires ("))) { tok->astOperand1(state.op.top()); state.op.pop(); state.op.push(tok); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index e59f7b3be62..eefc0b8aba0 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7147,6 +7147,7 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("crequires{ac::||= a{b{||", testAst("template concept c = requires { a{} || b{}; } || a::c;")); ASSERT_EQUALS("ifrequires{(", testAst("if (requires { true; }) {}")); // #13308 + ASSERT_EQUALS("Crequires({requires({||= sizeofT(4== sizeofT(8==", testAst("concept C = requires() { sizeof(T) == 4; } || requires() { sizeof(T) == 8; };")); } void astcast() { From 36b8eb5a2d31409d3670040cc581c2fda3c302ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 16 Mar 2026 08:04:22 +0100 Subject: [PATCH 038/168] Partial fix for #14576: Missing attribute alignas (#8305) --- lib/tokenize.cpp | 11 ++++++++++- test/testtokenize.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 193fa5bbb4d..8ad49dedd37 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9761,10 +9761,19 @@ void Tokenizer::simplifyCPPAttribute() Token* atok = nullptr; if (Token::Match(tok->previous(), "%name%")) atok = tok->previous(); - else { + else if (Token::simpleMatch(tok->previous(), "]")) { + atok = tok; + while (atok && Token::simpleMatch(atok->previous(), "]")) { + atok = atok->linkAt(-1); + atok = atok ? atok->previous() : nullptr; + } + if (!Token::Match(atok, "%name%")) + atok = nullptr; + } else { atok = tok; while (isCPPAttribute(atok) || isAlignAttribute(atok)) atok = skipCPPOrAlignAttribute(atok)->next(); + atok = atok ? getVariableTokenAfterAttributes(atok) : atok; } if (atok) { std::string a; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index eefc0b8aba0..16c9335dce7 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -284,6 +284,9 @@ class TestTokenizer : public TestFixture { TEST_CASE(cppMaybeUnusedAfter2); TEST_CASE(cppMaybeUnusedStructuredBinding); + TEST_CASE(attributeAlignasBefore); + TEST_CASE(attributeAlignasAfter); + TEST_CASE(splitTemplateRightAngleBrackets); TEST_CASE(cpp03template1); @@ -4332,6 +4335,35 @@ class TestTokenizer : public TestFixture { ASSERT(var2 && var2->isAttributeMaybeUnused()); } + void attributeAlignasBefore() { + const char code[] = "alignas(long) unsigned char buffer[sizeof(long)];"; + const char expected[] = "char buffer [ sizeof ( long ) ] ;"; + SimpleTokenizer tokenizer(settings0, *this); + ASSERT(tokenizer.tokenize(code)); + + ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false)); + + const Token *var = Token::findsimplematch(tokenizer.tokens(), "buffer"); + ASSERT(var); + ASSERT(var->hasAttributeAlignas()); + ASSERT(var->getAttributeAlignas().size() == 1); + ASSERT_EQUALS(var->getAttributeAlignas()[0], "long"); + } + + void attributeAlignasAfter() { + const char code[] = "unsigned char buffer[sizeof(long)] alignas(long);"; + const char expected[] = "char buffer [ sizeof ( long ) ] ;"; + SimpleTokenizer tokenizer(settings0, *this); + ASSERT(tokenizer.tokenize(code)); + + ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false)); + + const Token *var = Token::findsimplematch(tokenizer.tokens(), "buffer"); + ASSERT(var); + ASSERT(var->hasAttributeAlignas()); + ASSERT(var->getAttributeAlignas().size() == 1); + ASSERT_EQUALS(var->getAttributeAlignas()[0], "long"); + } void splitTemplateRightAngleBrackets() { { From 1d1f7478a21f97633eec28d40d63a4fa23df4261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Mon, 16 Mar 2026 14:45:11 +0100 Subject: [PATCH 039/168] refs #14593 - improved string concatenation in `ScopeInfo3` constructor (#8334) --- lib/tokenize.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 8ad49dedd37..a371df76e5d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2418,7 +2418,8 @@ namespace { while (scope && scope->parent) { if (scope->name.empty()) break; - fullName = scope->name + " :: " + fullName; + fullName.insert(0, " :: "); + fullName.insert(0, scope->name); scope = scope->parent; } } From 8cb66cf41c5385276984d36c1e408af95a27c9a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Mon, 16 Mar 2026 16:30:08 +0100 Subject: [PATCH 040/168] updated CI to Clang 22 - again (#8342) --- .clang-tidy | 12 ++++++++++-- .github/workflows/asan.yml | 6 +++--- .github/workflows/clang-tidy.yml | 10 +++++----- .github/workflows/iwyu.yml | 12 ++++++------ .github/workflows/tsan.yml | 6 +++--- .github/workflows/ubsan.yml | 6 +++--- clang-tidy.md | 13 +++++++++++++ cmake/clang_tidy.cmake | 6 ++++++ cmake/compileroptions.cmake | 6 ++++++ lib/vf_common.cpp | 2 +- test/testcheckersreport.cpp | 2 +- tools/triage/mainwindow.cpp | 1 + 12 files changed, 58 insertions(+), 24 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 91173d82e10..b83436861bd 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -23,12 +23,14 @@ Checks: > google-explicit-constructor, -bugprone-assignment-in-if-condition, -bugprone-branch-clone, + -bugprone-command-processor, -bugprone-easily-swappable-parameters, -bugprone-empty-catch, -bugprone-macro-parentheses, -bugprone-narrowing-conversions, -bugprone-signed-char-misuse, -bugprone-switch-missing-default-case, + -bugprone-throwing-static-initialization, -bugprone-unchecked-optional-access, -clang-analyzer-*, -concurrency-mt-unsafe, @@ -37,11 +39,12 @@ Checks: > -misc-non-private-member-variables-in-classes, -misc-throw-by-value-catch-by-reference, -misc-use-anonymous-namespace, - -misc-use-internal-linkage, -modernize-avoid-c-arrays, -modernize-deprecated-ios-base-aliases, -misc-include-cleaner, + -misc-multiple-inheritance, -misc-unused-using-decls, + -modernize-avoid-c-style-cast, -modernize-loop-convert, -modernize-macro-to-enum, -modernize-raw-string-literal, @@ -67,9 +70,10 @@ Checks: > -readability-identifier-length, -readability-identifier-naming, -readability-implicit-bool-conversion, + -readability-inconsistent-ifelse-braces, -readability-isolate-declaration, -readability-magic-numbers, - -readability-math-missing-parentheses, + -readability-redundant-parentheses, -readability-suspicious-call-argument, -readability-uppercase-literal-suffix, -readability-use-concise-preprocessor-directives, @@ -84,3 +88,7 @@ CheckOptions: value: '0' - key: modernize-use-trailing-return-type.TransformFunctions value: false + - key: misc-override-with-different-visibility.DisallowedVisibilityChange + value: widening + - key: misc-use-internal-linkage.AnalyzeTypes + value: false diff --git a/.github/workflows/asan.yml b/.github/workflows/asan.yml index 977d3f05337..38e90cb760a 100644 --- a/.github/workflows/asan.yml +++ b/.github/workflows/asan.yml @@ -54,7 +54,7 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 21 + sudo ./llvm.sh 22 - name: Install Qt ${{ env.QT_VERSION }} uses: jurplel/install-qt-action@v4 @@ -76,8 +76,8 @@ jobs: run: | cmake -S . -B cmake.output -Werror=dev -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DUSE_MATCHCOMPILER=Verify -DANALYZE_ADDRESS=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DFILESDIR= -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache env: - CC: clang-21 - CXX: clang++-21 + CC: clang-22 + CXX: clang++-22 - name: Build cppcheck run: | diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 00a4ee7d332..c4f8cc0cf6b 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -43,8 +43,8 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 21 - sudo apt-get install -y clang-tidy-21 + sudo ./llvm.sh 22 + sudo apt-get install -y clang-tidy-22 - name: Install Qt ${{ env.QT_VERSION }} uses: jurplel/install-qt-action@v4 @@ -57,14 +57,14 @@ jobs: - name: Verify clang-tidy configuration run: | - clang-tidy-21 --verify-config + clang-tidy-22 --verify-config - name: Prepare CMake run: | cmake -S . -B cmake.output -Werror=dev -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_COMPILE_WARNING_AS_ERROR=On env: - CC: clang-21 - CXX: clang++-21 + CC: clang-22 + CXX: clang++-22 - name: Prepare CMake dependencies run: | diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml index 7a7d5c8d500..fa9be0cbba8 100644 --- a/.github/workflows/iwyu.yml +++ b/.github/workflows/iwyu.yml @@ -217,13 +217,13 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 21 - sudo apt-get install -y clang-tools-21 + sudo ./llvm.sh 22 + sudo apt-get install -y clang-tools-22 - name: Install libc++ if: matrix.stdlib == 'libc++' run: | - sudo apt-get install -y libc++-21-dev + sudo apt-get install -y libc++-22-dev - name: Install Qt ${{ env.QT_VERSION }} uses: jurplel/install-qt-action@v4 @@ -238,8 +238,8 @@ jobs: run: | cmake -S . -B cmake.output -Werror=dev -DCMAKE_BUILD_TYPE=Release -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCPPCHK_GLIBCXX_DEBUG=Off -DUSE_MATCHCOMPILER=Off -DEXTERNALS_AS_SYSTEM=On -DUSE_LIBCXX=${{ matrix.use_libcxx }} env: - CC: clang-21 - CXX: clang++-21 + CC: clang-22 + CXX: clang++-22 - name: Prepare CMake dependencies run: | @@ -256,7 +256,7 @@ jobs: - name: clang-include-cleaner run: | # TODO: run multi-threaded - find $PWD/cli $PWD/lib $PWD/test $PWD/gui -maxdepth 1 -name "*.cpp" | xargs -t -n 1 clang-include-cleaner-21 --print=changes --extra-arg=-w --extra-arg=-stdlib=${{ matrix.stdlib }} -p cmake.output > clang-include-cleaner.log 2>&1 + find $PWD/cli $PWD/lib $PWD/test $PWD/gui -maxdepth 1 -name "*.cpp" | xargs -t -n 1 clang-include-cleaner-22 --print=changes --extra-arg=-w --extra-arg=-stdlib=${{ matrix.stdlib }} -p cmake.output > clang-include-cleaner.log 2>&1 - uses: actions/upload-artifact@v4 if: success() || failure() diff --git a/.github/workflows/tsan.yml b/.github/workflows/tsan.yml index 0e78566faae..72b1764d11d 100644 --- a/.github/workflows/tsan.yml +++ b/.github/workflows/tsan.yml @@ -53,7 +53,7 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 21 + sudo ./llvm.sh 22 - name: Install Qt ${{ env.QT_VERSION }} uses: jurplel/install-qt-action@v4 @@ -75,8 +75,8 @@ jobs: run: | cmake -S . -B cmake.output -Werror=dev -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DUSE_MATCHCOMPILER=Verify -DANALYZE_THREAD=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=Off -DDISABLE_DMAKE=On -DFILESDIR= -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache env: - CC: clang-21 - CXX: clang++-21 + CC: clang-22 + CXX: clang++-22 - name: Build cppcheck run: | diff --git a/.github/workflows/ubsan.yml b/.github/workflows/ubsan.yml index 66c56b6966a..5afc5feb1f9 100644 --- a/.github/workflows/ubsan.yml +++ b/.github/workflows/ubsan.yml @@ -53,7 +53,7 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 21 + sudo ./llvm.sh 22 - name: Install Qt ${{ env.QT_VERSION }} uses: jurplel/install-qt-action@v4 @@ -75,8 +75,8 @@ jobs: run: | cmake -S . -B cmake.output -Werror=dev -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTING=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DUSE_MATCHCOMPILER=Verify -DANALYZE_UNDEFINED=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DFILESDIR= -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache env: - CC: clang-21 - CXX: clang++-21 + CC: clang-22 + CXX: clang++-22 - name: Build cppcheck run: | diff --git a/clang-tidy.md b/clang-tidy.md index aae6918e372..e6180b53d62 100644 --- a/clang-tidy.md +++ b/clang-tidy.md @@ -133,6 +133,7 @@ Does not improve the readability. `misc-unconventional-assign-operator`
`bugprone-throwing-static-initialization`
`bugprone-command-processor`
+`misc-multiple-inheritance`
To be evaluated (need to remove exclusion). @@ -163,6 +164,18 @@ We are not interested in this. Reports false positives - see https://github.com/llvm/llvm-project/issues/164125. +`readability-inconsistent-ifelse-braces`
+ +The suggestions are too intrusive. + +`modernize-avoid-c-style-cast`
+ +Currently flags functional casts - see https://github.com/llvm/llvm-project/issues/186784. + +`misc-use-internal-linkage.AnalyzeTypes`
+ +Adding anonymous namespaces requires identation which is too instrusive right now. Would require changes to our fomatting configuration. + ### Disabled for performance reasons `portability-std-allocator-const`
diff --git a/cmake/clang_tidy.cmake b/cmake/clang_tidy.cmake index a192fc13320..f8324b98d21 100644 --- a/cmake/clang_tidy.cmake +++ b/cmake/clang_tidy.cmake @@ -25,6 +25,12 @@ if(RUN_CLANG_TIDY_NAMES) endif() message(STATUS "NPROC=${NPROC}") + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 22) + set(CLANG_TIDY_CONFIG "-enable-check-profile") + else() + set(CLANG_TIDY_CONFIG "") + endif() + # most of these are disabled because they are too noisy in our code # clang-analyzer-core.CallAndMessage # clang-analyzer-core.NonNullParamChecker diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake index 348ad9f2674..aa7deb8552c 100644 --- a/cmake/compileroptions.cmake +++ b/cmake/compileroptions.cmake @@ -170,6 +170,12 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wno-weak-vtables) add_compile_options(-Wno-multichar) + # FIXME: only reported when running clang-tidy + # /home/runner/work/cppcheck/cppcheck/tools/triage/mainwindow.cpp:19:10: error: multiple candidates for header 'mainwindow.h' found; directory '/home/runner/work/cppcheck/cppcheck/tools/triage' chosen, ignoring others including '/home/runner/work/cppcheck/cppcheck/gui' [clang-diagnostic-shadow-header] + # 19 | #include "mainwindow.h" + # | ^ + add_compile_options_safe(-Wno-shadow-header) + if(ENABLE_COVERAGE OR ENABLE_COVERAGE_XML) message(FATAL_ERROR "Do not use clang to generate code coverage. Use GCC instead.") endif() diff --git a/lib/vf_common.cpp b/lib/vf_common.cpp index 934757edea4..46059985b0b 100644 --- a/lib/vf_common.cpp +++ b/lib/vf_common.cpp @@ -101,7 +101,7 @@ namespace ValueFlow return value; const MathLib::biguint unsignedMaxValue = std::numeric_limits::max() >> ((sizeof(unsignedMaxValue) - value_size) * 8); - const MathLib::biguint signBit = 1ULL << (value_size * 8 - 1); + const MathLib::biguint signBit = 1ULL << ((value_size * 8) - 1); value &= unsignedMaxValue; if (dst_sign == ValueType::Sign::SIGNED && (value & signBit)) value |= ~unsignedMaxValue; diff --git a/test/testcheckersreport.cpp b/test/testcheckersreport.cpp index 2d539ee77cf..85ef3547fd5 100644 --- a/test/testcheckersreport.cpp +++ b/test/testcheckersreport.cpp @@ -28,7 +28,7 @@ class TestCheckersReport : public TestFixture { public: TestCheckersReport() : TestFixture("TestCheckersReport") {} - +private: void run() final { // AddonInfo::checkers TEST_CASE(addonInfoCheckers); diff --git a/tools/triage/mainwindow.cpp b/tools/triage/mainwindow.cpp index ce95ff82d8d..8e5e4d39020 100644 --- a/tools/triage/mainwindow.cpp +++ b/tools/triage/mainwindow.cpp @@ -77,6 +77,7 @@ MainWindow::MainWindow(QWidget *parent) : srcFiles{"*.cpp", "*.cxx", "*.cc", "*.c++", "*.C", "*.c", "*.cl"} { ui->setupUi(this); + // NOLINTNEXTLINE(bugprone-random-generator-seed) - the random numbers are not used in a security context so this should be sufficient std::srand(static_cast(std::time(nullptr))); QDir workFolder(WORK_FOLDER); if (!workFolder.exists()) { From b52fd4803b890a67467a49a820f7ac5f91601697 Mon Sep 17 00:00:00 2001 From: olabetskyi <153490942+olabetskyi@users.noreply.github.com> Date: Tue, 17 Mar 2026 18:11:35 +0200 Subject: [PATCH 041/168] Fix #14606: Crash in Gui (#8346) --- gui/checkthread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp index fa5d68ba6d6..07ca4e77ed2 100644 --- a/gui/checkthread.cpp +++ b/gui/checkthread.cpp @@ -170,7 +170,7 @@ void CheckThread::run() const Details details{ mThreadIndex, QString::fromStdString(fname), QTime::currentTime(), }; emit startCheck(details); - cppcheck.check(*file); + cppcheck.check(*fileSettings); runAddonsAndTools(mSettings, fileSettings, QString::fromStdString(fname)); emit finishCheck(details); From b17b4edb2963d77ccafd803db077492999ae3e3c Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Thu, 19 Mar 2026 04:40:02 -0500 Subject: [PATCH 042/168] Disable matchcompiler on old python versions (#8352) --- cmake/findDependencies.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/findDependencies.cmake b/cmake/findDependencies.cmake index ddfef6718c2..b1f6571504d 100644 --- a/cmake/findDependencies.cmake +++ b/cmake/findDependencies.cmake @@ -49,7 +49,8 @@ if(NOT Python_Interpreter_FOUND) endif() else() if(${Python_VERSION} VERSION_LESS 3.7) - message(FATAL_ERROR "The minimum supported Python version is 3.7 - found ${Python_VERSION}") + message(WARNING "The minimum supported Python version is 3.7, found ${Python_VERSION} - disabling matchcompiler.") + set(USE_MATCHCOMPILER_OPT "Off") endif() endif() From 3a7e382990c0366d6cd956b1103422b18b35399c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 19 Mar 2026 10:40:53 +0100 Subject: [PATCH 043/168] Fix #11498 debug: Failed to parse 'x'. The checking continues anyway. (#8345) --- lib/tokenlist.cpp | 3 +++ test/testsimplifytemplate.cpp | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index a46fad5d021..7f7ca25aa5c 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -198,6 +198,7 @@ void TokenList::addtoken(const Token * tok, const nonneg int lineno, const nonne mTokensFrontBack->back->column(column); mTokensFrontBack->back->fileIndex(fileno); mTokensFrontBack->back->flags(tok->flags()); + mTokensFrontBack->back->tokType(tok->tokType()); } void TokenList::addtoken(const Token *tok, const Token *locationTok) @@ -219,6 +220,7 @@ void TokenList::addtoken(const Token *tok, const Token *locationTok) mTokensFrontBack->back->linenr(locationTok->linenr()); mTokensFrontBack->back->column(locationTok->column()); mTokensFrontBack->back->fileIndex(locationTok->fileIndex()); + mTokensFrontBack->back->tokType(tok->tokType()); } void TokenList::addtoken(const Token *tok) @@ -242,6 +244,7 @@ void TokenList::addtoken(const Token *tok) mTokensFrontBack->back->linenr(tok->linenr()); mTokensFrontBack->back->column(tok->column()); mTokensFrontBack->back->fileIndex(tok->fileIndex()); + mTokensFrontBack->back->tokType(tok->tokType()); } diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 2dda926fb40..66b2e022679 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -224,6 +224,7 @@ class TestSimplifyTemplate : public TestFixture { TEST_CASE(template180); TEST_CASE(template181); TEST_CASE(template182); // #13770 + TEST_CASE(template183); TEST_CASE(template_specialization_1); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_specialization_2); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_specialization_3); @@ -4678,6 +4679,25 @@ class TestSimplifyTemplate : public TestFixture { ASSERT_EQUALS(exp, tok(code)); } + void template183() { // #11498 + const char code[] = "template \n" + "struct S {\n" + " void f();\n" + " using X = decltype(&S::f);\n" + "private:\n" + " X x;\n" + "};\n" + "S s;\n"; + const char exp[] = "struct S ; " + "S s ; " + "struct S { " + "void f ( ) ; " + "private: " + "decltype ( & S :: f ) x ; " + "} ;"; + ASSERT_EQUALS(exp, tok(code)); + } + void template_specialization_1() { // #7868 - template specialization template struct S> {..}; const char code[] = "template struct C {};\n" "template struct S {a};\n" From 8119a9d99211a63089258ada082e6bffad8337ec Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 19 Mar 2026 18:31:50 +0100 Subject: [PATCH 044/168] Fix #13305 FN moduloofone with %= (#8353) --- lib/checkother.cpp | 2 +- test/testother.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index f051d231b69..698ef62e78b 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -4429,7 +4429,7 @@ void CheckOther::checkModuloOfOne() for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) { if (!tok->astOperand2() || !tok->astOperand1()) continue; - if (tok->str() != "%") + if (tok->str() != "%" && tok->str() != "%=") continue; if (!tok->valueType() || !tok->valueType()->isIntegral()) continue; diff --git a/test/testother.cpp b/test/testother.cpp index 241a7512000..d2f57bbb2a4 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -13284,6 +13284,13 @@ class TestOther : public TestFixture { " if (j % c) {}\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("void f() {\n" + " int i = 0;\n" + " i %= 1;\n" + " (void)i;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3:7]: (style) Modulo of one is always equal to zero [moduloofone]\n", errout_str()); } void sameExpressionPointers() { From 44128339d43824960341cb619053f7b42517d5ed Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 20 Mar 2026 08:27:05 +0100 Subject: [PATCH 045/168] Fix #14612 Internal error: "Cannot find end of expression" (#8354) --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a371df76e5d..20e3c6231f5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5544,7 +5544,7 @@ void Tokenizer::createLinks2() while (!type.empty() && type.top()->str() == "<") { const Token* end = type.top()->findClosingBracket(); - if (Token::Match(end, "> %comp%|;|.|=|{|(|::")) + if (Token::Match(end, "> %comp%|;|.|=|{|(|)|::")) break; // Variable declaration if (Token::Match(end, "> %var% ;") && (type.top()->tokAt(-2) == nullptr || Token::Match(type.top()->tokAt(-2), ";|}|{"))) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 16c9335dce7..dea8d08e57f 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -3829,6 +3829,19 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS(true, tok1->link() == tok2); ASSERT_EQUALS(true, tok2->link() == tok1); } + + { + const char code[] = "template \n" // #14612 + "void f(Fn && fn, Args&&... args) {\n" + " static_assert(std::is_invocable_v);\n" + "}\n"; + SimpleTokenizer tokenizer(settings0, *this); + ASSERT(tokenizer.tokenize(code)); + const Token* tok1 = Token::findsimplematch(tokenizer.tokens(), "< Fn"); + const Token* tok2 = Token::findsimplematch(tok1, "> )"); + ASSERT_EQUALS(true, tok1->link() == tok2); + ASSERT_EQUALS(true, tok2->link() == tok1); + } } void simplifyString() { From 0900f6400f94e8817968f0e5395d905cc33039d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Fri, 20 Mar 2026 14:01:55 +0100 Subject: [PATCH 046/168] fixed #13792 - release-windows.yml: use latest Python version [skip ci] (#8332) --- .github/workflows/release-windows.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/release-windows.yml b/.github/workflows/release-windows.yml index 1caa87b61e5..607c8434baa 100644 --- a/.github/workflows/release-windows.yml +++ b/.github/workflows/release-windows.yml @@ -25,6 +25,7 @@ jobs: if: ${{ github.repository_owner == 'danmar' }} env: + PYTHON_VERSION: 3.14 # see https://www.pcre.org/original/changelog.txt PCRE_VERSION: 8.45 QT_VERSION: 6.10.0 @@ -35,6 +36,12 @@ jobs: with: persist-credentials: false + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + check-latest: true + - name: Set up Visual Studio environment uses: ilammy/msvc-dev-cmd@v1 From 0a07f76bf782a743156c70584b7f206da0a666e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Fri, 20 Mar 2026 14:03:53 +0100 Subject: [PATCH 047/168] refs #14599 - Tokenizer: use `TimerResultsIntf` (#8348) --- lib/tokenize.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/tokenize.h b/lib/tokenize.h index 23669be7225..94f08f9f68e 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -34,7 +34,7 @@ class Settings; class SymbolDatabase; -class TimerResults; +class TimerResultsIntf; class Token; class TemplateSimplifier; class ErrorLogger; @@ -53,7 +53,7 @@ class CPPCHECKLIB Tokenizer { Tokenizer(TokenList tokenList, ErrorLogger &errorLogger); ~Tokenizer(); - void setTimerResults(TimerResults *tr) { + void setTimerResults(TimerResultsIntf *tr) { mTimerResults = tr; } @@ -713,9 +713,9 @@ class CPPCHECKLIB Tokenizer { nonneg int mUnnamedCount{}; /** - * TimerResults + * timer results */ - TimerResults* mTimerResults{}; + TimerResultsIntf* mTimerResults{}; }; /// @} From 498b2c6e428591fe1e3872b6c3848feb2f01e8ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Fri, 20 Mar 2026 14:07:58 +0100 Subject: [PATCH 048/168] refs #14599/#4452 - test/cli/other_test.py: improved `--showtime` tests (#8337) --- test/cli/other_test.py | 94 +++++++++++++++++++++++++++++++++--------- 1 file changed, 75 insertions(+), 19 deletions(-) diff --git a/test/cli/other_test.py b/test/cli/other_test.py index cc8b96badf1..2ff65efc052 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -954,33 +954,89 @@ def test_unused_function_include(tmpdir): __test_unused_function_include(tmpdir, []) -# TODO: test with all other types -def test_showtime_top5_file(tmpdir): - test_file = os.path.join(tmpdir, 'test.cpp') +# TODO: test with multiple files +def __test_showtime(tmp_path, showtime, exp_len, exp_last, extra_args=None): + test_file = tmp_path / 'test.cpp' with open(test_file, 'wt') as f: - f.write(""" - int main(int argc) - { - } - """) + f.write( +""" +void f() +{ + (void)(*((int*)0)); // cppcheck-suppress nullPointer +} +""") + + args = [ + f'--showtime={showtime}', + '--quiet', + '--inline-suppr', + str(test_file) + ] - args = ['--showtime=top5_file', '--quiet', test_file] + if extra_args: + args += extra_args exitcode, stdout, stderr = cppcheck(args) - assert exitcode == 0 # TODO: needs to be 1 + assert exitcode == 0 lines = stdout.splitlines() - assert len(lines) == 7 - assert lines[0] == '' - for i in range(1, 5): - if lines[i].startswith('valueFlowLifetime'): - assert lines[i].endswith(' - 2 result(s))') - elif lines[i].startswith('valueFlowEnumValue'): - assert lines[i].endswith(' - 2 result(s))') - else: - assert lines[i].endswith(' result(s))') + if 'cppcheck internal API usage' in stdout: + exp_len += 1 + assert len(lines) == exp_len + idx_last = exp_len-1 + if idx_last: + assert lines[0] == '' + for i in range(1, idx_last): + assert 'avg.' in lines[i] + assert lines[idx_last].startswith(exp_last) assert stderr == '' +def test_showtime_top5_file(tmp_path): + __test_showtime(tmp_path, 'top5_file', 7, 'Check time: ') + + +# TODO: remove extra args when --executor=process works works +def test_showtime_top5_summary(tmp_path): + __test_showtime(tmp_path, 'top5_summary', 7, 'Overall time: ', ['-j1']) + + +# TODO: remove when --executor=process works works +def test_showtime_top5_summary_j_thread(tmp_path): + __test_showtime(tmp_path, 'top5_summary', 7, 'Overall time: ', ['-j2', '--executor=thread']) + + +# TODO: remove override when fixed +@pytest.mark.skipif(sys.platform == 'win32', reason="requires ProcessExecutor") +@pytest.mark.xfail(strict=True) # TODO: need to transfer the timer results to parent process - see #4452 +def test_showtime_top5_summary_j_process(tmp_path): + __test_showtime(tmp_path, 'top5_summary', 7, 'Overall time: ', ['-j2', '--executor=process']) + + +def test_showtime_file(tmp_path): + __test_showtime(tmp_path, 'file', 79, 'Check time: ') + + +# TODO: remove extra args when --executor=process works works +def test_showtime_summary(tmp_path): + __test_showtime(tmp_path, 'summary', 79, 'Overall time: ', ['-j1']) + + +# TODO: remove when --executor=process works works +def test_showtime_summary_j_thread(tmp_path): + __test_showtime(tmp_path, 'summary', 79, 'Overall time: ', ['-j2', '--executor=thread']) + + +# TODO: remove override when fixed +@pytest.mark.skipif(sys.platform == 'win32', reason="requires ProcessExecutor") +@pytest.mark.xfail(strict=True) # TODO: need to transfer the timer results to parent process - see #4452 +def test_showtime_summary_j_process(tmp_path): + __test_showtime(tmp_path, 'summary', 79, 'Overall time: ', ['-j2', '--executor=process']) + + +def test_showtime_file_total(tmp_path): + __test_showtime(tmp_path, 'file-total', 1, 'Check time: ') + + def test_missing_addon(tmpdir): args = ['--addon=misra3', '--addon=misra', '--addon=misra2', 'file.c'] From c331d49373edd1f379af75b39e940eb824501e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Sun, 22 Mar 2026 18:01:30 +0100 Subject: [PATCH 049/168] prevent unnecessary `utils::as_const()` calls (#8316) --- cli/signalhandler.cpp | 2 +- lib/checkleakautovar.cpp | 2 +- lib/ctu.cpp | 2 +- lib/library.cpp | 6 +++--- lib/library.h | 8 ++++---- lib/settings.cpp | 12 ++++++------ lib/symboldatabase.cpp | 16 ++++++++-------- lib/tokenize.cpp | 12 ++++++------ lib/utils.h | 1 + 9 files changed, 31 insertions(+), 30 deletions(-) diff --git a/cli/signalhandler.cpp b/cli/signalhandler.cpp index 88864efd743..e1ea7f31267 100644 --- a/cli/signalhandler.cpp +++ b/cli/signalhandler.cpp @@ -124,7 +124,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context) / killid = getpid(); #endif - const auto it = utils::as_const(listofsignals).find(signo); + const auto it = listofsignals.find(signo); const char * const signame = (it==listofsignals.end()) ? "unknown" : it->second.c_str(); bool unexpectedSignal=true; // unexpected indicates program failure bool terminate=true; // exit process/thread diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 00c8492498a..bb80ead84a5 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -1163,7 +1163,7 @@ void CheckLeakAutoVar::leakIfAllocated(const Token *vartok, const std::map &alloctype = varInfo.alloctype; const auto& possibleUsage = varInfo.possibleUsage; - const auto var = utils::as_const(alloctype).find(vartok->varId()); + const auto var = alloctype.find(vartok->varId()); if (var != alloctype.cend() && var->second.status == VarInfo::ALLOC) { const auto use = possibleUsage.find(vartok->varId()); if (use == possibleUsage.end()) { diff --git a/lib/ctu.cpp b/lib/ctu.cpp index d1be82b34fa..938bb2a4dcc 100644 --- a/lib/ctu.cpp +++ b/lib/ctu.cpp @@ -512,7 +512,7 @@ static bool findPath(const std::string &callId, if (index >= maxCtuDepth) return false; // TODO: add bailout message? - const auto it = utils::as_const(callsMap).find(callId); + const auto it = callsMap.find(callId); if (it == callsMap.end()) return false; diff --git a/lib/library.cpp b/lib/library.cpp index 1628cc3cdcd..bd4a62d0a42 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -46,7 +46,7 @@ struct Library::LibraryData { struct Platform { const PlatformType *platform_type(const std::string &name) const { - const auto it = utils::as_const(mPlatformTypes).find(name); + const auto it = mPlatformTypes.find(name); return (it != mPlatformTypes.end()) ? &(it->second) : nullptr; } std::map mPlatformTypes; @@ -1323,10 +1323,10 @@ const Library::ArgumentChecks * Library::getarg(const Token *ftok, int argnr) co const Function* func = nullptr; if (isNotLibraryFunction(ftok, &func)) return nullptr; - const auto it2 = utils::as_const(func->argumentChecks).find(argnr); + const auto it2 = func->argumentChecks.find(argnr); if (it2 != func->argumentChecks.cend()) return &it2->second; - const auto it3 = utils::as_const(func->argumentChecks).find(-1); + const auto it3 = func->argumentChecks.find(-1); if (it3 != func->argumentChecks.cend()) return &it3->second; return nullptr; diff --git a/lib/library.h b/lib/library.h index dea9c1e66c7..10b9463cbaa 100644 --- a/lib/library.h +++ b/lib/library.h @@ -242,21 +242,21 @@ class CPPCHECKLIB Library { bool startPatternHasStd{}; Action getAction(const std::string& function) const { - const auto i = utils::as_const(functions).find(function); + const auto i = functions.find(function); if (i != functions.end()) return i->second.action; return Action::NO_ACTION; } Yield getYield(const std::string& function) const { - const auto i = utils::as_const(functions).find(function); + const auto i = functions.find(function); if (i != functions.end()) return i->second.yield; return Yield::NO_YIELD; } const std::string& getReturnType(const std::string& function) const { - const auto i = utils::as_const(functions).find(function); + const auto i = functions.find(function); return (i != functions.end()) ? i->second.returnType : mEmptyString; } @@ -482,7 +482,7 @@ class CPPCHECKLIB Library { std::string getFunctionName(const Token *ftok, bool &error) const; static const AllocFunc* getAllocDealloc(const std::map &data, const std::string &name) { - const auto it = utils::as_const(data).find(name); + const auto it = data.find(name); return (it == data.end()) ? nullptr : &it->second; } diff --git a/lib/settings.cpp b/lib/settings.cpp index 645488260b0..cd1f094e1c1 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -109,7 +109,7 @@ std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppress } const picojson::object& obj = json.get(); { - const auto it = utils::as_const(obj).find("productName"); + const auto it = obj.find("productName"); if (it != obj.cend()) { const auto& v = it->second; if (!v.is()) @@ -118,7 +118,7 @@ std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppress } } { - const auto it = utils::as_const(obj).find("manualUrl"); + const auto it = obj.find("manualUrl"); if (it != obj.cend()) { const auto& v = it->second; if (!v.is()) @@ -127,7 +127,7 @@ std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppress } } { - const auto it = utils::as_const(obj).find("about"); + const auto it = obj.find("about"); if (it != obj.cend()) { const auto& v = it->second; if (!v.is()) @@ -136,7 +136,7 @@ std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppress } } { - const auto it = utils::as_const(obj).find("addons"); + const auto it = obj.find("addons"); if (it != obj.cend()) { const auto& entry = it->second; if (!entry.is()) @@ -154,7 +154,7 @@ std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppress } } { - const auto it = utils::as_const(obj).find("suppressions"); + const auto it = obj.find("suppressions"); if (it != obj.cend()) { const auto& entry = it->second; if (!entry.is()) @@ -171,7 +171,7 @@ std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppress } } { - const auto it = utils::as_const(obj).find("safety"); + const auto it = obj.find("safety"); if (it != obj.cend()) { const auto& v = it->second; if (!v.is()) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 9748959ba53..c9851d6e7ca 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3864,7 +3864,7 @@ void SymbolDatabase::returnImplicitIntError(const Token *tok) const const Function* Type::getFunction(const std::string& funcName) const { if (classScope) { - const auto it = utils::as_const(classScope->functionMap).find(funcName); + const auto it = classScope->functionMap.find(funcName); if (it != classScope->functionMap.end()) return it->second; } @@ -4838,7 +4838,7 @@ std::vector Function::getOverloadedFunctions() const while (scope) { const bool isMemberFunction = scope->isClassOrStruct() && !isStatic(); - for (auto it = utils::as_const(scope->functionMap).find(tokenDef->str()); + for (auto it = scope->functionMap.find(tokenDef->str()); it != scope->functionMap.end() && it->first == tokenDef->str(); ++it) { const Function* func = it->second; @@ -4889,7 +4889,7 @@ const Function * Function::getOverriddenFunctionRecursive(const ::Type* baseType const Scope *parent = derivedFromType->classScope; // check if function defined in base class - auto range = utils::as_const(parent->functionMap).equal_range(tokenDef->str()); + auto range = parent->functionMap.equal_range(tokenDef->str()); for (auto it = range.first; it != range.second; ++it) { const Function * func = it->second; if (func->isImplicitlyVirtual()) { // Base is virtual and of same name @@ -5836,7 +5836,7 @@ void Scope::findFunctionInBase(const Token* tok, nonneg int args, std::vectorclassScope == this) // Ticket #5120, #5125: Recursive class; tok should have been found already continue; - auto range = utils::as_const(base->classScope->functionMap).equal_range(tok->str()); + auto range = base->classScope->functionMap.equal_range(tok->str()); for (auto it = range.first; it != range.second; ++it) { const Function *func = it->second; if (func->isDestructor() && !Token::simpleMatch(tok->tokAt(-1), "~")) @@ -5998,7 +5998,7 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst, Referen const std::size_t args = arguments.size(); auto addMatchingFunctions = [&](const Scope *scope) { - auto range = utils::as_const(scope->functionMap).equal_range(tok->str()); + auto range = scope->functionMap.equal_range(tok->str()); for (auto it = range.first; it != range.second; ++it) { const Function *func = it->second; if (ref == Reference::LValue && func->hasRvalRefQualifier()) @@ -6766,7 +6766,7 @@ Function * SymbolDatabase::findFunctionInScope(const Token *func, const Scope *n const Function * function = nullptr; const bool destructor = func->strAt(-1) == "~"; - auto range = utils::as_const(ns->functionMap).equal_range(func->str()); + auto range = ns->functionMap.equal_range(func->str()); for (auto it = range.first; it != range.second; ++it) { if (it->second->argsMatch(ns, it->second->argDef, func->next(), path, path_length) && it->second->isDestructor() == destructor) { @@ -7685,14 +7685,14 @@ static const Function *getOperatorFunction(const Token * const tok) const Scope *classScope = getClassScope(tok->astOperand1()); if (classScope) { - auto it = utils::as_const(classScope->functionMap).find(functionName); + auto it = classScope->functionMap.find(functionName); if (it != classScope->functionMap.end()) return it->second; } classScope = getClassScope(tok->astOperand2()); if (classScope) { - auto it = utils::as_const(classScope->functionMap).find(functionName); + auto it = classScope->functionMap.find(functionName); if (it != classScope->functionMap.end()) return it->second; } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 20e3c6231f5..b485b3fb2cc 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -135,7 +135,7 @@ Tokenizer::~Tokenizer() nonneg int Tokenizer::sizeOfType(const std::string& type) const { - const auto it = utils::as_const(mTypeSize).find(type); + const auto it = mTypeSize.find(type); if (it == mTypeSize.end()) { const Library::PodType* podtype = mSettings.library.podtype(type); if (!podtype) @@ -154,7 +154,7 @@ nonneg int Tokenizer::sizeOfType(const Token *type) const if (type->tokType() == Token::eString) return Token::getStrLength(type) + 1U; - const auto it = utils::as_const(mTypeSize).find(type->str()); + const auto it = mTypeSize.find(type->str()); if (it == mTypeSize.end()) { const Library::PodType* podtype = mSettings.library.podtype(type->str()); if (!podtype) @@ -4630,7 +4630,7 @@ void Tokenizer::setVarIdClassFunction(const std::string &classname, if (Token::Match(tok2, "%name% ::")) continue; - const auto it = utils::as_const(varlist).find(tok2->str()); + const auto it = varlist.find(tok2->str()); if (it != varlist.end()) { tok2->varId(it->second); setVarIdStructMembers(tok2, structMembers, varId_); @@ -7800,7 +7800,7 @@ bool Tokenizer::simplifyCAlternativeTokens() if (!tok->isName()) continue; - const auto cOpIt = utils::as_const(cAlternativeTokens).find(tok->str()); + const auto cOpIt = cAlternativeTokens.find(tok->str()); if (cOpIt != cAlternativeTokens.end()) { alt.push_back(tok); @@ -7842,7 +7842,7 @@ bool Tokenizer::simplifyCAlternativeTokens() return false; for (Token *tok: alt) { - const auto cOpIt = utils::as_const(cAlternativeTokens).find(tok->str()); + const auto cOpIt = cAlternativeTokens.find(tok->str()); if (cOpIt != cAlternativeTokens.end()) tok->str(cOpIt->second); else if (tok->str() == "not") @@ -10452,7 +10452,7 @@ void Tokenizer::simplifyMicrosoftStringFunctions() if (tok->strAt(1) != "(") continue; - const auto match = utils::as_const(apis).find(tok->str()); + const auto match = apis.find(tok->str()); if (match!=apis.end()) { tok->str(ansi ? match->second.mbcs : match->second.unicode); tok->originalName(match->first); diff --git a/lib/utils.h b/lib/utils.h index 5a6927a5d96..6f410af3dbc 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -418,6 +418,7 @@ namespace utils { template constexpr typename std::add_const::type & as_const(T& t) noexcept { + static_assert(!std::is_const::value, "object is already const"); // NOLINTNEXTLINE(bugprone-return-const-ref-from-parameter) - potential false positive return t; } From bb948d2368918fca257b07a69d0db56ad53a6d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Mon, 23 Mar 2026 11:15:43 +0100 Subject: [PATCH 050/168] TestTokenizer: reduced amount of `settingsBuilder().build()` calls (#8367) --- test/testtokenize.cpp | 155 ++++++++++++++++++++---------------------- 1 file changed, 73 insertions(+), 82 deletions(-) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index dea8d08e57f..f78899820b2 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -47,10 +47,17 @@ class TestTokenizer : public TestFixture { private: const Settings settings0 = settingsBuilder().library("qt.cfg").build(); - const Settings settings1 = settingsBuilder().library("qt.cfg").library("std.cfg").debugwarnings().build(); + const Settings settings1 = settingsBuilder().library("std.cfg").library("qt.cfg").debugwarnings().build(); const Settings settings2 = settingsBuilder(settings1).cpp(Standards::CPP11).c(Standards::C11).build(); + const Settings settings2_win32a = settingsBuilder(settings2).platform(Platform::Type::Win32A).build(); + const Settings settings2_win32w = settingsBuilder(settings2).platform(Platform::Type::Win32W).build(); + const Settings settings2_win64 = settingsBuilder(settings2).platform(Platform::Type::Win64).build(); + const Settings settings2_unix32 = settingsBuilder(settings2).platform(Platform::Type::Unix32).build(); + const Settings settings2_unix64 = settingsBuilder(settings2).platform(Platform::Type::Unix64).build(); const Settings settings3 = settingsBuilder(settings0).c(Standards::C89).cpp(Standards::CPP03).build(); const Settings settings_windows = settingsBuilder().library("windows.cfg").debugwarnings().cpp(Standards::CPP11).build(); + const Settings settings_win32a = settingsBuilder(settings_windows).platform(Platform::Type::Win32A).build(); + const Settings settings_win32w = settingsBuilder(settings_windows).platform(Platform::Type::Win32W).build(); void run() override { mNewTemplate = true; @@ -535,19 +542,14 @@ class TestTokenizer : public TestFixture { struct TokenizeOptions { bool expand = true; - Platform::Type platform = Platform::Type::Native; bool cpp = true; - Standards::cppstd_t cppstd = Standards::CPP11; - Standards::cstd_t cstd = Standards::C11; }; #define tokenizeAndStringify(...) tokenizeAndStringify_(__FILE__, __LINE__, __VA_ARGS__) template std::string tokenizeAndStringify_(const char* file, int linenr, const char (&code)[size], const TokenizeOptions& opt = make_default_obj{}) { - const Settings settings = settingsBuilder(settings1).cpp(opt.cppstd).c(opt.cstd).platform(opt.platform).build(); - // tokenize.. - SimpleTokenizer tokenizer(settings, *this, opt.cpp); + SimpleTokenizer tokenizer(settings2, *this, opt.cpp); ASSERT_LOC(tokenizer.tokenize(code), file, linenr); if (tokenizer.tokens()) @@ -566,27 +568,13 @@ class TestTokenizer : public TestFixture { } template - std::string tokenizeAndStringify_(const char* file, int line, const char (&code)[size], const Settings &settings, bool cpp = true) { + std::string tokenizeAndStringify_(const char* file, int line, const char (&code)[size], const Settings &settings, bool cpp = true, bool expand = true) { // tokenize.. SimpleTokenizer tokenizer(settings, *this, cpp); ASSERT_LOC(tokenizer.tokenize(code), file, line); if (!tokenizer.tokens()) return ""; - return tokenizer.tokens()->stringifyList(false, true, false, true, false, nullptr, nullptr); - } - -#define tokenizeAndStringifyWindows(...) tokenizeAndStringifyWindows_(__FILE__, __LINE__, __VA_ARGS__) - template - std::string tokenizeAndStringifyWindows_(const char* file, int linenr, const char (&code)[size], Platform::Type platform = Platform::Type::Native) { - const Settings settings = settingsBuilder(settings_windows).platform(platform).build(); - - // tokenize.. - SimpleTokenizer tokenizer(settings, *this); - ASSERT_LOC(tokenizer.tokenize(code), file, linenr); - - if (tokenizer.tokens()) - return tokenizer.tokens()->stringifyList(false, true, false, true, false, nullptr, nullptr); - return ""; + return tokenizer.tokens()->stringifyList(false, expand, false, true, false, nullptr, nullptr); } #define tokenizeDebugListing(...) tokenizeDebugListing_(__FILE__, __LINE__, __VA_ARGS__) @@ -2032,7 +2020,7 @@ class TestTokenizer : public TestFixture { const char code[] = "struct foo {\n" " void operator delete(void *obj, size_t sz);\n" "}\n"; - const std::string actual(tokenizeAndStringify(code, dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + const std::string actual(tokenizeAndStringify(code, settings2_win32a)); const char expected[] = "struct foo {\n" "void operatordelete ( void * obj , unsigned long sz ) ;\n" @@ -2568,8 +2556,9 @@ class TestTokenizer : public TestFixture { } void vardecl14() { + const Settings s = settingsBuilder(settings1).cpp(Standards::CPP03).build(); const char code[] = "::std::tr1::shared_ptr pNum1, pNum2;\n"; - ASSERT_EQUALS(":: std :: tr1 :: shared_ptr < int > pNum1 ; :: std :: tr1 :: shared_ptr < int > pNum2 ;", tokenizeAndStringify(code, dinit(TokenizeOptions, $.expand = false, $.cppstd = Standards::CPP03))); + ASSERT_EQUALS(":: std :: tr1 :: shared_ptr < int > pNum1 ; :: std :: tr1 :: shared_ptr < int > pNum2 ;", tokenizeAndStringify(code, s, true, false)); } void vardecl15() { @@ -4820,16 +4809,16 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("struct A { long x ; } ;", tokenizeAndStringify(code5)); const char code6[] = "struct A { __int8 x : 3; };"; - ASSERT_EQUALS("struct A { char x ; } ;", tokenizeAndStringifyWindows(code6, Platform::Type::Win32A)); + ASSERT_EQUALS("struct A { char x ; } ;", tokenizeAndStringify(code6, settings_win32a)); const char code7[] = "struct A { __int16 x : 3; };"; - ASSERT_EQUALS("struct A { short x ; } ;", tokenizeAndStringifyWindows(code7, Platform::Type::Win32A)); + ASSERT_EQUALS("struct A { short x ; } ;", tokenizeAndStringify(code7,settings_win32a)); const char code8[] = "struct A { __int32 x : 3; };"; - ASSERT_EQUALS("struct A { int x ; } ;", tokenizeAndStringifyWindows(code8, Platform::Type::Win32A)); + ASSERT_EQUALS("struct A { int x ; } ;", tokenizeAndStringify(code8, settings_win32a)); const char code9[] = "struct A { __int64 x : 3; };"; - ASSERT_EQUALS("struct A { long long x ; } ;", tokenizeAndStringifyWindows(code9, Platform::Type::Win32A)); + ASSERT_EQUALS("struct A { long long x ; } ;", tokenizeAndStringify(code9, settings_win32a)); const char code10[] = "struct A { unsigned char x : 3; };"; ASSERT_EQUALS("struct A { unsigned char x ; } ;", tokenizeAndStringify(code10)); @@ -4844,16 +4833,16 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("struct A { unsigned long x ; } ;", tokenizeAndStringify(code13)); const char code14[] = "struct A { unsigned __int8 x : 3; };"; - ASSERT_EQUALS("struct A { unsigned char x ; } ;", tokenizeAndStringifyWindows(code14, Platform::Type::Win32A)); + ASSERT_EQUALS("struct A { unsigned char x ; } ;", tokenizeAndStringify(code14, settings_win32a)); const char code15[] = "struct A { unsigned __int16 x : 3; };"; - ASSERT_EQUALS("struct A { unsigned short x ; } ;", tokenizeAndStringifyWindows(code15, Platform::Type::Win32A)); + ASSERT_EQUALS("struct A { unsigned short x ; } ;", tokenizeAndStringify(code15, settings_win32a)); const char code16[] = "struct A { unsigned __int32 x : 3; };"; - ASSERT_EQUALS("struct A { unsigned int x ; } ;", tokenizeAndStringifyWindows(code16, Platform::Type::Win32A)); + ASSERT_EQUALS("struct A { unsigned int x ; } ;", tokenizeAndStringify(code16, settings_win32a)); const char code17[] = "struct A { unsigned __int64 x : 3; };"; - ASSERT_EQUALS("struct A { unsigned long long x ; } ;", tokenizeAndStringifyWindows(code17, Platform::Type::Win32A)); + ASSERT_EQUALS("struct A { unsigned long long x ; } ;", tokenizeAndStringify(code17, settings_win32a)); const char code18[] = "struct A { signed char x : 3; };"; ASSERT_EQUALS("struct A { signed char x ; } ;", tokenizeAndStringify(code18)); @@ -4865,19 +4854,19 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("struct A { signed int x ; } ;", tokenizeAndStringify(code20)); const char code21[] = "struct A { signed long x : 3; };"; - ASSERT_EQUALS("struct A { signed long x ; } ;", tokenizeAndStringifyWindows(code21)); + ASSERT_EQUALS("struct A { signed long x ; } ;", tokenizeAndStringify(code21, settings_windows)); const char code22[] = "struct A { signed __int8 x : 3; };"; - ASSERT_EQUALS("struct A { signed char x ; } ;", tokenizeAndStringifyWindows(code22, Platform::Type::Win32A)); + ASSERT_EQUALS("struct A { signed char x ; } ;", tokenizeAndStringify(code22, settings_win32a)); const char code23[] = "struct A { signed __int16 x : 3; };"; - ASSERT_EQUALS("struct A { signed short x ; } ;", tokenizeAndStringifyWindows(code23, Platform::Type::Win32A)); + ASSERT_EQUALS("struct A { signed short x ; } ;", tokenizeAndStringify(code23, settings_win32a)); const char code24[] = "struct A { signed __int32 x : 3; };"; - ASSERT_EQUALS("struct A { signed int x ; } ;", tokenizeAndStringifyWindows(code24, Platform::Type::Win32A)); + ASSERT_EQUALS("struct A { signed int x ; } ;", tokenizeAndStringify(code24, settings_win32a)); const char code25[] = "struct A { signed __int64 x : 3; };"; - ASSERT_EQUALS("struct A { signed long long x ; } ;", tokenizeAndStringifyWindows(code25, Platform::Type::Win32A)); + ASSERT_EQUALS("struct A { signed long long x ; } ;", tokenizeAndStringify(code25, settings_win32a)); } void bitfields2() { @@ -5301,72 +5290,72 @@ class TestTokenizer : public TestFixture { void microsoftMemory() { const char code1a[] = "void foo() { int a[10], b[10]; CopyMemory(a, b, sizeof(a)); }"; - ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memcpy ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code1a,dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memcpy ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code1a,settings2_win32a)); const char code1b[] = "void foo() { int a[10], b[10]; RtlCopyMemory(a, b, sizeof(a)); }"; - ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memcpy ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code1b,dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memcpy ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code1b,settings2_win32a)); const char code1c[] = "void foo() { int a[10], b[10]; RtlCopyBytes(a, b, sizeof(a)); }"; - ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memcpy ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code1c,dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memcpy ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code1c,settings2_win32a)); const char code2a[] = "void foo() { int a[10]; FillMemory(a, sizeof(a), 255); }"; - ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 255 , sizeof ( a ) ) ; }", tokenizeAndStringify(code2a,dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 255 , sizeof ( a ) ) ; }", tokenizeAndStringify(code2a,settings2_win32a)); const char code2b[] = "void foo() { int a[10]; RtlFillMemory(a, sizeof(a), 255); }"; - ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 255 , sizeof ( a ) ) ; }", tokenizeAndStringify(code2b,dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 255 , sizeof ( a ) ) ; }", tokenizeAndStringify(code2b,settings2_win32a)); const char code2c[] = "void foo() { int a[10]; RtlFillBytes(a, sizeof(a), 255); }"; - ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 255 , sizeof ( a ) ) ; }", tokenizeAndStringify(code2c,dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 255 , sizeof ( a ) ) ; }", tokenizeAndStringify(code2c,settings2_win32a)); const char code3a[] = "void foo() { int a[10], b[10]; MoveMemory(a, b, sizeof(a)); }"; - ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memmove ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code3a,dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memmove ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code3a,settings2_win32a)); const char code3b[] = "void foo() { int a[10], b[10]; RtlMoveMemory(a, b, sizeof(a)); }"; - ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memmove ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code3b,dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memmove ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code3b,settings2_win32a)); const char code4a[] = "void foo() { int a[10]; ZeroMemory(a, sizeof(a)); }"; - ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 0 , sizeof ( a ) ) ; }", tokenizeAndStringify(code4a,dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 0 , sizeof ( a ) ) ; }", tokenizeAndStringify(code4a,settings2_win32a)); const char code4b[] = "void foo() { int a[10]; RtlZeroMemory(a, sizeof(a)); }"; - ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 0 , sizeof ( a ) ) ; }", tokenizeAndStringify(code4b,dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 0 , sizeof ( a ) ) ; }", tokenizeAndStringify(code4b,settings2_win32a)); const char code4c[] = "void foo() { int a[10]; RtlZeroBytes(a, sizeof(a)); }"; - ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 0 , sizeof ( a ) ) ; }", tokenizeAndStringify(code4c,dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 0 , sizeof ( a ) ) ; }", tokenizeAndStringify(code4c,settings2_win32a)); const char code4d[] = "void foo() { int a[10]; RtlSecureZeroMemory(a, sizeof(a)); }"; - ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 0 , sizeof ( a ) ) ; }", tokenizeAndStringify(code4d,dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 0 , sizeof ( a ) ) ; }", tokenizeAndStringify(code4d,settings2_win32a)); const char code5[] = "void foo() { int a[10], b[10]; RtlCompareMemory(a, b, sizeof(a)); }"; - ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memcmp ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code5,dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memcmp ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code5,settings2_win32a)); const char code6[] = "void foo() { ZeroMemory(f(1, g(a, b)), h(i, j(0, 1))); }"; - ASSERT_EQUALS("void foo ( ) { memset ( f ( 1 , g ( a , b ) ) , 0 , h ( i , j ( 0 , 1 ) ) ) ; }", tokenizeAndStringify(code6,dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { memset ( f ( 1 , g ( a , b ) ) , 0 , h ( i , j ( 0 , 1 ) ) ) ; }", tokenizeAndStringify(code6,settings2_win32a)); const char code7[] = "void foo() { FillMemory(f(1, g(a, b)), h(i, j(0, 1)), 255); }"; - ASSERT_EQUALS("void foo ( ) { memset ( f ( 1 , g ( a , b ) ) , 255 , h ( i , j ( 0 , 1 ) ) ) ; }", tokenizeAndStringify(code7,dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { memset ( f ( 1 , g ( a , b ) ) , 255 , h ( i , j ( 0 , 1 ) ) ) ; }", tokenizeAndStringify(code7,settings2_win32a)); } void microsoftString() { const char code1a[] = "void foo() { _tprintf (_T(\"test\") _T(\"1\")); }"; - ASSERT_EQUALS("void foo ( ) { printf ( \"test1\" ) ; }", tokenizeAndStringify(code1a, dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { printf ( \"test1\" ) ; }", tokenizeAndStringify(code1a, settings2_win32a)); const char code1b[] = "void foo() { _tprintf (_TEXT(\"test\") _TEXT(\"2\")); }"; - ASSERT_EQUALS("void foo ( ) { printf ( \"test2\" ) ; }", tokenizeAndStringify(code1b, dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { printf ( \"test2\" ) ; }", tokenizeAndStringify(code1b, settings2_win32a)); const char code1c[] = "void foo() { _tprintf (TEXT(\"test\") TEXT(\"3\")); }"; - ASSERT_EQUALS("void foo ( ) { printf ( \"test3\" ) ; }", tokenizeAndStringify(code1c, dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + ASSERT_EQUALS("void foo ( ) { printf ( \"test3\" ) ; }", tokenizeAndStringify(code1c, settings2_win32a)); const char code2a[] = "void foo() { _tprintf (_T(\"test\") _T(\"1\")); }"; - ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test1\" ) ; }", tokenizeAndStringify(code2a, dinit(TokenizeOptions, $.platform = Platform::Type::Win32W))); - ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test1\" ) ; }", tokenizeAndStringify(code2a, dinit(TokenizeOptions, $.platform = Platform::Type::Win64))); + ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test1\" ) ; }", tokenizeAndStringify(code2a, settings2_win32w)); + ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test1\" ) ; }", tokenizeAndStringify(code2a, settings2_win64)); const char code2b[] = "void foo() { _tprintf (_TEXT(\"test\") _TEXT(\"2\")); }"; - ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test2\" ) ; }", tokenizeAndStringify(code2b, dinit(TokenizeOptions, $.platform = Platform::Type::Win32W))); - ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test2\" ) ; }", tokenizeAndStringify(code2b, dinit(TokenizeOptions, $.platform = Platform::Type::Win64))); + ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test2\" ) ; }", tokenizeAndStringify(code2b, settings2_win32w)); + ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test2\" ) ; }", tokenizeAndStringify(code2b, settings2_win64)); const char code2c[] = "void foo() { _tprintf (TEXT(\"test\") TEXT(\"3\")); }"; - ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test3\" ) ; }", tokenizeAndStringify(code2c, dinit(TokenizeOptions, $.platform = Platform::Type::Win32W))); - ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test3\" ) ; }", tokenizeAndStringify(code2c, dinit(TokenizeOptions, $.platform = Platform::Type::Win64))); + ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test3\" ) ; }", tokenizeAndStringify(code2c, settings2_win32w)); + ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test3\" ) ; }", tokenizeAndStringify(code2c, settings2_win64)); } void borland() { // __closure ASSERT_EQUALS("int ( * a ) ( ) ;", // TODO VarId - tokenizeAndStringify("int (__closure *a)();", dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + tokenizeAndStringify("int (__closure *a)();", settings2_win32a)); // __property ASSERT_EQUALS("class Fred { ; __property ; } ;", - tokenizeAndStringify("class Fred { __property int x = { } };", dinit(TokenizeOptions, $.platform = Platform::Type::Win32A))); + tokenizeAndStringify("class Fred { __property int x = { } };", settings2_win32a)); } void simplifySQL() { @@ -6149,10 +6138,10 @@ class TestTokenizer : public TestFixture { "float * ptrToFloat ;"; // These types should be defined the same on all Windows platforms - const std::string win32A = tokenizeAndStringifyWindows(code, Platform::Type::Win32A); + const std::string win32A = tokenizeAndStringify(code, settings_win32a); ASSERT_EQUALS(expected, win32A); - ASSERT_EQUALS(win32A, tokenizeAndStringifyWindows(code, Platform::Type::Win32W)); - ASSERT_EQUALS(win32A, tokenizeAndStringifyWindows(code, Platform::Type::Win64)); + ASSERT_EQUALS(win32A, tokenizeAndStringify(code, settings_win32w)); + ASSERT_EQUALS(win32A, tokenizeAndStringify(code, settings_win32a)); } void platformWin32A() { @@ -6198,13 +6187,13 @@ class TestTokenizer : public TestFixture { "sscanf ( dst , \"%s\" , dst ) ; " "} " "unsigned char tbyte ;"; - ASSERT_EQUALS(expected, tokenizeAndStringifyWindows(code, Platform::Type::Win32A)); + ASSERT_EQUALS(expected, tokenizeAndStringify(code, settings_win32a)); const char code2[] = "LPCTSTR f(void* p) { return LPCTSTR(p); }\n" // #11430 "LPCTSTR g() { return LPCTSTR{}; }"; const char expected2[] = "const char * f ( void * p ) { return ( const char * ) ( p ) ; }\n" "const char * g ( ) { return ( const char * ) ( 0 ) ; }"; - ASSERT_EQUALS(expected2, tokenizeAndStringifyWindows(code2, Platform::Type::Win32A)); + ASSERT_EQUALS(expected2, tokenizeAndStringify(code2, settings_win32a)); } void platformWin32W() { @@ -6250,29 +6239,29 @@ class TestTokenizer : public TestFixture { "wscanf ( L\"%s\" , dst ) ; " "swscanf ( dst , L\"%s\" , dst ) ; " "}"; - ASSERT_EQUALS(expected, tokenizeAndStringifyWindows(code, Platform::Type::Win32W)); + ASSERT_EQUALS(expected, tokenizeAndStringify(code, settings_win32w)); } void platformWin32AStringCat() { //#5150 const char code[] = "TCHAR text[] = _T(\"123\") _T(\"456\") _T(\"789\");"; const char expected[] = "char text [ 10 ] = \"123456789\" ;"; - ASSERT_EQUALS(expected, tokenizeAndStringifyWindows(code, Platform::Type::Win32A)); + ASSERT_EQUALS(expected, tokenizeAndStringify(code, settings_win32a)); } void platformWin32WStringCat() { //#5150 const char code[] = "TCHAR text[] = _T(\"123\") _T(\"456\") _T(\"789\");"; const char expected[] = "wchar_t text [ 10 ] = L\"123456789\" ;"; - ASSERT_EQUALS(expected, tokenizeAndStringifyWindows(code, Platform::Type::Win32W)); + ASSERT_EQUALS(expected, tokenizeAndStringify(code, settings_win32w)); } void platformWinWithNamespace() { const char code1[] = "UINT32 a; ::UINT32 b; foo::UINT32 c;"; const char expected1[] = "unsigned int a ; unsigned int b ; foo :: UINT32 c ;"; - ASSERT_EQUALS(expected1, tokenizeAndStringifyWindows(code1, Platform::Type::Win32A)); + ASSERT_EQUALS(expected1, tokenizeAndStringify(code1, settings_win32a)); const char code2[] = "LPCVOID a; ::LPCVOID b; foo::LPCVOID c;"; const char expected2[] = "const void * a ; const void * b ; foo :: LPCVOID c ;"; - ASSERT_EQUALS(expected2, tokenizeAndStringifyWindows(code2, Platform::Type::Win32A)); + ASSERT_EQUALS(expected2, tokenizeAndStringify(code2, settings_win32w)); } void isOneNumber() const { @@ -6417,8 +6406,9 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("int func1 ( ) ;", tokenizeAndStringify("[[clang::optnone]] [[nodiscard]] int func1();")); + const Settings s = settingsBuilder(settings1).c(Standards::C23).build(); ASSERT_EQUALS("void f ( int i ) { exit ( i ) ; }", - tokenizeAndStringify("[[noreturn]] void f(int i) { exit(i); }", dinit(TokenizeOptions, $.cpp = false, $.cstd = Standards::C23))); + tokenizeAndStringify("[[noreturn]] void f(int i) { exit(i); }", s, false)); } void simplifyCaseRange() { @@ -7308,6 +7298,7 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("", errout_str()); // #11128 + const Settings s = settingsBuilder(settings1).cpp(Standards::CPP17).build(); ASSERT_NO_THROW(tokenizeAndStringify("template \n" "struct S;\n" "struct R;\n" @@ -7317,7 +7308,7 @@ class TestTokenizer : public TestFixture { " return y;\n" " else\n" " return z;\n" - "}\n", dinit(TokenizeOptions, $.cppstd = Standards::CPP17))); + "}\n", s)); ignore_errout(); // #10079 - createInnerAST bug.. @@ -8926,18 +8917,18 @@ class TestTokenizer : public TestFixture { void simplifyPlatformTypes() { { const char code[] = "size_t f();"; - ASSERT_EQUALS("unsigned long f ( ) ;", tokenizeAndStringify(code, dinit(TokenizeOptions, $.platform = Platform::Type::Unix32))); - ASSERT_EQUALS("unsigned long f ( ) ;", tokenizeAndStringify(code, dinit(TokenizeOptions, $.platform = Platform::Type::Unix64))); + ASSERT_EQUALS("unsigned long f ( ) ;", tokenizeAndStringify(code, settings2_unix32)); + ASSERT_EQUALS("unsigned long f ( ) ;", tokenizeAndStringify(code, settings2_unix64)); } { const char code[] = "ssize_t f();"; - ASSERT_EQUALS("long f ( ) ;", tokenizeAndStringify(code, dinit(TokenizeOptions, $.platform = Platform::Type::Unix32))); - ASSERT_EQUALS("long f ( ) ;", tokenizeAndStringify(code, dinit(TokenizeOptions, $.platform = Platform::Type::Unix64))); + ASSERT_EQUALS("long f ( ) ;", tokenizeAndStringify(code, settings2_unix32)); + ASSERT_EQUALS("long f ( ) ;", tokenizeAndStringify(code, settings2_unix64)); } { const char code[] = "std::ptrdiff_t f();"; - ASSERT_EQUALS("long f ( ) ;", tokenizeAndStringify(code, dinit(TokenizeOptions, $.platform = Platform::Type::Unix32))); - ASSERT_EQUALS("long f ( ) ;", tokenizeAndStringify(code, dinit(TokenizeOptions, $.platform = Platform::Type::Unix64))); + ASSERT_EQUALS("long f ( ) ;", tokenizeAndStringify(code, settings2_unix32)); + ASSERT_EQUALS("long f ( ) ;", tokenizeAndStringify(code, settings2_unix64)); } } From 5bec5624f677636d38803d3a9fc152bcc5923fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Mon, 23 Mar 2026 11:21:03 +0100 Subject: [PATCH 051/168] library.cpp: use `std::unordered_map` for some `Library::LibraryData` members (#8363) --- lib/library.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/library.cpp b/lib/library.cpp index bd4a62d0a42..efba862eb15 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -123,9 +123,9 @@ struct Library::LibraryData std::map mDealloc; // deallocation functions std::map mRealloc; // reallocation functions std::unordered_map mNoReturn; // is function noreturn? - std::map mReturnValue; - std::map mReturnValueType; - std::map mReturnValueContainer; + std::unordered_map mReturnValue; + std::unordered_map mReturnValueType; + std::unordered_map mReturnValueContainer; std::map> mUnknownReturnValues; std::map mReportErrors; std::map mProcessAfterCode; From f68416390189250aaa99e884b4994ab8e50c1c50 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 23 Mar 2026 11:41:27 +0100 Subject: [PATCH 052/168] Fix #12699 QDir functions missing from qt.cfg (#8349) Continuation of #6374 --------- Co-authored-by: Dominik Strasser Co-authored-by: chrchr-github --- cfg/qt.cfg | 119 +++++++++++++++++++++++++++++++++--- test/cfg/qt.cpp | 23 +++++++ tools/triage/mainwindow.cpp | 2 +- 3 files changed, 134 insertions(+), 10 deletions(-) diff --git a/cfg/qt.cfg b/cfg/qt.cfg index 00cb66c1909..5371e598568 100644 --- a/cfg/qt.cfg +++ b/cfg/qt.cfg @@ -2319,10 +2319,28 @@
+ + + + + false + + + + + + + + + + false + + + - + false @@ -2338,6 +2356,68 @@
+ + + false + + + + + + + + + + + false + + + + + + + + + + + false + + + + + + + + + + + false + + + + + + + + false + + + + + + + + + + + false + + + + + + + false @@ -2346,7 +2426,7 @@ - + false @@ -2356,13 +2436,6 @@
- - - false - - - - @@ -2375,6 +2448,34 @@
+ + + false + + + + + + + false + + + + + + + false + + + + + + + false + + + + diff --git a/test/cfg/qt.cpp b/test/cfg/qt.cpp index d508eeef487..4c6c881b752 100644 --- a/test/cfg/qt.cpp +++ b/test/cfg/qt.cpp @@ -32,6 +32,7 @@ #include #include #include +#include // TODO: this is actually avilable via Core5Compat but I could not get it to work with pkg-config #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) @@ -54,6 +55,28 @@ int ignoredReturnValue_QSize_width(const QSize &s) return s.width(); } + +void ignoredReturnValue_QDir(const QString& dirname) +{ + QDir dir(dirname); + + // cppcheck-suppress ignoredReturnValue + dir.exists("abc"); + + // cppcheck-suppress ignoredReturnErrorCode + dir.mkdir("abc"); + + // cppcheck-suppress ignoredReturnValue + dir.count(); + + // cppcheck-suppress ignoredReturnValue + dir.filePath("abc"); + + // cppcheck-suppress ignoredReturnValue + dir.entryList(); +} + + void unusedVariable_QTransform() { // cppcheck-suppress unusedVariable diff --git a/tools/triage/mainwindow.cpp b/tools/triage/mainwindow.cpp index 8e5e4d39020..564d6e1bcf2 100644 --- a/tools/triage/mainwindow.cpp +++ b/tools/triage/mainwindow.cpp @@ -81,7 +81,7 @@ MainWindow::MainWindow(QWidget *parent) : std::srand(static_cast(std::time(nullptr))); QDir workFolder(WORK_FOLDER); if (!workFolder.exists()) { - workFolder.mkdir(WORK_FOLDER); + (void)workFolder.mkdir(WORK_FOLDER); } ui->results->setContextMenuPolicy(Qt::CustomContextMenu); From 74e6823ca873473c743f2c43d1122622984b4952 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 23 Mar 2026 12:33:34 +0100 Subject: [PATCH 053/168] Fix #14613 Crash in compilePrecedence2() (function called requires) (#8361) Co-authored-by: chrchr-github --- lib/tokenlist.cpp | 8 +++++--- test/testtokenize.cpp | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 7f7ca25aa5c..55ca98c628c 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1058,10 +1058,12 @@ static void compilePrecedence2(Token *&tok, AST_state& state) else compileUnaryOp(tok, state, compileExpression); tok = tok2->link()->next(); - } else if (Token::simpleMatch(tok->previous(), "requires {") - || (Token::simpleMatch(tok->previous(), ")") + } else if ((Token::simpleMatch(tok->tokAt(-1), "requires {") && tok->tokAt(-1)->isKeyword()) + || (Token::simpleMatch(tok->tokAt(-1), ")") && tok->linkAt(-1) - && Token::simpleMatch(tok->linkAt(-1)->previous(), "requires ("))) { + && Token::simpleMatch(tok->linkAt(-1)->tokAt(-1), "requires (") && tok->linkAt(-1)->tokAt(-1)->isKeyword())) { + if (!tok->link()) + throw InternalError(tok, "Syntax error, token has no link.", InternalError::AST); tok->astOperand1(state.op.top()); state.op.pop(); state.op.push(tok); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index f78899820b2..7a33f757737 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -8332,6 +8332,12 @@ class TestTokenizer : public TestFixture { void cppKeywordInCSource() { ASSERT_NO_THROW(tokenizeAndStringify("int throw() {}", dinit(TokenizeOptions, $.cpp = false))); + + const char code[] = "void requires(const char*);\n" // #14613 + "void f() { requires(\"abc\"); }\n"; + ASSERT_NO_THROW(tokenizeAndStringify(code, dinit(TokenizeOptions, $.cpp = false))); + ASSERT_NO_THROW(tokenizeAndStringify(code, dinit(TokenizeOptions, $.cpp = true, $.cppstd = Standards::CPP17))); + ASSERT_THROW_INTERNAL(tokenizeAndStringify(code, dinit(TokenizeOptions, $.cpp = true, $.cppstd = Standards::CPP20)), AST); } void cppcast() { From 7108f9fda4398c5a53319b3bb78c750c17614380 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 23 Mar 2026 13:09:25 +0100 Subject: [PATCH 054/168] Revert "Fix #14613 Crash in compilePrecedence2() (function called requires)" (broken build) (#8370) Reverts danmar/cppcheck#8361 --- lib/tokenlist.cpp | 8 +++----- test/testtokenize.cpp | 6 ------ 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 55ca98c628c..7f7ca25aa5c 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1058,12 +1058,10 @@ static void compilePrecedence2(Token *&tok, AST_state& state) else compileUnaryOp(tok, state, compileExpression); tok = tok2->link()->next(); - } else if ((Token::simpleMatch(tok->tokAt(-1), "requires {") && tok->tokAt(-1)->isKeyword()) - || (Token::simpleMatch(tok->tokAt(-1), ")") + } else if (Token::simpleMatch(tok->previous(), "requires {") + || (Token::simpleMatch(tok->previous(), ")") && tok->linkAt(-1) - && Token::simpleMatch(tok->linkAt(-1)->tokAt(-1), "requires (") && tok->linkAt(-1)->tokAt(-1)->isKeyword())) { - if (!tok->link()) - throw InternalError(tok, "Syntax error, token has no link.", InternalError::AST); + && Token::simpleMatch(tok->linkAt(-1)->previous(), "requires ("))) { tok->astOperand1(state.op.top()); state.op.pop(); state.op.push(tok); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7a33f757737..f78899820b2 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -8332,12 +8332,6 @@ class TestTokenizer : public TestFixture { void cppKeywordInCSource() { ASSERT_NO_THROW(tokenizeAndStringify("int throw() {}", dinit(TokenizeOptions, $.cpp = false))); - - const char code[] = "void requires(const char*);\n" // #14613 - "void f() { requires(\"abc\"); }\n"; - ASSERT_NO_THROW(tokenizeAndStringify(code, dinit(TokenizeOptions, $.cpp = false))); - ASSERT_NO_THROW(tokenizeAndStringify(code, dinit(TokenizeOptions, $.cpp = true, $.cppstd = Standards::CPP17))); - ASSERT_THROW_INTERNAL(tokenizeAndStringify(code, dinit(TokenizeOptions, $.cpp = true, $.cppstd = Standards::CPP20)), AST); } void cppcast() { From ee1afe9490f6e6812a682dd1b1a808cb15fcc330 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 24 Mar 2026 00:41:40 +0100 Subject: [PATCH 055/168] Remove unnecessary loading of qt.cfg in testtokenize.cpp (#8372) Co-authored-by: chrchr-github --- test/testtokenize.cpp | 159 +++++++++++++++++++++--------------------- 1 file changed, 79 insertions(+), 80 deletions(-) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index f78899820b2..8ea3ca7d9ac 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -46,15 +46,14 @@ class TestTokenizer : public TestFixture { TestTokenizer() : TestFixture("TestTokenizer") {} private: - const Settings settings0 = settingsBuilder().library("qt.cfg").build(); - const Settings settings1 = settingsBuilder().library("std.cfg").library("qt.cfg").debugwarnings().build(); + const Settings settings1 = settingsBuilder().library("std.cfg").debugwarnings().build(); const Settings settings2 = settingsBuilder(settings1).cpp(Standards::CPP11).c(Standards::C11).build(); const Settings settings2_win32a = settingsBuilder(settings2).platform(Platform::Type::Win32A).build(); const Settings settings2_win32w = settingsBuilder(settings2).platform(Platform::Type::Win32W).build(); const Settings settings2_win64 = settingsBuilder(settings2).platform(Platform::Type::Win64).build(); const Settings settings2_unix32 = settingsBuilder(settings2).platform(Platform::Type::Unix32).build(); const Settings settings2_unix64 = settingsBuilder(settings2).platform(Platform::Type::Unix64).build(); - const Settings settings3 = settingsBuilder(settings0).c(Standards::C89).cpp(Standards::CPP03).build(); + const Settings settings3 = settingsBuilder().c(Standards::C89).cpp(Standards::CPP03).build(); const Settings settings_windows = settingsBuilder().library("windows.cfg").debugwarnings().cpp(Standards::CPP11).build(); const Settings settings_win32a = settingsBuilder(settings_windows).platform(Platform::Type::Win32A).build(); const Settings settings_win32w = settingsBuilder(settings_windows).platform(Platform::Type::Win32W).build(); @@ -1734,7 +1733,7 @@ class TestTokenizer : public TestFixture { { const char code[] = "extern \"C\" int foo();"; // tokenize.. - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); // Expected result.. ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false)); @@ -1743,7 +1742,7 @@ class TestTokenizer : public TestFixture { { const char code[] = "extern \"C\" { int foo(); }"; // tokenize.. - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); // Expected result.. ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false)); @@ -1752,7 +1751,7 @@ class TestTokenizer : public TestFixture { { const char code[] = "extern \"C++\" int foo();"; // tokenize.. - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); // Expected result.. ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false)); @@ -1761,7 +1760,7 @@ class TestTokenizer : public TestFixture { { const char code[] = "extern \"C++\" { int foo(); }"; // tokenize.. - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); // Expected result.. ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false)); @@ -3188,7 +3187,7 @@ class TestTokenizer : public TestFixture { const char code[] = "class A{\n" " void f() {}\n" "};"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); // A body {} @@ -3211,7 +3210,7 @@ class TestTokenizer : public TestFixture { " char a[10];\n" " char *b ; b = new char[a[0]];\n" "};"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); // a[10] @@ -3233,7 +3232,7 @@ class TestTokenizer : public TestFixture { const char code[] = "void f(){\n" " foo(g());\n" "};"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); // foo( @@ -3251,7 +3250,7 @@ class TestTokenizer : public TestFixture { const char code[] = "bool foo(C a, bar>& f, int b) {\n" " return(af);\n" "}"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); // template< @@ -3277,7 +3276,7 @@ class TestTokenizer : public TestFixture { const char code[] = "void foo() {\n" " return static_cast(a);\n" "}"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); @@ -3292,7 +3291,7 @@ class TestTokenizer : public TestFixture { const char code[] = "void foo() {\n" " nvwa<(x > y)> ERROR_nnn;\n" "}"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); @@ -3306,7 +3305,7 @@ class TestTokenizer : public TestFixture { { // #4860 const char code[] = "class A : public B {};"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); @@ -3320,7 +3319,7 @@ class TestTokenizer : public TestFixture { { // #4860 const char code[] = "Bar>>>::set(1, 2, 3);"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); @@ -3335,7 +3334,7 @@ class TestTokenizer : public TestFixture { { // #5627 const char code[] = "new Foo[10];"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); @@ -3349,7 +3348,7 @@ class TestTokenizer : public TestFixture { { // #6242 const char code[] = "func = integral_;"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); @@ -3362,7 +3361,7 @@ class TestTokenizer : public TestFixture { { // if (a < b || c > d) { } const char code[] = "{ if (a < b || c > d); }"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); @@ -3372,7 +3371,7 @@ class TestTokenizer : public TestFixture { { // bool f = a < b || c > d const char code[] = "bool f = a < b || c > d;"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); @@ -3382,7 +3381,7 @@ class TestTokenizer : public TestFixture { { // template const char code[] = "a < b || c > d;"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); @@ -3392,7 +3391,7 @@ class TestTokenizer : public TestFixture { { // if (a < ... > d) { } const char code[] = "{ if (a < b || c == 3 || d > e); }"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); @@ -3402,7 +3401,7 @@ class TestTokenizer : public TestFixture { { // template const char code[] = "a d;"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(7)); @@ -3411,7 +3410,7 @@ class TestTokenizer : public TestFixture { { // template const char code[] = "a d;"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(7)); @@ -3419,7 +3418,7 @@ class TestTokenizer : public TestFixture { { const char code[] = "template < f = b || c > struct S;"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(7)); @@ -3428,7 +3427,7 @@ class TestTokenizer : public TestFixture { { const char code[] = "struct A : B {};"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->linkAt(4) == tok->tokAt(8)); @@ -3437,7 +3436,7 @@ class TestTokenizer : public TestFixture { { const char code[] = "Data;"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(4)); @@ -3447,7 +3446,7 @@ class TestTokenizer : public TestFixture { { // #6601 const char code[] = "template struct FuncType : FuncType { };"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = tokenizer.tokens(); @@ -3465,7 +3464,7 @@ class TestTokenizer : public TestFixture { { // #7158 const char code[] = "enum { value = boost::mpl::at_c };"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok = Token::findsimplematch(tokenizer.tokens(), "<"); ASSERT_EQUALS(true, tok->link() == tok->tokAt(4)); @@ -3477,7 +3476,7 @@ class TestTokenizer : public TestFixture { const char code[] = "template \n" "struct CheckedDivOp< T, U, typename std::enable_if::value || std::is_floating_point::value>::type> {\n" "};\n"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "struct")->tokAt(2); const Token *tok2 = Token::findsimplematch(tokenizer.tokens(), "{")->previous(); @@ -3488,7 +3487,7 @@ class TestTokenizer : public TestFixture { { // #7975 const char code[] = "template X copy() {};\n"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "< Y"); const Token *tok2 = Token::findsimplematch(tok1, "> copy"); @@ -3499,7 +3498,7 @@ class TestTokenizer : public TestFixture { { // #8006 const char code[] = "C && a = b;"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok1 = tokenizer.tokens()->next(); const Token *tok2 = tok1->tokAt(2); @@ -3510,7 +3509,7 @@ class TestTokenizer : public TestFixture { { // #8115 const char code[] = "void Test(C && c);"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "<"); const Token *tok2 = tok1->tokAt(2); @@ -3521,7 +3520,7 @@ class TestTokenizer : public TestFixture { // #8654 const char code[] = "template struct A {}; " "template struct foo : A... {};"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *A = Token::findsimplematch(tokenizer.tokens(), "A <"); ASSERT_EQUALS(true, A->linkAt(1) == A->tokAt(3)); @@ -3530,7 +3529,7 @@ class TestTokenizer : public TestFixture { // #8851 const char code[] = "template::type>" "void basic_json() {}"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); ASSERT_EQUALS(true, Token::simpleMatch(tokenizer.tokens()->linkAt(1), "> void")); } @@ -3538,7 +3537,7 @@ class TestTokenizer : public TestFixture { { // #9094 - template usage or comparison? const char code[] = "a = f(x%x<--a==x>x);"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); ASSERT(nullptr == Token::findsimplematch(tokenizer.tokens(), "<")->link()); } @@ -3548,7 +3547,7 @@ class TestTokenizer : public TestFixture { const char code[] = "using std::same_as;\n" "template T>\n" "void f();"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "template <"); const Token *tok2 = Token ::findsimplematch(tokenizer.tokens(), "same_as <"); @@ -3559,7 +3558,7 @@ class TestTokenizer : public TestFixture { { // #9131 - template usage or comparison? const char code[] = "using std::list; list l;"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "<")->link()); } @@ -3570,7 +3569,7 @@ class TestTokenizer : public TestFixture { "{\n" " for (set::iterator i = sources.begin(); i != sources.end(); ++i) {}\n" "}"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "<")->link()); } @@ -3581,7 +3580,7 @@ class TestTokenizer : public TestFixture { " a<> b;\n" " b.a<>::c();\n" "}\n"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ::")->link()); } @@ -3592,7 +3591,7 @@ class TestTokenizer : public TestFixture { "template struct c {\n" " void d() { a[0]; }\n" "};\n"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> [")->link()); } @@ -3604,7 +3603,7 @@ class TestTokenizer : public TestFixture { "template using f = c;\n" "template > struct g {};\n" "template using baz = g;\n"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ;")->link()); } @@ -3618,7 +3617,7 @@ class TestTokenizer : public TestFixture { "template using c = a;\n" "template c e;\n" "auto f = -e<1> == 0;\n"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ==")->link()); } @@ -3636,7 +3635,7 @@ class TestTokenizer : public TestFixture { "constexpr void b::operator()(c &&) const {\n" " i<3>.f([] {});\n" "}\n"; - SimpleTokenizer tokenizer(settings0, *this); + SimpleTokenizer tokenizer(settingsDefault, *this); ASSERT(tokenizer.tokenize(code)); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> . f (")->link()); } @@ -3644,7 +3643,7 @@ class TestTokenizer : public TestFixture { { // #10491 const char code[] = "template