From 6c2563c467a6dabe8412cc1d9b9d9960d511af1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 3 Nov 2012 13:18:43 +0100 Subject: [PATCH] Fixed #4311 (False positive: warning (selfAssignment): Redundant assignment of 'm_bar' to itself. --- lib/checkother.cpp | 2 +- lib/tokenize.cpp | 2 +- test/testother.cpp | 10 ---------- test/testtokenize.cpp | 22 ---------------------- 4 files changed, 2 insertions(+), 34 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index c06df0e01..6ee7d282c 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1033,7 +1033,7 @@ void CheckOther::checkSelfAssignment() const char selfAssignmentPattern[] = "%var% = %var% ;|=|)"; const Token *tok = Token::findmatch(_tokenizer->tokens(), selfAssignmentPattern); while (tok) { - if (Token::Match(tok->previous(), "[;{}.]") && + if (Token::Match(tok->previous(), "[;{}]") && tok->varId() && tok->varId() == tok->tokAt(2)->varId() && isTypeWithoutSideEffects(_tokenizer, symbolDatabase->getVariableFromVarId(tok->varId()))) { bool err = true; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index da42f7019..87f43e472 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2624,7 +2624,7 @@ static void setVarIdClassFunction(Token * const startToken, unsigned int *_varId) { for (Token *tok2 = startToken; tok2 && tok2 != endToken; tok2 = tok2->next()) { - if (tok2->varId() == 0) { + if (tok2->varId() == 0 && tok2->previous()->str() != ".") { const std::map::const_iterator it = varlist.find(tok2->str()); if (it != varlist.end()) { tok2->varId(it->second); diff --git a/test/testother.cpp b/test/testother.cpp index 0351450e4..95d2fcbb4 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2791,16 +2791,6 @@ private: " i = i;\n" "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of 'i' to itself.\n", errout.str()); - - // #4291 - id for variables accessed through 'this' - check("class Foo {\n" - " int var;\n" - " void func();\n" - "};\n" - "void Foo::func() {\n" - " this->var = var;\n" - "}"); - ASSERT_EQUALS("[test.cpp:6]: (warning) Redundant assignment of 'var' to itself.\n", errout.str()); } void trac1132() { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index d209e5eba..3528e9ec7 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -250,7 +250,6 @@ private: TEST_CASE(varid_in_class6); // #3755 TEST_CASE(varid_in_class7); // set variable id for struct members TEST_CASE(varid_in_class8); // unknown macro in class - TEST_CASE(varid_in_class9); // #4291 - id for variables accessed through 'this' TEST_CASE(varid_initList); TEST_CASE(varid_operator); TEST_CASE(varid_throw); @@ -3891,27 +3890,6 @@ private: tokenizeDebugListing(code)); } - void varid_in_class9() { // #4291 - id for variables accessed through 'this' - const char code[] = "class A {\n" - " int var;\n" - "public:\n" - " void setVar();\n" - "};\n" - "void A::setVar() {\n" - " this->var = var;\n" - "}"; - ASSERT_EQUALS("\n\n##file 0\n" - "1: class A {\n" - "2: int var@1 ;\n" - "3: public:\n" - "4: void setVar ( ) ;\n" - "5: } ;\n" - "6: void A :: setVar ( ) {\n" - "7: this . var@1 = var@1 ;\n" - "8: }\n", - tokenizeDebugListing(code)); - } - void varid_initList() { const char code[] = "class A {\n" " A() : x(0) {}\n"