partial fix for #2867 Tokenizer::removeRedundantAssignment didn't understand function local class and removed class variable
This commit is contained in:
parent
70a32fc245
commit
f403de7bad
|
@ -4707,7 +4707,9 @@ void Tokenizer::removeRedundantAssignment()
|
||||||
const Token * const end = tok->next()->link();
|
const Token * const end = tok->next()->link();
|
||||||
for (Token *tok2 = tok->next(); tok2 && tok2 != end; tok2 = tok2->next())
|
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);
|
tok2 = tok2->tokAt(3);
|
||||||
localvars.insert(tok2->varId());
|
localvars.insert(tok2->varId());
|
||||||
|
|
|
@ -64,6 +64,7 @@ private:
|
||||||
TEST_CASE(uninitVar17);
|
TEST_CASE(uninitVar17);
|
||||||
TEST_CASE(uninitVar18); // ticket #2465
|
TEST_CASE(uninitVar18); // ticket #2465
|
||||||
TEST_CASE(uninitVar19); // ticket #2792
|
TEST_CASE(uninitVar19); // ticket #2792
|
||||||
|
TEST_CASE(uninitVar20); // ticket #2867
|
||||||
TEST_CASE(uninitVarEnum);
|
TEST_CASE(uninitVarEnum);
|
||||||
TEST_CASE(uninitVarStream);
|
TEST_CASE(uninitVarStream);
|
||||||
TEST_CASE(uninitVarTypedef);
|
TEST_CASE(uninitVarTypedef);
|
||||||
|
@ -2210,6 +2211,19 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
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()
|
void uninitVarArray1()
|
||||||
{
|
{
|
||||||
checkUninitVar("class John\n"
|
checkUninitVar("class John\n"
|
||||||
|
|
Loading…
Reference in New Issue