Fix ticket #457 (False positive: Member variable not assigned a value in copy constructor)
http://sourceforge.net/apps/trac/cppcheck/ticket/457 Simplify "a = 0, b = 0;" into "a = 0; b = 0;"
This commit is contained in:
parent
c43073049d
commit
e858ab2f0d
|
@ -1494,7 +1494,7 @@ void Tokenizer::simplifyTokenList()
|
|||
modified |= simplifyQuestionMark();
|
||||
}
|
||||
|
||||
simplifyCommaNearKeyWords();
|
||||
simplifyComma();
|
||||
createLinks();
|
||||
if (_settings._debug)
|
||||
{
|
||||
|
@ -3012,7 +3012,7 @@ void Tokenizer::syntaxError(const Token *tok, char c)
|
|||
|
||||
}
|
||||
|
||||
bool Tokenizer::simplifyCommaNearKeyWords()
|
||||
bool Tokenizer::simplifyComma()
|
||||
{
|
||||
bool ret = false;
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
|
@ -3028,14 +3028,34 @@ bool Tokenizer::simplifyCommaNearKeyWords()
|
|||
tok->str(";");
|
||||
ret = true;
|
||||
}
|
||||
else if (tok->previous() &&
|
||||
Token::Match(tok->previous()->previous(), "delete") &&
|
||||
tok->next()->varId() != 0)
|
||||
|
||||
if (tok->previous() && tok->previous()->previous())
|
||||
{
|
||||
// Handle "delete a, b;"
|
||||
tok->str(";");
|
||||
tok->insertToken("delete");
|
||||
ret = true;
|
||||
if (Token::Match(tok->previous()->previous(), "delete") &&
|
||||
tok->next()->varId() != 0)
|
||||
{
|
||||
// Handle "delete a, b;"
|
||||
tok->str(";");
|
||||
tok->insertToken("delete");
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Token *tok2 = tok->previous(); tok2; tok2 = tok2->previous())
|
||||
{
|
||||
if (tok2->str() == "=")
|
||||
{
|
||||
// Handle "a = 0, b = 0;"
|
||||
tok->str(";");
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
else if (Token::Match(tok2, "[;,{}()]"))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -153,12 +153,13 @@ public:
|
|||
bool simplifyNot();
|
||||
|
||||
/**
|
||||
* Simplify comma near keywords into a semicolon
|
||||
* Simplify comma into a semicolon when possible
|
||||
* Example: "delete a, delete b" => "delete a; delete b;"
|
||||
* Example: "a = 0, b = 0;" => "a = 0; b = 0;"
|
||||
* @return true if something is modified
|
||||
* false if nothing is done.
|
||||
*/
|
||||
bool simplifyCommaNearKeyWords();
|
||||
bool simplifyComma();
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -1033,7 +1033,7 @@ private:
|
|||
" a=0,\n"
|
||||
" b=0;\n"
|
||||
"}\n";
|
||||
TODO_ASSERT_EQUALS(" void f ( ) { int a ; int b ; if ( a ) { a = 0 ; b = 0 ; } }", sizeof_(code));
|
||||
ASSERT_EQUALS(" void f ( ) { int a ; int b ; if ( a ) { a = 0 ; b = 0 ; } }", sizeof_(code));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -1044,7 +1044,7 @@ private:
|
|||
" a.f=b.f,\n"
|
||||
" a.g=b.g;\n"
|
||||
"}\n";
|
||||
TODO_ASSERT_EQUALS(" void f ( ) { A a ; A b ; if ( a . f ) { a . f = b . f ; a . g = b . g ; } }", sizeof_(code));
|
||||
ASSERT_EQUALS(" void f ( ) { A a ; A b ; if ( a . f ) { a . f = b . f ; a . g = b . g ; } }", sizeof_(code));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue