From 558899dc74d8f8391310b0fcb4d1318f0fbcee0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 31 Oct 2010 09:34:25 +0100 Subject: [PATCH] Variable usage: Fixed false negative that I introduced when simplifying compound assignments --- lib/checkother.cpp | 11 +++++++---- test/testunusedvar.cpp | 3 +-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 50c1d3835..648cc93bd 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -909,8 +909,14 @@ static int doAssignment(Variables &variables, const Token *tok, bool dereference { int next = 0; + // a = a + b; + if (Token::Match(tok, "%var% = %var% !!;") && tok->str() == tok->strAt(2)) + { + return 2; + } + // check for aliased variable - unsigned int varid1 = tok->varId(); + const unsigned int varid1 = tok->varId(); Variables::VariableUsage *var1 = variables.find(varid1); if (var1) @@ -1642,9 +1648,6 @@ void CheckOther::functionVariableUsage() (Token::Match(tok->next(), "%var%") && !Token::Match(tok->next(), "true|false|new"))) variables.readAll(tok->next()->varId()); - else if (Token::Match(tok, "-=|+=|*=|/=|&=|^= %var%") || Token::Match(tok, "|= %var%")) - variables.modified(tok->next()->varId()); - else if (Token::Match(tok, "%var%") && (tok->next()->str() == ")" || isOp(tok->next()))) variables.readAll(tok->varId()); diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 9685c60bd..fa85cba44 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -2281,8 +2281,7 @@ private: " int b = 2;\n" " a |= b;\n" "}\n"); - TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used\n", errout.str()); - ASSERT_EQUALS("", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used\n", errout.str()); } void localvarFor()