Fixed false positive #5566.
This commit is contained in:
parent
5e2ea8b6cd
commit
a8dc17c1d9
|
@ -830,6 +830,19 @@ static bool checkFunctionUsage(const std::string& name, const Scope* scope)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (std::list<Variable>::const_iterator i = scope->varlist.begin(); i != scope->varlist.end(); ++i) {
|
||||||
|
if (i->isStatic()) {
|
||||||
|
const Token* tok = Token::findmatch(scope->classEnd, "%varid% =|(|{", i->declarationId());
|
||||||
|
if (tok)
|
||||||
|
tok = tok->tokAt(2);
|
||||||
|
while (tok && tok->str() != ";") {
|
||||||
|
if (tok->str() == name && (tok->strAt(-1) == "." || tok->strAt(-2) == scope->className))
|
||||||
|
return true;
|
||||||
|
tok = tok->next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false; // Unused in this scope
|
return false; // Unused in this scope
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1286,7 +1286,7 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
|
||||||
if (tok2->isName() && tok2->next()->isName())
|
if (tok2->isName() && tok2->next()->isName())
|
||||||
condition += ' ';
|
condition += ' ';
|
||||||
}
|
}
|
||||||
reportError(tok, Severity::debug, "debug", "bailout uninitialized variable checking for '" + var.nameToken()->str() + "'. can't determine if this condition can be false when previous condition is false: " + condition);
|
reportError(tok, Severity::debug, "debug", "bailout uninitialized variable checking for '" + var.name() + "'. can't determine if this condition can be false when previous condition is false: " + condition);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,8 @@ private:
|
||||||
TEST_CASE(multiFile);
|
TEST_CASE(multiFile);
|
||||||
TEST_CASE(unknownBaseTemplate); // ticket #2580
|
TEST_CASE(unknownBaseTemplate); // ticket #2580
|
||||||
TEST_CASE(hierarchie_loop); // ticket 5590
|
TEST_CASE(hierarchie_loop); // ticket 5590
|
||||||
|
|
||||||
|
TEST_CASE(staticVariable); //ticket #5566
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -725,6 +727,30 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:10]: (style) Unused private function: 'InfiniteA::foo'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:10]: (style) Unused private function: 'InfiniteA::foo'\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void staticVariable() {
|
||||||
|
check("class Foo {\n"
|
||||||
|
" static int i;\n"
|
||||||
|
" static int F() const { return 1; }\n"
|
||||||
|
"};\n"
|
||||||
|
"int Foo::i = Foo::F();");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("class Foo {\n"
|
||||||
|
" static int i;\n"
|
||||||
|
" int F() const { return 1; }\n"
|
||||||
|
"};\n"
|
||||||
|
"Foo f;\n"
|
||||||
|
"int Foo::i = f.F();");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("class Foo {\n"
|
||||||
|
" static int i;\n"
|
||||||
|
" static int F() const { return 1; }\n"
|
||||||
|
"};\n"
|
||||||
|
"int Foo::i = sth();"
|
||||||
|
"int i = F();");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (style) Unused private function: 'Foo::F'\n", errout.str());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestUnusedPrivateFunction)
|
REGISTER_TEST(TestUnusedPrivateFunction)
|
||||||
|
|
Loading…
Reference in New Issue