Fixed #1080 (false positive: member variable not initialized)

This commit is contained in:
Daniel Marjamäki 2009-12-11 21:34:04 +01:00
parent 9646f62ec1
commit 4d185f0935
2 changed files with 22 additions and 1 deletions

View File

@ -241,12 +241,20 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *va
break;
}
if (!Token::Match(ftok->next(), "%var%") && !Token::Match(ftok->next(), "this . %var%"))
if (!Token::Match(ftok->next(), "%var%") &&
!Token::Match(ftok->next(), "this . %var%") &&
!Token::Match(ftok->next(), "( * this ) . %var%"))
continue;
// Goto the first token in this statement..
ftok = ftok->next();
// Skip "( * this )"
if (Token::simpleMatch(ftok, "( * this ) ."))
{
ftok = ftok->tokAt(5);
}
// Skip "this->"
if (Token::simpleMatch(ftok, "this ."))
ftok = ftok->tokAt(2);

View File

@ -45,6 +45,7 @@ private:
TEST_CASE(virtualDestructorTemplate);
TEST_CASE(uninitVar1);
TEST_CASE(uninitVar2);
TEST_CASE(uninitVarEnum);
TEST_CASE(uninitVarStream);
TEST_CASE(uninitVarTypedef);
@ -397,6 +398,18 @@ private:
ASSERT_EQUALS("", errout.str());
}
void uninitVar2()
{
checkUninitVar("class John\n"
"{\n"
"public:\n"
" John() { (*this).i = 0; }\n"
"private:\n"
" int i;\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void uninitVarArray()
{
checkUninitVar("class John\n"