From 151cdfc5dd316b04355d6bfa22e66b7ef14bd945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 1 Jun 2026 14:25:36 +0200 Subject: [PATCH 1/3] add test --- test/testother.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 93e67229f43..fc206013931 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -13124,6 +13124,9 @@ class TestOther : public TestFixture { check("struct S { static int i(); static void f(int i) {} };\n"); ASSERT_EQUALS("[test.cpp:1:23] -> [test.cpp:1:46]: (style) Argument 'i' shadows outer function [shadowFunction]\n", errout_str()); + + check("struct S { void g(float f) {} void f() {} };\n"); + ASSERT_EQUALS("[test.cpp:1:36] -> [test.cpp:1:25]: (style) Argument 'f' shadows outer function [shadowFunction]\n", errout_str()); } void knownArgument() { From a1b67a68c31d1f563ab8fb8ef591ab049ddd6b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 1 Jun 2026 14:25:43 +0200 Subject: [PATCH 2/3] fix --- lib/checkother.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index b5fd0dda361..d339d549f0e 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -4140,7 +4140,8 @@ static const Token *findShadowed(const Scope *scope, const Variable& var, int li return v.nameToken(); } auto it = std::find_if(scope->functionList.cbegin(), scope->functionList.cend(), [&](const Function& f) { - return f.type == FunctionType::eFunction && f.name() == var.name() && precedes(f.tokenDef, var.nameToken()); + return f.type == FunctionType::eFunction && f.name() == var.name() + && (scope->isClassOrStructOrUnion() || precedes(f.tokenDef, var.nameToken())); }); if (it != scope->functionList.end()) return it->tokenDef; From 509375efd25db41f6749c4078b337f4e3baa55bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Tue, 2 Jun 2026 13:24:47 +0200 Subject: [PATCH 3/3] fix new warnings --- lib/filesettings.h | 8 ++++---- lib/token.h | 42 +++++++++++++++++++-------------------- lib/tokenize.cpp | 18 ++++++++--------- test/testpreprocessor.cpp | 4 ++-- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/lib/filesettings.h b/lib/filesettings.h index 183e38708fd..a9d6ee0f2b2 100644 --- a/lib/filesettings.h +++ b/lib/filesettings.h @@ -46,9 +46,9 @@ class FileWithDetails throw std::runtime_error("empty path specified"); } - void setPath(std::string path) + void setPath(std::string p) { - mPath = std::move(path); + mPath = std::move(p); mPathSimplified = Path::simplifyPath(mPath); mPathAbsolute.clear(); } @@ -76,9 +76,9 @@ class FileWithDetails return mSize; } - void setLang(Standards::Language lang) + void setLang(Standards::Language language) { - mLang = lang; + mLang = language; } Standards::Language lang() const diff --git a/lib/token.h b/lib/token.h index ca945fcab22..85c93329952 100644 --- a/lib/token.h +++ b/lib/token.h @@ -249,35 +249,35 @@ class CPPCHECKLIB Token { * For example index 1 would return next token, and 2 * would return next from that one. */ - const Token *tokAt(int index) const + const Token *tokAt(int idx) const { - return tokAtImpl(this, index); + return tokAtImpl(this, idx); } - Token *tokAt(int index) + Token *tokAt(int idx) { - return tokAtImpl(this, index); + return tokAtImpl(this, idx); } /** * @return the link to the token in given index, related to this token. * For example index 1 would return the link to next token. */ - const Token *linkAt(int index) const + const Token *linkAt(int idx) const { - return linkAtImpl(this, index); + return linkAtImpl(this, idx); } - Token *linkAt(int index) + Token *linkAt(int idx) { - return linkAtImpl(this, index); + return linkAtImpl(this, idx); } /** * @return String of the token in given index, related to this token. * If that token does not exist, an empty string is being returned. */ - const std::string &strAt(int index) const + const std::string &strAt(int idx) const { - const Token *tok = this->tokAt(index); + const Token *tok = this->tokAt(idx); return tok ? tok->mStr : mEmptyString; } @@ -604,11 +604,11 @@ class CPPCHECKLIB Token { bool hasAttributeCleanup() const { return !mImpl->mAttributeCleanup.empty(); } - void setCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint value) { - mImpl->setCppcheckAttribute(type, value); + void setCppcheckAttribute(CppcheckAttributesType attrType, MathLib::bigint value) { + mImpl->setCppcheckAttribute(attrType, value); } - bool getCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint &value) const { - return mImpl->getCppcheckAttribute(type, value); + bool getCppcheckAttribute(CppcheckAttributesType attrType, MathLib::bigint &value) const { + return mImpl->getCppcheckAttribute(attrType, value); } // cppcheck-suppress unusedFunction bool hasCppcheckAttributes() const { @@ -891,15 +891,15 @@ class CPPCHECKLIB Token { private: template )> - static T *tokAtImpl(T *tok, int index) + static T *tokAtImpl(T *tok, int idx) { - while (index > 0 && tok) { + while (idx > 0 && tok) { tok = tok->next(); - --index; + --idx; } - while (index < 0 && tok) { + while (idx < 0 && tok) { tok = tok->previous(); - ++index; + ++idx; } return tok; } @@ -908,9 +908,9 @@ class CPPCHECKLIB Token { * @throws InternalError thrown if index is out of range */ template )> - static T *linkAtImpl(T *thisTok, int index) + static T *linkAtImpl(T *thisTok, int idx) { - T *tok = thisTok->tokAt(index); + T *tok = thisTok->tokAt(idx); if (!tok) { throw InternalError(thisTok, "Internal error. Token::linkAt called with index outside the tokens range."); } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 6305e0f021a..e03ab9b24fd 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -568,23 +568,23 @@ namespace { const std::pair rangeBefore(start, Token::findsimplematch(start, "{")); // find typedef name token - Token* nameToken = rangeBefore.second->link()->next(); - while (Token::Match(nameToken, "%name%|* %name%|*")) - nameToken = nameToken->next(); - const std::pair rangeQualifiers(rangeBefore.second->link()->next(), nameToken); + Token* nameTok = rangeBefore.second->link()->next(); + while (Token::Match(nameTok, "%name%|* %name%|*")) + nameTok = nameTok->next(); + const std::pair rangeQualifiers(rangeBefore.second->link()->next(), nameTok); - if (Token::Match(nameToken, "%name% ;")) { + if (Token::Match(nameTok, "%name% ;")) { if (Token::Match(rangeBefore.second->previous(), "enum|struct|union|class {")) - rangeBefore.second->previous()->insertToken(nameToken->str()); + rangeBefore.second->previous()->insertToken(nameTok->str()); mRangeType = rangeBefore; mRangeTypeQualifiers = rangeQualifiers; Token* typeName = rangeBefore.second->previous(); if (typeName->isKeyword()) { // TODO typeName->insertToken("T:" + std::to_string(num++)); - typeName->insertToken(nameToken->str()); + typeName->insertToken(nameTok->str()); } - mNameToken = nameToken; - mEndToken = nameToken->next(); + mNameToken = nameTok; + mEndToken = nameTok->next(); return; } } diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 7e01f6f233b..606f34a0dd9 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -140,8 +140,8 @@ class TestPreprocessor : public TestFixture { cfgs = preprocessor.getConfigs(); for (const std::string & config : cfgs) { try { - const bool writeLocations = (strstr(code, "#file") != nullptr) || (strstr(code, "#include") != nullptr); - cfgcode[config] = preprocessor.getcode(config, files, writeLocations); + const bool writeLocs = (strstr(code, "#file") != nullptr) || (strstr(code, "#include") != nullptr); + cfgcode[config] = preprocessor.getcode(config, files, writeLocs); } catch (const simplecpp::Output &) { cfgcode[config] = ""; }