Fixed #2275 (False Positive: Member variable not initialized in the constructor)

This commit is contained in:
Robert Reif 2010-12-04 20:24:13 +01:00 committed by Daniel Marjamäki
parent 80b2c0594b
commit c20b8831ee
2 changed files with 40 additions and 0 deletions

View File

@ -1614,6 +1614,13 @@ void SymbolDatabase::SpaceInfo::initializeVarList(const Func &func, std::list<st
assignVar(ftok->str());
}
// Assignment of member of array item of member variable?
else if (Token::Match(ftok, "%var% [ %any% ] . %var% =") ||
Token::Match(ftok, "%var% [ %any% ] . %var% . %var% ="))
{
assignVar(ftok->str());
}
// Assignment of array item of member variable?
else if (Token::Match(ftok, "%var% [ %any% ] [ %any% ] ="))
{

View File

@ -60,6 +60,7 @@ private:
TEST_CASE(uninitVar14); // ticket #2149
TEST_CASE(uninitVar15);
TEST_CASE(uninitVar16);
TEST_CASE(uninitVar17);
TEST_CASE(uninitVarEnum);
TEST_CASE(uninitVarStream);
TEST_CASE(uninitVarTypedef);
@ -1987,6 +1988,38 @@ private:
ASSERT_EQUALS("[test.cpp:10]: (warning) Member variable not initialized in the constructor 'Bar::foo'\n", errout.str());
}
void uninitVar17()
{
checkUninitVar("struct Foo\n"
"{\n"
" int a;\n"
"};\n"
"class Bar\n"
"{\n"
" Foo foo[10];\n"
"public:\n"
" Bar()\n"
" {\n"
" foo[0].a = 0;\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("struct Foo\n"
"{\n"
" int a;\n"
"};\n"
"class Bar\n"
"{\n"
" Foo foo[10];\n"
"public:\n"
" Bar()\n"
" {\n"
" }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable not initialized in the constructor 'Bar::foo'\n", errout.str());
}
void uninitVarArray1()
{
checkUninitVar("class John\n"