diff --git a/lib/checkother.cpp b/lib/checkother.cpp index fccd25ca4..a8b279a52 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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"); } diff --git a/test/testother.cpp b/test/testother.cpp index 21da5c39d..bf31fcf28 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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() {