diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 9947e893e..dff996088 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -289,7 +289,8 @@ void CheckOther::checkSelfAssignment() const Token *tok = Token::findmatch(_tokenizer->tokens(), selfAssignmentPattern); 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()); } diff --git a/test/testother.cpp b/test/testother.cpp index dced35a69..864cf25a1 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1160,7 +1160,7 @@ private: " std::string var = var = \"test\";\n" " return 0;\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" "{\n" @@ -1169,6 +1169,13 @@ private: " return 0;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void foo()\n" + "{\n" + " int *x = getx();\n" + " *x = x;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void testScanf1()