Ticket #8734: Skip static member variables in CheckUninitVar. (#1388)

This commit is contained in:
Simon Martin 2018-09-22 16:52:34 +02:00 committed by Daniel Marjamäki
parent d43cd56afd
commit 915acac0b8
2 changed files with 18 additions and 1 deletions

View File

@ -170,7 +170,8 @@ void CheckUninitVar::checkStruct(const Token *tok, const Variable &structvar)
for (std::list<Variable>::const_iterator it = scope2->varlist.begin(); it != scope2->varlist.end(); ++it) { for (std::list<Variable>::const_iterator it = scope2->varlist.begin(); it != scope2->varlist.end(); ++it) {
const Variable &var = *it; const Variable &var = *it;
if (var.hasDefault() || var.isArray() || (!mTokenizer->isC() && var.isClass() && (!var.type() || var.type()->needInitialization != Type::True))) if (var.isStatic() || var.hasDefault() || var.isArray() ||
(!mTokenizer->isC() && var.isClass() && (!var.type() || var.type()->needInitialization != Type::True)))
continue; continue;
// is the variable declared in a inner union? // is the variable declared in a inner union?

View File

@ -75,6 +75,7 @@ private:
TEST_CASE(uninitvar_pointertoarray); TEST_CASE(uninitvar_pointertoarray);
TEST_CASE(uninitvar_cpp11ArrayInit); // #7010 TEST_CASE(uninitvar_cpp11ArrayInit); // #7010
TEST_CASE(uninitvar_rangeBasedFor); // #7078 TEST_CASE(uninitvar_rangeBasedFor); // #7078
TEST_CASE(uninitvar_static); // #8734
TEST_CASE(trac_4871); TEST_CASE(trac_4871);
TEST_CASE(syntax_error); // Ticket #5073 TEST_CASE(syntax_error); // Ticket #5073
TEST_CASE(trac_5970); TEST_CASE(trac_5970);
@ -3811,6 +3812,21 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void uninitvar_static() { // #8734
checkUninitVar("struct X { "
" typedef struct { int p; } P_t; "
" static int arr[]; "
"}; "
"int X::arr[] = {42}; "
"void f() { "
" std::vector<X::P_t> result; "
" X::P_t P; "
" P.p = 0; "
" result.push_back(P); "
"}");
ASSERT_EQUALS("", errout.str());
}
void trac_4871() { // #4871 void trac_4871() { // #4871
checkUninitVar("void pickup(int a) {\n" checkUninitVar("void pickup(int a) {\n"
"bool using_planner_action;\n" "bool using_planner_action;\n"