Fixed #2498 (False positive: redundant assignment)

This commit is contained in:
Daniel Marjamäki 2011-02-04 21:08:42 +01:00
parent 40b8c1d83f
commit 5640845a17
2 changed files with 10 additions and 2 deletions

View File

@ -289,7 +289,8 @@ void CheckOther::checkSelfAssignment()
const Token *tok = Token::findmatch(_tokenizer->tokens(), selfAssignmentPattern); const Token *tok = Token::findmatch(_tokenizer->tokens(), selfAssignmentPattern);
while (tok) while (tok)
{ {
if (tok->varId() && tok->varId() == tok->tokAt(2)->varId()) if (Token::Match(tok->previous(), "[;{}]") &&
tok->varId() && tok->varId() == tok->tokAt(2)->varId())
{ {
selfAssignmentError(tok, tok->str()); selfAssignmentError(tok, tok->str());
} }

View File

@ -1160,7 +1160,7 @@ private:
" std::string var = var = \"test\";\n" " std::string var = var = \"test\";\n"
" return 0;\n" " return 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of \"var\" to itself\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of \"var\" to itself\n", "", errout.str());
check("void foo()\n" check("void foo()\n"
"{\n" "{\n"
@ -1169,6 +1169,13 @@ private:
" return 0;\n" " return 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("void foo()\n"
"{\n"
" int *x = getx();\n"
" *x = x;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void testScanf1() void testScanf1()