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 001/667] 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 002/667] 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 003/667] 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 004/667] 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 005/667] 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 006/667] 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 007/667] 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 008/667] 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 009/667] 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 010/667] 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 011/667] 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 012/667] 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 013/667] 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 014/667] 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 015/667] 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 016/667] 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 017/667] 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 018/667] 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 019/667] 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 020/667] 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 021/667] 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 022/667] 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 023/667] 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 024/667] 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 025/667] 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 026/667] 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 027/667] 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 028/667] 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 029/667] 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 030/667] 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 031/667] 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 032/667] 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 033/667] 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 034/667] 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 035/667] 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