Fixed #1722 (Member variable initialized in call to base class constructor)

This commit is contained in:
Daniel Marjamäki 2010-06-06 08:29:35 +02:00
parent f75ca79849
commit 68ad8219ed
2 changed files with 18 additions and 0 deletions

View File

@ -238,6 +238,11 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *va
if (Assign && Token::Match(ftok, "%var% (")) if (Assign && Token::Match(ftok, "%var% ("))
{ {
initVar(varlist, ftok->strAt(0)); initVar(varlist, ftok->strAt(0));
// assignment in the initializer..
// : var(value = x)
if (Token::Match(ftok->tokAt(2), "%var% ="))
initVar(varlist, ftok->strAt(2));
} }
Assign |= (ftok->str() == ":"); Assign |= (ftok->str() == ":");

View File

@ -49,6 +49,7 @@ private:
TEST_CASE(uninitVar3); TEST_CASE(uninitVar3);
TEST_CASE(uninitVar4); TEST_CASE(uninitVar4);
TEST_CASE(uninitVar5); TEST_CASE(uninitVar5);
TEST_CASE(uninitVar6);
TEST_CASE(uninitVarEnum); TEST_CASE(uninitVarEnum);
TEST_CASE(uninitVarStream); TEST_CASE(uninitVarStream);
TEST_CASE(uninitVarTypedef); TEST_CASE(uninitVarTypedef);
@ -1524,6 +1525,18 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void uninitVar6()
{
checkUninitVar("class Foo : public Bar\n"
"{\n"
"public:\n"
" Foo(int i) : Bar(mi=i) { }\n"
"private:\n"
" int mi;\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void uninitVarArray1() void uninitVarArray1()
{ {
checkUninitVar("class John\n" checkUninitVar("class John\n"