Fixed #2225 (false positive: variable is assigned a value that is never used '*(stack[0])+=arg')
This commit is contained in:
parent
1842a122da
commit
22a4dd2cc3
|
@ -4467,7 +4467,7 @@ void Tokenizer::simplifyCompoundAssignment()
|
||||||
// "a+=b" => "a = a + b"
|
// "a+=b" => "a = a + b"
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
if (Token::Match(tok, "[;{}:] *| %var%"))
|
if (Token::Match(tok, "[;{}:] *| (| %var%"))
|
||||||
{
|
{
|
||||||
if (tok->str() == ":")
|
if (tok->str() == ":")
|
||||||
{
|
{
|
||||||
|
@ -4481,6 +4481,12 @@ void Tokenizer::simplifyCompoundAssignment()
|
||||||
if (tok->strAt(1) == "*")
|
if (tok->strAt(1) == "*")
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
||||||
|
if (tok->strAt(1) == "(")
|
||||||
|
{
|
||||||
|
tok = tok->next()->link()->next();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// variable..
|
// variable..
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
while (Token::Match(tok, ". %var%") || (tok && tok->str() == "["))
|
while (Token::Match(tok, ". %var%") || (tok && tok->str() == "["))
|
||||||
|
@ -4501,6 +4507,7 @@ void Tokenizer::simplifyCompoundAssignment()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!tok)
|
if (!tok)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -4526,15 +4533,18 @@ void Tokenizer::simplifyCompoundAssignment()
|
||||||
// simplify the compound assignment..
|
// simplify the compound assignment..
|
||||||
tok->str("=");
|
tok->str("=");
|
||||||
tok->insertToken(op);
|
tok->insertToken(op);
|
||||||
Token *tokend = 0;
|
std::stack<Token *> tokend;
|
||||||
for (const Token *tok2 = tok->previous(); tok2 && tok2 != tok1; tok2 = tok2->previous())
|
for (const Token *tok2 = tok->previous(); tok2 && tok2 != tok1; tok2 = tok2->previous())
|
||||||
{
|
{
|
||||||
tok->insertToken(tok2->str());
|
tok->insertToken(tok2->str());
|
||||||
tok->next()->varId(tok2->varId());
|
tok->next()->varId(tok2->varId());
|
||||||
if (Token::simpleMatch(tok->next(), "]"))
|
if (Token::Match(tok->next(), "]|)"))
|
||||||
tokend = tok->next();
|
tokend.push(tok->next());
|
||||||
else if (Token::simpleMatch(tok->next(), "["))
|
else if (Token::Match(tok->next(), "(|["))
|
||||||
Token::createMutualLinks(tok->next(), tokend);
|
{
|
||||||
|
Token::createMutualLinks(tok->next(), tokend.top());
|
||||||
|
tokend.pop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4694,6 +4694,7 @@ private:
|
||||||
ASSERT_EQUALS("{ x = x >> y ; }", tokenizeAndStringify("{ x >>= y;}"));
|
ASSERT_EQUALS("{ x = x >> y ; }", tokenizeAndStringify("{ x >>= y;}"));
|
||||||
|
|
||||||
ASSERT_EQUALS("; * p = * p + y ;", tokenizeAndStringify("; *p += y;"));
|
ASSERT_EQUALS("; * p = * p + y ;", tokenizeAndStringify("; *p += y;"));
|
||||||
|
ASSERT_EQUALS("; * ( p [ 0 ] ) = * ( p [ 0 ] ) + y ;", tokenizeAndStringify("; *(p[0]) += y;"));
|
||||||
|
|
||||||
ASSERT_EQUALS("case 0 : x = x + y ; break ;", tokenizeAndStringify("case 0: x += y; break;"));
|
ASSERT_EQUALS("case 0 : x = x + y ; break ;", tokenizeAndStringify("case 0: x += y; break;"));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue