Fixed #4229
This commit is contained in:
parent
1f87961c16
commit
65db8b8b9f
|
@ -666,7 +666,7 @@ static void eraseNotLocalArg(std::map<unsigned int, const Token*>& container, co
|
|||
{
|
||||
for (std::map<unsigned int, const Token*>::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;
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue