Skip to content

Commit

Permalink
Update checkother.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Apr 5, 2024
1 parent aa9b4d8 commit 9853278
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3577,27 +3577,27 @@ void CheckOther::funcArgOrderDifferent(const std::string & functionName,
reportError(tokens, Severity::warning, "funcArgOrderDifferent", msg, CWE683, Certainty::normal);
}

static const Token *findShadowed(const Scope *scope, const std::string &varname, int linenr)
static const Token *findShadowed(const Scope *scope, const Variable& var, int linenr)
{
if (!scope)
return nullptr;
for (const Variable &var : scope->varlist) {
if (scope->isExecutable() && var.nameToken()->linenr() > linenr)
for (const Variable &v : scope->varlist) {
if (scope->isExecutable() && v.nameToken()->linenr() > linenr)
continue;
if (var.name() == varname)
return var.nameToken();
if (v.name() == var.name())
return v.nameToken();
}
auto it = std::find_if(scope->functionList.cbegin(), scope->functionList.cend(), [&](const Function& f) {
return f.type == Function::Type::eFunction && f.name() == varname;
return f.type == Function::Type::eFunction && f.name() == var.name() && precedes(f.tokenDef, var.nameToken());
});
if (it != scope->functionList.end())
return it->tokenDef;

if (scope->type == Scope::eLambda)
return nullptr;
const Token* shadowed = findShadowed(scope->nestedIn, varname, linenr);
const Token* shadowed = findShadowed(scope->nestedIn, var, linenr);
if (!shadowed)
shadowed = findShadowed(scope->functionOf, varname, linenr);
shadowed = findShadowed(scope->functionOf, var, linenr);
return shadowed;
}

Expand Down Expand Up @@ -3628,9 +3628,9 @@ void CheckOther::checkShadowVariables()
}
}

const Token *shadowed = findShadowed(scope.nestedIn, var.name(), var.nameToken()->linenr());
const Token *shadowed = findShadowed(scope.nestedIn, var, var.nameToken()->linenr());
if (!shadowed)
shadowed = findShadowed(scope.functionOf, var.name(), var.nameToken()->linenr());
shadowed = findShadowed(scope.functionOf, var, var.nameToken()->linenr());
if (!shadowed)
continue;
if (scope.type == Scope::eFunction && scope.className == var.name())
Expand Down

0 comments on commit 9853278

Please sign in to comment.