From a2be91a573e64f6721dc169ca92ad106223dbf07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Sun, 1 Mar 2026 20:55:27 +0100 Subject: [PATCH 1/8] Fix #14471 --- lib/checkother.cpp | 58 +++++++++++++++++++++++++++++----------------- lib/checkother.h | 2 +- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 698ef62e78b..ce42c4aa1a8 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -4144,18 +4144,21 @@ void CheckOther::checkShadowVariables() const Scope *functionScope = &scope; while (functionScope && functionScope->type != ScopeType::eFunction && functionScope->type != ScopeType::eLambda) functionScope = functionScope->nestedIn; - for (const Variable &var : scope.varlist) { - if (var.nameToken() && var.nameToken()->isExpandedMacro()) // #8903 - continue; + const auto checkVar = [&](const Variable &var) { + if (!var.nameToken()) + return; - if (functionScope && functionScope->type == ScopeType::eFunction && functionScope->function) { + if (var.nameToken()->isExpandedMacro()) // #8903 + return; + + if (!var.isArgument() && functionScope && functionScope->type == ScopeType::eFunction && functionScope->function) { const auto & argList = functionScope->function->argumentList; auto it = std::find_if(argList.cbegin(), argList.cend(), [&](const Variable& arg) { return arg.nameToken() && var.name() == arg.name(); }); if (it != argList.end()) { - shadowError(var.nameToken(), it->nameToken(), "argument"); - continue; + shadowError(var.nameToken(), "local variable", it->nameToken(), "argument"); + return; } } @@ -4163,27 +4166,39 @@ void CheckOther::checkShadowVariables() if (!shadowed) shadowed = findShadowed(scope.functionOf, var, var.nameToken()->linenr()); if (!shadowed) - continue; + return; if (scope.type == ScopeType::eFunction && scope.className == var.name()) - continue; + return; if (functionScope->functionOf && functionScope->functionOf->isClassOrStructOrUnion() && functionScope->function && (functionScope->function->isStatic() || functionScope->function->isFriend()) && shadowed->variable() && !shadowed->variable()->isLocal()) - continue; - shadowError(var.nameToken(), shadowed, (shadowed->varId() != 0) ? "variable" : "function"); - } + return; + if (var.scope() && var.scope()->function && var.scope()->function->isConstructor() + && shadowed->variable() && shadowed->variable()->isMember()) + return; + shadowError(var.nameToken(), var.isArgument() ? "argument" : "local variable", + shadowed, (shadowed->varId() != 0) ? + (shadowed->variable()->isMember() ? "member" : "variable") : "function"); + }; + for (const Variable &var : scope.varlist) + checkVar(var); + if (functionScope && functionScope->type == ScopeType::eFunction && functionScope->function) + for (const Variable &arg: functionScope->function->argumentList) + checkVar(arg); } } -void CheckOther::shadowError(const Token *var, const Token *shadowed, const std::string& type) +void CheckOther::shadowError(const Token *shadows, const std::string &shadowsType, + const Token *shadowed, const std::string &shadowedType) { ErrorPath errorPath; - errorPath.emplace_back(shadowed, "Shadowed declaration"); - errorPath.emplace_back(var, "Shadow variable"); - const std::string &varname = var ? var->str() : type; - const std::string Type = char(std::toupper(type[0])) + type.substr(1); - const std::string id = "shadow" + Type; - const std::string message = "$symbol:" + varname + "\nLocal variable \'$symbol\' shadows outer " + type; + errorPath.emplace_back(shadowed, "Shadowed " + shadowedType); + errorPath.emplace_back(shadows, "Shadow " + shadowsType); + const std::string &varname = shadows ? shadows->str() : shadowsType; + const std::string ShadowsType = char(std::toupper(shadowsType[0])) + shadowsType.substr(1); + const std::string ShadowedType = char(std::toupper(shadowedType[0])) + shadowedType.substr(1); + const std::string id = "shadow" + ShadowedType; + const std::string message = "$symbol:" + varname + "\n" + ShadowsType + " \'$symbol\' shadows outer " + shadowedType; reportError(std::move(errorPath), Severity::style, id.c_str(), message, CWE398, Certainty::normal); } @@ -4865,9 +4880,10 @@ void CheckOther::getErrorMessages(ErrorLogger *errorLogger, const Settings *sett c.accessMovedError(nullptr, "v", nullptr, false); c.funcArgNamesDifferent("function", 1, nullptr, nullptr); c.redundantBitwiseOperationInSwitchError(nullptr, "varname"); - c.shadowError(nullptr, nullptr, "variable"); - c.shadowError(nullptr, nullptr, "function"); - c.shadowError(nullptr, nullptr, "argument"); + c.shadowError(nullptr, "local variable", nullptr, "variable"); + c.shadowError(nullptr, "local variable", nullptr, "argument"); + c.shadowError(nullptr, "local variable", nullptr, "function"); + c.shadowError(nullptr, "local variable", nullptr, "member"); c.knownArgumentError(nullptr, nullptr, nullptr, "x", false); c.knownPointerToBoolError(nullptr, nullptr); c.comparePointersError(nullptr, nullptr, nullptr); diff --git a/lib/checkother.h b/lib/checkother.h index 28ee25cfa76..f779141f499 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -258,7 +258,7 @@ class CPPCHECKLIB CheckOther : public Check { void accessMovedError(const Token *tok, const std::string &varname, const ValueFlow::Value *value, bool inconclusive); void funcArgNamesDifferent(const std::string & functionName, nonneg int index, const Token* declaration, const Token* definition); void funcArgOrderDifferent(const std::string & functionName, const Token * declaration, const Token * definition, const std::vector & declarations, const std::vector & definitions); - void shadowError(const Token *var, const Token *shadowed, const std::string& type); + void shadowError(const Token *shadows, const std::string &shadowsType, const Token *shadowed, const std::string &shadowedType); void knownArgumentError(const Token *tok, const Token *ftok, const ValueFlow::Value *value, const std::string &varexpr, bool isVariableExpressionHidden); void knownPointerToBoolError(const Token* tok, const ValueFlow::Value* value); void comparePointersError(const Token *tok, const ValueFlow::Value *v1, const ValueFlow::Value *v2); From 31d2812f1406030fabab4387bbff763cd63f28b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Sun, 1 Mar 2026 20:55:36 +0100 Subject: [PATCH 2/8] Update tests --- test/testother.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/testother.cpp b/test/testother.cpp index 0c6828a0b63..562630f6507 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -6517,9 +6517,9 @@ class TestOther : public TestFixture { check("class Foo {\n" " int var;\n" - " void func(int var);\n" + " Foo(int var);\n" "};\n" - "void Foo::func(int var) {\n" + "Foo::Foo(int var) {\n" " this->var = var;\n" "}"); ASSERT_EQUALS("", errout_str()); @@ -12853,14 +12853,14 @@ class TestOther : public TestFixture { " int i{};\n" " void f() { int i; }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer member [shadowMember]\n", errout_str()); check("struct S {\n" " int i{};\n" " std::vector v;\n" " void f() const { for (const int& i : v) {} }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer member [shadowMember]\n", errout_str()); check("struct S {\n" // #10405 " F* f{};\n" @@ -12870,7 +12870,7 @@ class TestOther : public TestFixture { "void S::f() const {\n" " for (const F& f : fl) {}\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer member [shadowMember]\n", errout_str()); check("extern int a;\n" "int a;\n" From 9ae1f59e5c308258b1d655bf5b7d566d3b4deb14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Fri, 6 Mar 2026 12:58:35 +0100 Subject: [PATCH 3/8] Add tests --- test/testother.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 562630f6507..0df2f8420d1 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -12892,6 +12892,26 @@ class TestOther : public TestFixture { " friend int f() { int i = 5; return i; }\n" "};\n"); ASSERT_EQUALS("", errout_str()); + + check("int x;\n" + "void f(int x) {}\n"); + ASSERT_EQUALS("[test.cpp:1:5] -> [test.cpp:2:12]: (style) Argument 'x' shadows outer variable [shadowVariable]\n", errout_str()); + + check("void x() {}\n" + "void f(int x) {}\n"); + ASSERT_EQUALS("[test.cpp:1:6] -> [test.cpp:2:12]: (style) Argument 'x' shadows outer function [shadowFunction]\n", errout_str()); + + check("struct S { int v; void func(int v); };\n" + "void S::func(int v) { this->v = v; }\n"); + ASSERT_EQUALS("[test.cpp:1:16] -> [test.cpp:2:18]: (style) Argument 'v' shadows outer member [shadowMember]\n", errout_str()); + + check("struct S { int v; void func(void); };\n" + "void S::func() { int v = 0; }\n"); + ASSERT_EQUALS("[test.cpp:1:16] -> [test.cpp:2:22]: (style) Local variable 'v' shadows outer member [shadowMember]\n", errout_str()); + + check("struct S { int v; explicit S(int v); };\n" + "S::S(int v) : v(v) {}\n"); + ASSERT_EQUALS("", errout_str()); } void knownArgument() { From c3339ac27c9210bca1e29d66877d1c46804c6c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Wed, 11 Mar 2026 11:01:51 +0100 Subject: [PATCH 4/8] Add suppressions in cfg tests --- test/cfg/qt.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/cfg/qt.cpp b/test/cfg/qt.cpp index 70e6ac0310a..a4fe32ac6ab 100644 --- a/test/cfg/qt.cpp +++ b/test/cfg/qt.cpp @@ -723,6 +723,7 @@ namespace { private: int m_value; }; + // cppcheck-suppress shadowFunction void Counter1::setValue(int value) { if (value != m_value) { m_value = value; @@ -746,6 +747,7 @@ namespace { private: int m_value; }; + // cppcheck-suppress shadowFunction void Counter2::setValue(int value) { if (value != m_value) { m_value = value; From 66aca80a5eb25d2a1f6d64a15d8a2afbd65bffd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Sun, 29 Mar 2026 17:56:40 +0200 Subject: [PATCH 5/8] Add test for shadowed method --- test/testother.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 0df2f8420d1..b15b8755b76 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -12912,6 +12912,10 @@ class TestOther : public TestFixture { check("struct S { int v; explicit S(int v); };\n" "S::S(int v) : v(v) {}\n"); ASSERT_EQUALS("", errout_str()); + + check("struct S { int v(); explicit S(int v); };\n" + "S::S(int v) : v(v) {}\n"); + ASSERT_EQUALS("", errout_str()); } void knownArgument() { From 7b9416460508466ad840ca66696a2dac07cd8f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Sun, 29 Mar 2026 17:54:24 +0200 Subject: [PATCH 6/8] Don't warn for shadowed methods in constructor --- lib/checkother.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index ce42c4aa1a8..472767d758a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -4173,9 +4173,13 @@ void CheckOther::checkShadowVariables() (functionScope->function->isStatic() || functionScope->function->isFriend()) && shadowed->variable() && !shadowed->variable()->isLocal()) return; - if (var.scope() && var.scope()->function && var.scope()->function->isConstructor() - && shadowed->variable() && shadowed->variable()->isMember()) - return; + if (var.scope() && var.scope()->function && var.scope()->function->isConstructor()) { + if (shadowed->variable() && shadowed->variable()->isMember()) + return; + if (shadowed->function() && shadowed->function()->nestedIn && + shadowed->function()->nestedIn->isClassOrStruct()) + return; + } shadowError(var.nameToken(), var.isArgument() ? "argument" : "local variable", shadowed, (shadowed->varId() != 0) ? (shadowed->variable()->isMember() ? "member" : "variable") : "function"); From 40ad29e06510153b022e1d776f9f7bdf2f6a8aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 30 Mar 2026 10:09:40 +0200 Subject: [PATCH 7/8] Add selfcheck suppression for simplecpp --- .selfcheck_suppressions | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.selfcheck_suppressions b/.selfcheck_suppressions index 171a5a997d7..77b3d8746d6 100644 --- a/.selfcheck_suppressions +++ b/.selfcheck_suppressions @@ -41,3 +41,5 @@ nullPointerRedundantCheck:externals/tinyxml2/tinyxml2.cpp knownConditionTrueFalse:externals/tinyxml2/tinyxml2.cpp useStlAlgorithm:externals/simplecpp/simplecpp.cpp missingMemberCopy:externals/simplecpp/simplecpp.h +shadowFunction:externals/simplecpp/simplecpp.cpp +shadowFunction:externals/simplecpp/simplecpp.h From e14597544cf6165585f0d110ee3a3d8820cd79fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Sun, 29 Mar 2026 17:46:37 +0200 Subject: [PATCH 8/8] Update existing code to avoid shadow argument warnings --- gui/mainwindow.cpp | 20 ++++++------- gui/mainwindow.h | 18 +++++------ lib/checkcondition.cpp | 4 +-- lib/checkcondition.h | 2 +- lib/checkunusedfunctions.cpp | 8 ++--- lib/checkunusedfunctions.h | 2 +- lib/filesettings.h | 4 +-- lib/preprocessor.cpp | 36 +++++++++++----------- lib/preprocessor.h | 4 +-- lib/programmemory.cpp | 4 +-- lib/programmemory.h | 2 +- lib/regex.cpp | 6 ++-- lib/symboldatabase.cpp | 12 ++++---- lib/symboldatabase.h | 4 +-- lib/token.cpp | 58 ++++++++++++++++++------------------ lib/token.h | 22 +++++++------- lib/tokenlist.cpp | 8 ++--- lib/tokenlist.h | 4 +-- lib/vf_analyzers.cpp | 4 +-- tools/triage/mainwindow.cpp | 6 ++-- tools/triage/mainwindow.h | 2 +- 21 files changed, 115 insertions(+), 115 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 63917bdc912..7f7fb1d0f59 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -566,7 +566,7 @@ void MainWindow::saveSettings() const mUI->mResults->saveSettings(mSettings); } -void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, const bool checkConfiguration) +void MainWindow::doAnalyzeProject(ImportProject p, const bool doCheckLibrary, const bool doCheckConfiguration) { Settings checkSettings; auto supprs = std::make_shared(); @@ -610,8 +610,8 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons mUI->mResults->setCheckDirectory(checkPath); checkSettings.force = false; - checkSettings.checkLibrary = checkLibrary; - checkSettings.checkConfiguration = checkConfiguration; + checkSettings.checkLibrary = doCheckLibrary; + checkSettings.checkConfiguration = doCheckConfiguration; if (mProjectFile) qDebug() << "Checking project file" << mProjectFile->getFilename(); @@ -638,7 +638,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons mUI->mResults->setCheckSettings(checkSettings); } -void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrary, const bool checkConfiguration) +void MainWindow::doAnalyzeFiles(const QStringList &files, const bool doCheckLibrary, const bool doCheckConfiguration) { if (files.isEmpty()) return; @@ -679,7 +679,7 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrar // TODO: lock UI here? mUI->mResults->checkingStarted(fdetails.size()); mThread->setFiles(std::move(fdetails)); - if (mProjectFile && !checkConfiguration) + if (mProjectFile && !doCheckConfiguration) mThread->setAddonsAndTools(mProjectFile->getAddonsAndTools()); mThread->setSuppressions(mProjectFile ? mProjectFile->getCheckingSuppressions() : QList()); QDir inf(mCurrentDirectory); @@ -689,8 +689,8 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrar checkLockDownUI(); // lock UI while checking mUI->mResults->setCheckDirectory(checkPath); - checkSettings.checkLibrary = checkLibrary; - checkSettings.checkConfiguration = checkConfiguration; + checkSettings.checkLibrary = doCheckLibrary; + checkSettings.checkConfiguration = doCheckConfiguration; if (mProjectFile) qDebug() << "Checking project file" << mProjectFile->getFilename(); @@ -1883,7 +1883,7 @@ bool MainWindow::loadLastResults() return true; } -void MainWindow::analyzeProject(const ProjectFile *projectFile, const QStringList& recheckFiles, const bool checkLibrary, const bool checkConfiguration) +void MainWindow::analyzeProject(const ProjectFile *projectFile, const QStringList& recheckFiles, const bool doCheckLibrary, const bool doCheckConfiguration) { Settings::terminate(false); @@ -2011,7 +2011,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile, const QStringLis msg.exec(); return; } - doAnalyzeProject(p, checkLibrary, checkConfiguration); // TODO: avoid copy + doAnalyzeProject(p, doCheckLibrary, doCheckConfiguration); // TODO: avoid copy return; } @@ -2024,7 +2024,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile, const QStringLis if (paths.isEmpty()) { paths << mCurrentDirectory; } - doAnalyzeFiles(paths, checkLibrary, checkConfiguration); + doAnalyzeFiles(paths, doCheckLibrary, doCheckConfiguration); } void MainWindow::newProjectFile() diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 45506f3f6b8..c7c6b84a663 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -270,10 +270,10 @@ private slots: * @brief Analyze the project. * @param projectFile Pointer to the project to analyze. * @param recheckFiles files to recheck, empty => check all files - * @param checkLibrary Flag to indicate if the library should be checked. - * @param checkConfiguration Flag to indicate if the configuration should be checked. + * @param doCheckLibrary Flag to indicate if the library should be checked. + * @param doCheckConfiguration Flag to indicate if the configuration should be checked. */ - void analyzeProject(const ProjectFile *projectFile, const QStringList& recheckFiles, bool checkLibrary = false, bool checkConfiguration = false); + void analyzeProject(const ProjectFile *projectFile, const QStringList& recheckFiles, bool doCheckLibrary = false, bool doCheckConfiguration = false); /** * @brief Set current language @@ -309,19 +309,19 @@ private slots: /** * @brief Analyze project * @param p imported project - * @param checkLibrary Flag to indicate if library should be checked - * @param checkConfiguration Flag to indicate if the configuration should be checked. + * @param doCheckLibrary Flag to indicate if library should be checked + * @param doCheckConfiguration Flag to indicate if the configuration should be checked. */ - void doAnalyzeProject(ImportProject p, bool checkLibrary = false, bool checkConfiguration = false); + void doAnalyzeProject(ImportProject p, bool doCheckLibrary = false, bool doCheckConfiguration = false); /** * @brief Analyze all files specified in parameter files * * @param files List of files and/or directories to analyze - * @param checkLibrary Flag to indicate if library should be checked - * @param checkConfiguration Flag to indicate if the configuration should be checked. + * @param doCheckLibrary Flag to indicate if library should be checked + * @param doCheckConfiguration Flag to indicate if the configuration should be checked. */ - void doAnalyzeFiles(const QStringList &files, bool checkLibrary = false, bool checkConfiguration = false); + void doAnalyzeFiles(const QStringList &files, bool doCheckLibrary = false, bool doCheckConfiguration = false); /** * @brief Get our default cppcheck settings and read project file. diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index cf54c882f34..878d39205c5 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -2071,10 +2071,10 @@ void CheckCondition::checkCompareValueOutOfTypeRange() } } -void CheckCondition::compareValueOutOfTypeRangeError(const Token *comparison, const std::string &type, MathLib::bigint value, bool result) +void CheckCondition::compareValueOutOfTypeRangeError(const Token *comp, const std::string &type, MathLib::bigint value, bool result) { reportError( - comparison, + comp, Severity::style, "compareValueOutOfTypeRangeError", "Comparing expression of type '" + type + "' against value " + MathLib::toString(value) + ". Condition is always " + bool_to_string(result) + ".", diff --git a/lib/checkcondition.h b/lib/checkcondition.h index dac3ba8d0de..cc833c0f04c 100644 --- a/lib/checkcondition.h +++ b/lib/checkcondition.h @@ -155,7 +155,7 @@ class CPPCHECKLIB CheckCondition : public Check { void assignmentInCondition(const Token *eq); void checkCompareValueOutOfTypeRange(); - void compareValueOutOfTypeRangeError(const Token *comparison, const std::string &type, MathLib::bigint value, bool result); + void compareValueOutOfTypeRangeError(const Token *comp, const std::string &type, MathLib::bigint value, bool result); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override; diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index e10d25a87f1..f7d7cb0c6c6 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -502,9 +502,9 @@ void CheckUnusedFunctions::analyseWholeProgram(const Settings &settings, ErrorLo } } -void CheckUnusedFunctions::updateFunctionData(const CheckUnusedFunctions& check) +void CheckUnusedFunctions::updateFunctionData(const CheckUnusedFunctions& checkUnusedFunctions) { - for (const auto& entry : check.mFunctions) + for (const auto& entry : checkUnusedFunctions.mFunctions) { FunctionUsage &usage = mFunctions[entry.first]; if (!usage.lineNumber) { @@ -518,6 +518,6 @@ void CheckUnusedFunctions::updateFunctionData(const CheckUnusedFunctions& check) usage.usedOtherFile |= entry.second.usedOtherFile; usage.usedSameFile |= entry.second.usedSameFile; } - mFunctionDecl.insert(mFunctionDecl.cend(), check.mFunctionDecl.cbegin(), check.mFunctionDecl.cend()); - mFunctionCalls.insert(check.mFunctionCalls.cbegin(), check.mFunctionCalls.cend()); + mFunctionDecl.insert(mFunctionDecl.cend(), checkUnusedFunctions.mFunctionDecl.cbegin(), checkUnusedFunctions.mFunctionDecl.cend()); + mFunctionCalls.insert(checkUnusedFunctions.mFunctionCalls.cbegin(), checkUnusedFunctions.mFunctionCalls.cend()); } diff --git a/lib/checkunusedfunctions.h b/lib/checkunusedfunctions.h index 6f10e3446eb..20e1788cf64 100644 --- a/lib/checkunusedfunctions.h +++ b/lib/checkunusedfunctions.h @@ -58,7 +58,7 @@ class CPPCHECKLIB CheckUnusedFunctions { // Return true if an error is reported. bool check(const Settings& settings, ErrorLogger& errorLogger) const; - void updateFunctionData(const CheckUnusedFunctions& check); + void updateFunctionData(const CheckUnusedFunctions& checkUnusedFunctions); private: static void unusedFunctionError(ErrorLogger& errorLogger, diff --git a/lib/filesettings.h b/lib/filesettings.h index e9f883d5a87..183e38708fd 100644 --- a/lib/filesettings.h +++ b/lib/filesettings.h @@ -91,9 +91,9 @@ class FileWithDetails return mFsFileId; } - void setFsFileId(std::size_t fsFileId) + void setFsFileId(std::size_t id) { - mFsFileId = fsFileId; + mFsFileId = id; } private: std::string mPath; diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 9528360906e..fb17ab6eebd 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -512,14 +512,14 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::set &configs, const std::strin return ret; } -static bool isUndefined(const std::string &cfg, const std::set &undefined) +static bool isUndefined(const std::string &cfgStr, const std::set &undefined) { - for (std::string::size_type pos1 = 0U; pos1 < cfg.size();) { - const std::string::size_type pos2 = cfg.find(';',pos1); - const std::string def = (pos2 == std::string::npos) ? cfg.substr(pos1) : cfg.substr(pos1, pos2 - pos1); + for (std::string::size_type pos1 = 0U; pos1 < cfgStr.size();) { + const std::string::size_type pos2 = cfgStr.find(';',pos1); + const std::string def = (pos2 == std::string::npos) ? cfgStr.substr(pos1) : cfgStr.substr(pos1, pos2 - pos1); const std::string::size_type eq = def.find('='); if (eq == std::string::npos && undefined.find(def) != undefined.end()) @@ -797,11 +797,11 @@ std::set Preprocessor::getConfigs() const return ret; } -static void splitcfg(const std::string &cfg, std::list &defines, const std::string &defaultValue) +static void splitcfg(const std::string &cfgStr, std::list &defines, const std::string &defaultValue) { - for (std::string::size_type defineStartPos = 0U; defineStartPos < cfg.size();) { - const std::string::size_type defineEndPos = cfg.find(';', defineStartPos); - std::string def = (defineEndPos == std::string::npos) ? cfg.substr(defineStartPos) : cfg.substr(defineStartPos, defineEndPos - defineStartPos); + for (std::string::size_type defineStartPos = 0U; defineStartPos < cfgStr.size();) { + const std::string::size_type defineEndPos = cfgStr.find(';', defineStartPos); + std::string def = (defineEndPos == std::string::npos) ? cfgStr.substr(defineStartPos) : cfgStr.substr(defineStartPos, defineEndPos - defineStartPos); if (!defaultValue.empty() && def.find('=') == std::string::npos) def += '=' + defaultValue; defines.push_back(std::move(def)); @@ -811,14 +811,14 @@ static void splitcfg(const std::string &cfg, std::list &defines, co } } -static simplecpp::DUI createDUI(const Settings &mSettings, const std::string &cfg, Standards::Language lang) +static simplecpp::DUI createDUI(const Settings &mSettings, const std::string &cfgStr, Standards::Language lang) { // TODO: make it possible to specify platform-dependent sizes simplecpp::DUI dui; splitcfg(mSettings.userDefines, dui.defines, "1"); - if (!cfg.empty()) - splitcfg(cfg, dui.defines, ""); + if (!cfgStr.empty()) + splitcfg(cfgStr, dui.defines, ""); for (const std::string &def : mSettings.library.defines()) { const std::string::size_type pos = def.find_first_of(" ("); @@ -899,9 +899,9 @@ void Preprocessor::setPlatformInfo() mTokens.sizeOfType["long double *"] = mSettings.platform.sizeof_pointer; } -simplecpp::TokenList Preprocessor::preprocess(const std::string &cfg, std::vector &files, simplecpp::OutputList& outputList) +simplecpp::TokenList Preprocessor::preprocess(const std::string &cfgStr, std::vector &files, simplecpp::OutputList& outputList) { - const simplecpp::DUI dui = createDUI(mSettings, cfg, mLang); + const simplecpp::DUI dui = createDUI(mSettings, cfgStr, mLang); std::list macroUsage; std::list ifCond; @@ -915,10 +915,10 @@ simplecpp::TokenList Preprocessor::preprocess(const std::string &cfg, std::vecto return tokens2; } -std::string Preprocessor::getcode(const std::string &cfg, std::vector &files, const bool writeLocations) +std::string Preprocessor::getcode(const std::string &cfgStr, std::vector &files, const bool writeLocations) { simplecpp::OutputList outputList; - simplecpp::TokenList tokens2 = preprocess(cfg, files, outputList); + simplecpp::TokenList tokens2 = preprocess(cfgStr, files, outputList); handleErrors(outputList); unsigned int prevfile = 0; unsigned int line = 1; diff --git a/lib/preprocessor.h b/lib/preprocessor.h index a211341691f..9daabbf6ca8 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -118,9 +118,9 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor { void setPlatformInfo(); - simplecpp::TokenList preprocess(const std::string &cfg, std::vector &files, simplecpp::OutputList& outputList); + simplecpp::TokenList preprocess(const std::string &cfgStr, std::vector &files, simplecpp::OutputList& outputList); - std::string getcode(const std::string &cfg, std::vector &files, bool writeLocations); + std::string getcode(const std::string &cfgStr, std::vector &files, bool writeLocations); /** * Calculate HASH. Using toolinfo, tokens1, filedata. diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 889826380db..acbcb311c10 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -150,11 +150,11 @@ bool ProgramMemory::getContainerEmptyValue(nonneg int exprid, MathLib::bigint& r return false; } -void ProgramMemory::setContainerSizeValue(const Token* expr, MathLib::bigint value, bool isEqual) +void ProgramMemory::setContainerSizeValue(const Token* expr, MathLib::bigint value, bool equal) { ValueFlow::Value v(value); v.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE; - if (!isEqual) + if (!equal) v.valueKind = ValueFlow::Value::ValueKind::Impossible; setValue(expr, v); } diff --git a/lib/programmemory.h b/lib/programmemory.h index adb0d1469ce..3a3cf554104 100644 --- a/lib/programmemory.h +++ b/lib/programmemory.h @@ -116,7 +116,7 @@ struct CPPCHECKLIB ProgramMemory { bool getContainerSizeValue(nonneg int exprid, MathLib::bigint& result) const; bool getContainerEmptyValue(nonneg int exprid, MathLib::bigint& result) const; - void setContainerSizeValue(const Token* expr, MathLib::bigint value, bool isEqual = true); + void setContainerSizeValue(const Token* expr, MathLib::bigint value, bool equal = true); void setUnknown(const Token* expr); diff --git a/lib/regex.cpp b/lib/regex.cpp index af3bf44e7cc..36048078a8a 100644 --- a/lib/regex.cpp +++ b/lib/regex.cpp @@ -177,7 +177,7 @@ namespace { } std::string compile(); - std::string match(const std::string& str, const MatchFn& match) const override; + std::string match(const std::string& str, const MatchFn& matchFn) const override; private: std::string mPattern; @@ -219,7 +219,7 @@ namespace { return ""; } - std::string PcreRegex::match(const std::string& str, const MatchFn& match) const + std::string PcreRegex::match(const std::string& str, const MatchFn& matchFn) const { if (!mRe) return "pcre_exec failed: regular expression has not been compiled yet"; @@ -236,7 +236,7 @@ namespace { const auto pos1 = static_cast(ovector[0]); const auto pos2 = static_cast(ovector[1]); - match(pos1, pos2); + matchFn(pos1, pos2); // jump to the end of the match for the next pcre_exec pos = static_cast(pos2); diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index c9851d6e7ca..3116768d6a7 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -2370,9 +2370,9 @@ void SymbolDatabase::validate() const validateVariables(); } -void SymbolDatabase::clangSetVariables(const std::vector &variableList) +void SymbolDatabase::clangSetVariables(const std::vector &list) { - mVariableList = variableList; + mVariableList = list; } void SymbolDatabase::debugSymbolDatabase() const @@ -2636,16 +2636,16 @@ void Variable::evaluate(const Settings& settings) } } -void Variable::setValueType(const ValueType &valueType) +void Variable::setValueType(const ValueType &vt) { - if (valueType.type == ValueType::Type::UNKNOWN_TYPE) { + if (vt.type == ValueType::Type::UNKNOWN_TYPE) { const Token *declType = Token::findsimplematch(mTypeStartToken, "decltype (", mTypeEndToken); if (declType && !declType->next()->valueType()) return; } - const auto* vt = new ValueType(valueType); + const auto* tmp = new ValueType(vt); delete mValueType; - mValueType = vt; + mValueType = tmp; if ((mValueType->pointer > 0) && (!isArray() || Token::Match(mNameToken->previous(), "( * %name% )"))) setFlag(fIsPointer, true); setFlag(fIsConst, mValueType->constness & (1U << mValueType->pointer)); diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index a4cdfc5370a..5a5ff289e3f 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -651,7 +651,7 @@ class CPPCHECKLIB Variable { return mValueType; } - void setValueType(const ValueType &valueType); + void setValueType(const ValueType &vt); AccessControl accessControl() const { return mAccess; @@ -1424,7 +1424,7 @@ class CPPCHECKLIB SymbolDatabase { /** Set array dimensions when valueflow analysis is completed */ void setArrayDimensionsUsingValueFlow(); - void clangSetVariables(const std::vector &variableList); + void clangSetVariables(const std::vector &list); void createSymbolDatabaseExprIds(); /* returns the opening { if tok points to enum */ diff --git a/lib/token.cpp b/lib/token.cpp index 4d1d2f5890f..7b1bcdeb2e6 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -211,9 +211,9 @@ static const std::unordered_set stdTypes = { "bool" , "unsigned" }; -bool Token::isStandardType(const std::string& str) +bool Token::isStandardType(const std::string& s) { - return stdTypes.find(str) != stdTypes.end(); + return stdTypes.find(s) != stdTypes.end(); } void Token::update_property_isStandardType() @@ -637,31 +637,31 @@ bool Token::simpleMatch(const Token *tok, const char pattern[], size_t pattern_l return true; } -bool Token::firstWordEquals(const char *str, const char *word) +bool Token::firstWordEquals(const char *s, const char *word) { for (;;) { - if (*str != *word) - return (*str == ' ' && *word == 0); - if (*str == 0) + if (*s != *word) + return (*s == ' ' && *word == 0); + if (*s == 0) break; - ++str; + ++s; ++word; } return true; } -const char *Token::chrInFirstWord(const char *str, char c) +const char *Token::chrInFirstWord(const char *s, char c) { for (;;) { - if (*str == ' ' || *str == 0) + if (*s == ' ' || *s == 0) return nullptr; - if (*str == c) - return str; + if (*s == c) + return s; - ++str; + ++s; } } @@ -1014,41 +1014,41 @@ Token *Token::findsimplematch(Token * const startTok, const char pattern[], size } template )> -static T *findmatchImpl(T * const startTok, const char pattern[], const nonneg int varId) +static T *findmatchImpl(T * const startTok, const char pattern[], const nonneg int varid) { for (T* tok = startTok; tok; tok = tok->next()) { - if (Token::Match(tok, pattern, varId)) + if (Token::Match(tok, pattern, varid)) return tok; } return nullptr; } -const Token *Token::findmatch(const Token * const startTok, const char pattern[], const nonneg int varId) +const Token *Token::findmatch(const Token * const startTok, const char pattern[], const nonneg int varid) { - return findmatchImpl(startTok, pattern, varId); + return findmatchImpl(startTok, pattern, varid); } -Token *Token::findmatch(Token * const startTok, const char pattern[], const nonneg int varId) { - return findmatchImpl(startTok, pattern, varId); +Token *Token::findmatch(Token * const startTok, const char pattern[], const nonneg int varid) { + return findmatchImpl(startTok, pattern, varid); } template )> -static T *findmatchImpl(T * const startTok, const char pattern[], const Token * const end, const nonneg int varId) +static T *findmatchImpl(T * const startTok, const char pattern[], const Token * const end, const nonneg int varid) { for (T* tok = startTok; tok && tok != end; tok = tok->next()) { - if (Token::Match(tok, pattern, varId)) + if (Token::Match(tok, pattern, varid)) return tok; } return nullptr; } -const Token *Token::findmatch(const Token * const startTok, const char pattern[], const Token * const end, const nonneg int varId) +const Token *Token::findmatch(const Token * const startTok, const char pattern[], const Token * const end, const nonneg int varid) { - return findmatchImpl(startTok, pattern, end, varId); + return findmatchImpl(startTok, pattern, end, varid); } -Token *Token::findmatch(Token * const startTok, const char pattern[], const Token * const end, const nonneg int varId) { - return findmatchImpl(startTok, pattern, end, varId); +Token *Token::findmatch(Token * const startTok, const char pattern[], const Token * const end, const nonneg int varid) { + return findmatchImpl(startTok, pattern, end, varid); } void Token::function(const Function *f) @@ -2664,26 +2664,26 @@ Token::Impl::~Impl() } } -void Token::Impl::setCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint value) +void Token::Impl::setCppcheckAttribute(CppcheckAttributesType attrType, MathLib::bigint value) { CppcheckAttributes *attr = mCppcheckAttributes; - while (attr && attr->type != type) + while (attr && attr->type != attrType) attr = attr->next; if (attr) attr->value = value; else { attr = new CppcheckAttributes; - attr->type = type; + attr->type = attrType; attr->value = value; attr->next = mCppcheckAttributes; mCppcheckAttributes = attr; } } -bool Token::Impl::getCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint &value) const +bool Token::Impl::getCppcheckAttribute(CppcheckAttributesType attrType, MathLib::bigint &value) const { const CppcheckAttributes *attr = mCppcheckAttributes; - while (attr && attr->type != type) + while (attr && attr->type != attrType) attr = attr->next; if (attr) value = attr->value; diff --git a/lib/token.h b/lib/token.h index 51fe1b6b7d0..cec3af882b0 100644 --- a/lib/token.h +++ b/lib/token.h @@ -174,8 +174,8 @@ class CPPCHECKLIB Token { std::int8_t mMutableExpr{-1}; - void setCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint value); - bool getCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint &value) const; + void setCppcheckAttribute(CppcheckAttributesType attrType, MathLib::bigint value); + bool getCppcheckAttribute(CppcheckAttributesType attrType, MathLib::bigint &value) const; Impl() = default; ~Impl(); @@ -872,8 +872,8 @@ class CPPCHECKLIB Token { } static const Token *findsimplematch(const Token * startTok, const char pattern[], size_t pattern_len, const Token * end); - static const Token *findmatch(const Token * startTok, const char pattern[], nonneg int varId = 0); - static const Token *findmatch(const Token * startTok, const char pattern[], const Token * end, nonneg int varId = 0); + static const Token *findmatch(const Token * startTok, const char pattern[], nonneg int varid = 0); + static const Token *findmatch(const Token * startTok, const char pattern[], const Token * end, nonneg int varid = 0); template static Token *findsimplematch(Token * const startTok, const char (&pattern)[count]) { @@ -886,8 +886,8 @@ class CPPCHECKLIB Token { } static Token *findsimplematch(Token * startTok, const char pattern[], size_t pattern_len, const Token * end); - static Token *findmatch(Token * startTok, const char pattern[], nonneg int varId = 0); - static Token *findmatch(Token * startTok, const char pattern[], const Token * end, nonneg int varId = 0); + static Token *findmatch(Token * startTok, const char pattern[], nonneg int varid = 0); + static Token *findmatch(Token * startTok, const char pattern[], const Token * end, nonneg int varid = 0); private: template )> @@ -1268,7 +1268,7 @@ class CPPCHECKLIB Token { static std::string typeStr(const Token* tok); - static bool isStandardType(const std::string& str); + static bool isStandardType(const std::string& s); /** * @return a pointer to the Enumerator associated with this token. @@ -1440,17 +1440,17 @@ class CPPCHECKLIB Token { /** * Works almost like strcmp() except returns only true or false and - * if str has empty space ' ' character, that character is handled + * if s has empty space ' ' character, that character is handled * as if it were '\\0' */ - static bool firstWordEquals(const char *str, const char *word); + static bool firstWordEquals(const char *s, const char *word); /** * Works almost like strchr() except - * if str has empty space ' ' character, that character is handled + * if s has empty space ' ' character, that character is handled * as if it were '\\0' */ - static const char *chrInFirstWord(const char *str, char c); + static const char *chrInFirstWord(const char *s, char c); RET_NONNULL Token* insertToken(const std::string& tokenStr, bool prepend); RET_NONNULL Token* insertToken(const std::string& tokenStr, const std::string& originalNameStr, bool prepend); diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 55ca98c628c..811f93c6708 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -2301,7 +2301,7 @@ bool TokenList::isCPP() const return mLang == Standards::Language::CPP; } -const Token * TokenList::isFunctionHead(const Token *tok, const std::string &endsWith) +const Token * TokenList::isFunctionHead(const Token *tok, const std::string &end) { if (!tok) return nullptr; @@ -2314,11 +2314,11 @@ const Token * TokenList::isFunctionHead(const Token *tok, const std::string &end if (Token::Match(tok, ") ;|{|[")) { tok = tok->next(); while (tok && tok->str() == "[" && tok->link()) { - if (endsWith.find(tok->str()) != std::string::npos) + if (end.find(tok->str()) != std::string::npos) return tok; tok = tok->link()->next(); } - return (tok && endsWith.find(tok->str()) != std::string::npos) ? tok : nullptr; + return (tok && end.find(tok->str()) != std::string::npos) ? tok : nullptr; } if (tok->isCpp() && tok->str() == ")") { tok = tok->next(); @@ -2353,7 +2353,7 @@ const Token * TokenList::isFunctionHead(const Token *tok, const std::string &end } if (tok && tok->str() == ":" && !Token::Match(tok->next(), "%name%|::")) return nullptr; - return (tok && endsWith.find(tok->str()) != std::string::npos) ? tok : nullptr; + return (tok && end.find(tok->str()) != std::string::npos) ? tok : nullptr; } return nullptr; } diff --git a/lib/tokenlist.h b/lib/tokenlist.h index 48cf5d99547..24f2d4571bf 100644 --- a/lib/tokenlist.h +++ b/lib/tokenlist.h @@ -206,10 +206,10 @@ class CPPCHECKLIB TokenList { /** * is token pointing at function head? * @param tok A '(' or ')' token in a possible function head - * @param endsWith string after function head + * @param end string after function head * @return token matching with endsWith if syntax seems to be a function head else nullptr */ - static const Token * isFunctionHead(const Token *tok, const std::string &endsWith); + static const Token * isFunctionHead(const Token *tok, const std::string &end); const Settings& getSettings() const { return mSettings; diff --git a/lib/vf_analyzers.cpp b/lib/vf_analyzers.cpp index 58fbe0b6d61..4e067172a29 100644 --- a/lib/vf_analyzers.cpp +++ b/lib/vf_analyzers.cpp @@ -673,12 +673,12 @@ struct ValueFlowAnalyzer : Analyzer { } template - std::vector evaluateInt(const Token* tok, F getProgramMemory) const + std::vector evaluateInt(const Token* tok, F getProgramMemoryFunc) const { if (const ValueFlow::Value* v = tok->getKnownValue(ValueFlow::Value::ValueType::INT)) return {static_cast(v->intvalue)}; std::vector result; - ProgramMemory pm = getProgramMemory(); + ProgramMemory pm = getProgramMemoryFunc(); if (Token::Match(tok, "&&|%oror%")) { if (conditionIsTrue(tok, pm, getSettings())) result.push_back(1); diff --git a/tools/triage/mainwindow.cpp b/tools/triage/mainwindow.cpp index 564d6e1bcf2..a210970105d 100644 --- a/tools/triage/mainwindow.cpp +++ b/tools/triage/mainwindow.cpp @@ -181,12 +181,12 @@ void MainWindow::refreshResults() filter(ui->version->currentText()); } -void MainWindow::filter(const QString& filter) +void MainWindow::filter(const QString& filterStr) { QStringList allErrors; for (const QString &errorItem : mAllErrors) { - if (filter.isEmpty()) { + if (filterStr.isEmpty()) { allErrors << errorItem; continue; } @@ -195,7 +195,7 @@ void MainWindow::filter(const QString& filter) if (lines.size() < 2) continue; - if (lines[1].startsWith(filter)) + if (lines[1].startsWith(filterStr)) allErrors << errorItem; } diff --git a/tools/triage/mainwindow.h b/tools/triage/mainwindow.h index 999740fb59d..38afcaf9553 100644 --- a/tools/triage/mainwindow.h +++ b/tools/triage/mainwindow.h @@ -46,7 +46,7 @@ class MainWindow : public QMainWindow { public slots: void loadFile(); void loadFromClipboard(); - void filter(const QString& filter); + void filter(const QString& filterStr); void showResult(QListWidgetItem *item); void refreshResults(); void fileTreeFilter(const QString &str);