From 5640845a17b6600342c1567ddc42b97da5455460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 4 Feb 2011 21:08:42 +0100 Subject: [PATCH] Fixed #2498 (False positive: redundant assignment) --- lib/checkother.cpp | 3 ++- test/testother.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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()