From 3b8e9f5a2a3a88cc9cc94c357b68dc9fcb2d3fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 3 Sep 2013 17:02:46 +0200 Subject: [PATCH] Fixed #4899 (False positive on unused variable) --- lib/checkunusedvar.cpp | 2 ++ test/testunusedvar.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 9834de84d..8c5e760ac 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -462,6 +462,8 @@ static const Token* doAssignment(Variables &variables, const Token *tok, bool de addressOf = true; tok = tok->next(); } + } else if (Token::Match(tok, "%cop% %var%")) { + variables.read(tok->next()->varId(), tok); } } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 0409945b7..05da72ae0 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -92,6 +92,7 @@ private: TEST_CASE(localvar43); // ticket #3742 TEST_CASE(localvar44); // ticket #3602 TEST_CASE(localvar45); // ticket #4020 + TEST_CASE(localvar46); // ticket #4899 TEST_CASE(localvaralias1); TEST_CASE(localvaralias2); // ticket #1637 TEST_CASE(localvaralias3); // ticket #1639 @@ -1821,6 +1822,15 @@ private: ASSERT_EQUALS("", errout.str()); } + void localvar46() { // #4899 - FP + functionVariableUsage("int func() {\n" + " int a = 123;\n" + " int b = (short)-a;;\n" + " return b;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void localvaralias1() { functionVariableUsage("void foo()\n" "{\n"