Fixed #10752 (False positive: shadow variable in static method)

This commit is contained in:
Daniel Marjamäki 2022-01-28 16:03:06 +01:00
parent 38420c8ecf
commit 637aca8d59
2 changed files with 13 additions and 0 deletions

View File

@ -3273,6 +3273,8 @@ void CheckOther::checkShadowVariables()
continue;
if (scope.type == Scope::eFunction && scope.className == var.name())
continue;
if (functionScope->function && functionScope->function->isStatic() && shadowed->variable() && !shadowed->variable()->isLocal())
continue;
shadowError(var.nameToken(), shadowed, (shadowed->varId() != 0) ? "variable" : "function");
}
}

View File

@ -9323,6 +9323,17 @@ private:
check("class C { C(); void foo() { static int C = 0; } }"); // #9195 - shadow constructor
ASSERT_EQUALS("", errout.str());
// 10752 - no
check("struct S {\n"
" int i;\n"
"\n"
" static int foo() {\n"
" int i = 0;\n"
" return i;\n"
" }\n"
"};");
ASSERT_EQUALS("", errout.str());
}
void knownArgument() {