From 6eb16e0f16fb20ebdb09c8b0ef0bc4eb2f935711 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sat, 1 May 2010 21:15:14 +0200 Subject: [PATCH] Fixed #1640 (False negative: Unused value (variable is assigned but never read)) --- lib/checkother.cpp | 9 ++++++--- test/testunusedvar.cpp | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index f38db43b0..bf25cca09 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -809,9 +809,12 @@ static int doAssignment(Variables &variables, const Token *tok, bool pointer) } else // not a local variable { - // aliased variables in a larger scope are not supported yet - if (varid2) - variables.erase(varid1); + if (var1->_type == Variables::pointer && !pointer) + { + // aliased variables in a larger scope are not supported yet + if (varid2) + variables.erase(varid1); + } } } } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 6abcdbfc8..153760589 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -75,6 +75,7 @@ private: TEST_CASE(localvar10); TEST_CASE(localvar11); TEST_CASE(localvar12); + TEST_CASE(localvar13); // ticket #1640 TEST_CASE(localvaralias1); TEST_CASE(localvaralias2); // ticket #1637 TEST_CASE(localvarasm); @@ -1039,6 +1040,16 @@ private: errout.str()); } + void localvar13() // ticket #1640 + { + functionVariableUsage("void foo( OBJECT *obj )\n" + "{\n" + " int x;\n" + " x = obj->ySize / 8;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'x' is assigned a value that is never used\n", errout.str()); + } + void localvaralias1() { functionVariableUsage("void foo()\n"