diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 5a9a7c7b4..5e5a15cff 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -666,7 +666,7 @@ static void eraseNotLocalArg(std::map& container, co { for (std::map::iterator i = container.begin(); i != container.end();) { const Variable* var = symbolDatabase->getVariableFromVarId(i->first); - if (!var || (!var->isLocal() && !var->isArgument())) { + if (!var || (!var->isLocal() && !var->isArgument()) || var->isStatic()) { container.erase(i++); if (i == container.end()) break; diff --git a/test/testother.cpp b/test/testother.cpp index 1003f6fe6..891a295b0 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -6544,6 +6544,13 @@ private: "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str()); + check("void f() {\n" + " static int i;\n" + " i = 1;\n" + " i = 1;\n" + "}"); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str()); + // Testing different types check("void f() {\n" " Foo& bar = foo();\n" @@ -6573,6 +6580,14 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + check("void f() {\n" + " static int i;\n" + " i = 1;\n" + " bar();\n" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229) + " i = 2;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + check("void f() {\n" " int i;\n" " i = 1;\n"