partial fix for #2867 Tokenizer::removeRedundantAssignment didn't understand function local class and removed class variable

This commit is contained in:
Robert Reif 2011-06-28 19:48:28 -04:00
parent 70a32fc245
commit f403de7bad
2 changed files with 17 additions and 1 deletions

View File

@ -4707,7 +4707,9 @@ void Tokenizer::removeRedundantAssignment()
const Token * const end = tok->next()->link();
for (Token *tok2 = tok->next(); tok2 && tok2 != end; tok2 = tok2->next())
{
if (Token::Match(tok2, "[;{}] %type% * %var% ;") && tok2->strAt(1) != "return")
if (Token::Match(tok2, "class|struct %type% {"))
tok2 = tok2->tokAt(2)->link(); // skip local class or struct
else if (Token::Match(tok2, "[;{}] %type% * %var% ;") && tok2->strAt(1) != "return")
{
tok2 = tok2->tokAt(3);
localvars.insert(tok2->varId());

View File

@ -64,6 +64,7 @@ private:
TEST_CASE(uninitVar17);
TEST_CASE(uninitVar18); // ticket #2465
TEST_CASE(uninitVar19); // ticket #2792
TEST_CASE(uninitVar20); // ticket #2867
TEST_CASE(uninitVarEnum);
TEST_CASE(uninitVarStream);
TEST_CASE(uninitVarTypedef);
@ -2210,6 +2211,19 @@ private:
ASSERT_EQUALS("", errout.str());
}
void uninitVar20() // ticket #2867
{
checkUninitVar("Object::MemFunc() {\n"
" class LocalClass {\n"
" public:\n"
" LocalClass() : dataLength_(0) {}\n"
" std::streamsize dataLength_;\n"
" double bitsInData_;\n"
" } obj;\n"
"};\n");
ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'LocalClass::bitsInData_' is not initialized in the constructor.\n", errout.str());
}
void uninitVarArray1()
{
checkUninitVar("class John\n"