File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments