Fixed #1535 (False positive: member variable not initialized, struct with constructor)

This commit is contained in:
Daniel Marjamäki 2010-03-29 20:34:47 +02:00
parent 0bddd1977f
commit c213227133
2 changed files with 17 additions and 1 deletions

View File

@ -152,7 +152,7 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo
// Array? // Array?
else if (Token::Match(next, "%type% %var% [") && next->next()->str() != "operator") else if (Token::Match(next, "%type% %var% [") && next->next()->str() != "operator")
{ {
if (Token::findmatch(_tokenizer->tokens(), ("class " + next->str()).c_str())) if (Token::findmatch(_tokenizer->tokens(), ("class|struct " + next->str()).c_str()))
continue; continue;
varname = next->strAt(1); varname = next->strAt(1);
} }

View File

@ -46,6 +46,7 @@ private:
TEST_CASE(uninitVar1); TEST_CASE(uninitVar1);
TEST_CASE(uninitVar2); TEST_CASE(uninitVar2);
TEST_CASE(uninitVar3);
TEST_CASE(uninitVarEnum); TEST_CASE(uninitVarEnum);
TEST_CASE(uninitVarStream); TEST_CASE(uninitVarStream);
TEST_CASE(uninitVarTypedef); TEST_CASE(uninitVarTypedef);
@ -1107,6 +1108,21 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void uninitVar3()
{
checkUninitVar("class Foo\n"
"{\n"
"public:\n"
" Foo() { }\n"
"private:\n"
" struct Bar {\n"
" Bar();\n"
" };\n"
" Bar bars[2];\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void uninitVarArray1() void uninitVarArray1()
{ {
checkUninitVar("class John\n" checkUninitVar("class John\n"