FIx FN shadowVariable in static function (#4079)

* FIx FN shadowVariable in static function

* Use functionOf
This commit is contained in:
chrchr-github 2022-05-04 17:56:16 +02:00 committed by GitHub
parent e2069dd1b9
commit 9a379925cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -3407,7 +3407,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())
if (functionScope->functionOf && functionScope->functionOf->isClassOrStructOrUnion() && functionScope->function && functionScope->function->isStatic() &&
shadowed->variable() && !shadowed->variable()->isLocal())
continue;
shadowError(var.nameToken(), shadowed, (shadowed->varId() != 0) ? "variable" : "function");
}

View File

@ -9712,6 +9712,14 @@ private:
" for (const F& f : fl) {}\n"
"};\n");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:7]: (style) Local variable 'f' shadows outer variable\n", errout.str());
check("extern int a;\n"
"int a;\n"
"static int f(void) {\n"
" int a;\n"
" return 0;\n"
"}\n", "test.c");
ASSERT_EQUALS("[test.c:1] -> [test.c:4]: (style) Local variable 'a' shadows outer variable\n", errout.str());
}
void knownArgument() {