Skip to content

Commit 75b217d

Browse files
committed
Fix #14471 (Improve check: shadowVariable for function argument)
1 parent 3a99f41 commit 75b217d

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

lib/checkother.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4082,12 +4082,28 @@ void CheckOther::checkShadowVariables()
40824082
return;
40834083
logChecker("CheckOther::checkShadowVariables"); // style
40844084
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
4085+
40854086
for (const Scope & scope : symbolDatabase->scopeList) {
40864087
if (!scope.isExecutable() || scope.type == ScopeType::eLambda)
40874088
continue;
40884089
const Scope *functionScope = &scope;
40894090
while (functionScope && functionScope->type != ScopeType::eFunction && functionScope->type != ScopeType::eLambda)
40904091
functionScope = functionScope->nestedIn;
4092+
4093+
// Check shadowed variables in the outer scope
4094+
if (scope.type == ScopeType::eFunction && scope.function) {
4095+
for (const Variable &arg : scope.function->argumentList) {
4096+
if (arg.nameToken() && arg.nameToken()->isExpandedMacro())
4097+
continue;
4098+
const Token *shadowed = findShadowed(scope.nestedIn, arg, arg.nameToken()->linenr());
4099+
if (!shadowed)
4100+
shadowed = findShadowed(scope.functionOf, arg, arg.nameToken()->linenr());
4101+
if (shadowed)
4102+
shadowError(arg.nameToken(), shadowed, (shadowed->varId() != 0) ? "variable" : "function");
4103+
}
4104+
}
4105+
4106+
// Check shadowed variables in the inner scope
40914107
for (const Variable &var : scope.varlist) {
40924108
if (var.nameToken() && var.nameToken()->isExpandedMacro()) // #8903
40934109
continue;

0 commit comments

Comments
 (0)