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"