Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4194,6 +4194,9 @@ void CheckOtherImpl::checkShadowVariables()
(functionScope->function->isStatic() || functionScope->function->isFriend()) &&
shadowed->variable() && !shadowed->variable()->isLocal())
return;
if (functionScope->functionOf && functionScope->functionOf->isClassOrStructOrUnion() && functionScope->function &&
functionScope->function->isStatic() && shadowed->function() && !shadowed->function()->isStatic())
return;
if (var.scope() && var.scope()->function && var.scope()->function->isConstructor()) {
if (shadowed->variable() && shadowed->variable()->isMember())
return;
Expand Down
7 changes: 0 additions & 7 deletions lib/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,6 @@ bool Token::simpleMatch(const Token *tok, const char pattern[], size_t pattern_l
return false; // shortcut
const char *current = pattern;
const char *end = pattern + pattern_len;
// cppcheck-suppress shadowFunction - TODO: fix this
const char *next = static_cast<const char*>(std::memchr(pattern, ' ', pattern_len));
if (!next)
next = end;
Expand Down Expand Up @@ -769,7 +768,6 @@ nonneg int Token::getStrArraySize(const Token *tok)
{
assert(tok != nullptr);
assert(tok->tokType() == eString);
// cppcheck-suppress shadowFunction - TODO: fix this
const std::string str(getStringLiteral(tok->str()));
int sizeofstring = 1;
for (int i = 0; i < static_cast<int>(str.size()); i++) {
Expand Down Expand Up @@ -2359,11 +2357,9 @@ const ::Type* Token::typeOf(const Token* tok, const Token** typeTok)
if (tok->valueType() && tok->valueType()->typeScope && tok->valueType()->typeScope->definedType)
return tok->valueType()->typeScope->definedType;
if (Token::simpleMatch(tok, "return")) {
// cppcheck-suppress shadowFunction - TODO: fix this
const Scope *scope = tok->scope();
if (!scope)
return nullptr;
// cppcheck-suppress shadowFunction - TODO: fix this
const Function *function = scope->function;
if (!function)
return nullptr;
Expand Down Expand Up @@ -2473,18 +2469,15 @@ std::pair<const Token*, const Token*> Token::typeDecl(const Token* tok, bool poi
return {var->typeStartToken(), var->typeEndToken()->next()};
}
if (Token::simpleMatch(tok, "return")) {
// cppcheck-suppress shadowFunction - TODO: fix this
const Scope* scope = tok->scope();
if (!scope)
return {};
// cppcheck-suppress shadowFunction - TODO: fix this
const Function* function = scope->function;
if (!function)
return {};
return { function->retDef, function->returnDefEnd() };
}
if (tok->previous() && tok->previous()->function()) {
// cppcheck-suppress shadowFunction - TODO: fix this
const Function *function = tok->previous()->function();
return {function->retDef, function->returnDefEnd()};
}
Expand Down
6 changes: 6 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13118,6 +13118,12 @@ 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 i(); static void f(int i) {} };\n");
ASSERT_EQUALS("", errout_str());

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());
}

void knownArgument() {
Expand Down
Loading