Fixed #2158 (False positive: value is not unused when using +=)

This commit is contained in:
Daniel Marjamäki 2010-11-01 17:36:54 +01:00
parent 7e33b8fb9f
commit 3fb17baa12
2 changed files with 12 additions and 1 deletions

View File

@ -4369,7 +4369,7 @@ void Tokenizer::simplifyCompoundAssignment()
// "a+=b" => "a = a + b"
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::Match(tok, "; %var%"))
if (Token::Match(tok, "[;{}] %var%"))
{
const Token * const vartok = tok->next();
const std::string str = tok->strAt(2);

View File

@ -4598,6 +4598,17 @@ private:
ASSERT_EQUALS("; x = x ^ y ;", tokenizeAndStringify("; x ^= y;"));
ASSERT_EQUALS("; x = x << y ;", tokenizeAndStringify("; x <<= y;"));
ASSERT_EQUALS("; x = x >> y ;", tokenizeAndStringify("; x >>= y;"));
ASSERT_EQUALS("{ x = x + y ; }", tokenizeAndStringify("{ x += y;}"));
ASSERT_EQUALS("{ x = x - y ; }", tokenizeAndStringify("{ x -= y;}"));
ASSERT_EQUALS("{ x = x * y ; }", tokenizeAndStringify("{ x *= y;}"));
ASSERT_EQUALS("{ x = x / y ; }", tokenizeAndStringify("{ x /= y;}"));
ASSERT_EQUALS("{ x = x % y ; }", tokenizeAndStringify("{ x %= y;}"));
ASSERT_EQUALS("{ x = x & y ; }", tokenizeAndStringify("{ x &= y;}"));
ASSERT_EQUALS("{ x = x | y ; }", tokenizeAndStringify("{ x |= y;}"));
ASSERT_EQUALS("{ x = x ^ y ; }", tokenizeAndStringify("{ x ^= y;}"));
ASSERT_EQUALS("{ x = x << y ; }", tokenizeAndStringify("{ x <<= y;}"));
ASSERT_EQUALS("{ x = x >> y ; }", tokenizeAndStringify("{ x >>= y;}"));
}
void simplifyAssignmentInFunctionCall()