fix #2947 (False positive: member variable is not initialized (a[x::y] = 0;))

This commit is contained in:
Robert Reif 2011-07-27 12:03:44 -04:00
parent 54141f2e7f
commit ca2e8b057b
2 changed files with 23 additions and 4 deletions

View File

@ -500,20 +500,24 @@ void CheckClass::initializeVarList(const Function &func, std::list<std::string>
}
// Assignment of array item of member variable?
else if (Token::Match(ftok, "%var% [ %any% ] ="))
else if (Token::Match(ftok, "%var% [") &&
Token::simpleMatch(ftok->next()->link(), "] ="))
{
assignVar(ftok->str(), scope, usage);
}
// Assignment of member of array item of member variable?
else if (Token::Match(ftok, "%var% [ %any% ] . %var% =") ||
Token::Match(ftok, "%var% [ %any% ] . %var% . %var% ="))
else if (Token::Match(ftok, "%var% [ ") &&
(Token::Match(ftok->next()->link(), "] . %var% =") ||
Token::Match(ftok->next()->link(), "] . %var% . %var% =")))
{
assignVar(ftok->str(), scope, usage);
}
// Assignment of array item of member variable?
else if (Token::Match(ftok, "%var% [ %any% ] [ %any% ] ="))
else if (Token::Match(ftok, "%var% [") &&
Token::simpleMatch(ftok->next()->link(), "] [") &&
Token::simpleMatch(ftok->next()->link()->next()->link(), "] ="))
{
assignVar(ftok->str(), scope, usage);
}

View File

@ -65,6 +65,7 @@ private:
TEST_CASE(uninitVar18); // ticket #2465
TEST_CASE(uninitVar19); // ticket #2792
TEST_CASE(uninitVar20); // ticket #2867
TEST_CASE(uninitVar21); // ticket #2947
TEST_CASE(uninitVarEnum);
TEST_CASE(uninitVarStream);
TEST_CASE(uninitVarTypedef);
@ -2245,6 +2246,20 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'LocalClass::bitsInData_' is not initialized in the constructor.\n", errout.str());
}
void uninitVar21() // ticket #2947
{
checkUninitVar("class Fred {\n"
"private:\n"
" int a[23];\n"
"public:\n"
" Fred(); \n"
"};\n"
"Fred::Fred() {\n"
" a[x::y] = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void uninitVarArray1()
{
checkUninitVar("class John\n"