From 92acca3d0c7d1292eb2fa7330840ebc75248a509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 27 Dec 2010 20:49:07 +0100 Subject: [PATCH] Fixed #2368 (assigned a value that is never used) --- lib/tokenize.cpp | 3 +++ test/testtokenize.cpp | 3 +++ test/testunusedvar.cpp | 22 +++++++--------------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 8750c2583..e922f677a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4561,7 +4561,10 @@ void Tokenizer::simplifyCompoundAssignment() else if (str=="<<=" || str==">>=") op = str.substr(0, 2); else + { + tok = tok1; continue; + } // Remove the whole statement if it says: "+=0;", "-=0;", "*=1;" or "/=1;" if (Token::Match(tok, "+=|-= 0 ;") || diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 17b43381b..670f776fd 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5055,6 +5055,9 @@ private: ASSERT_EQUALS(";", tokenizeAndStringify(";x /= 1;")); ASSERT_EQUALS("; a . x ( ) = a . x ( ) + 1 ;", tokenizeAndStringify("; a.x() += 1;")); + + // #2368 + ASSERT_EQUALS("if ( false ) { } else { j = j - i ; }", tokenizeAndStringify("if (false) {} else { j -= i; }")); } void simplifyAssignmentInFunctionCall() diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 0576a8ebf..d73afa522 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -1361,22 +1361,14 @@ private: void localvar34() // ticket #2368 { - functionVariableUsage("int f(void) {\n" - " int i = 0;\n" - " int j = 3;\n" - " if (false) {\n" - " }\n" - " else {\n" - " j -= i;\n" - " }\n" - " if (false) {\n" - " }\n" - " else {\n" - " j -= i;\n" - " }\n" - " return j;\n" + functionVariableUsage("void f() {\n" + " int i = 0;\n" + " if (false) {\n" + " } else {\n" + " j -= i;\n" + " }\n" "}\n"); - TODO_ASSERT_EQUALS("", errout.str()); + ASSERT_EQUALS("", errout.str()); } void localvaralias1()