Fixed #1640 (False negative: Unused value (variable is assigned but never read))

This commit is contained in:
Robert Reif 2010-05-01 21:15:14 +02:00 committed by Daniel Marjamäki
parent 956495e10b
commit 6eb16e0f16
2 changed files with 17 additions and 3 deletions

View File

@ -809,9 +809,12 @@ static int doAssignment(Variables &variables, const Token *tok, bool pointer)
} }
else // not a local variable else // not a local variable
{ {
// aliased variables in a larger scope are not supported yet if (var1->_type == Variables::pointer && !pointer)
if (varid2) {
variables.erase(varid1); // aliased variables in a larger scope are not supported yet
if (varid2)
variables.erase(varid1);
}
} }
} }
} }

View File

@ -75,6 +75,7 @@ private:
TEST_CASE(localvar10); TEST_CASE(localvar10);
TEST_CASE(localvar11); TEST_CASE(localvar11);
TEST_CASE(localvar12); TEST_CASE(localvar12);
TEST_CASE(localvar13); // ticket #1640
TEST_CASE(localvaralias1); TEST_CASE(localvaralias1);
TEST_CASE(localvaralias2); // ticket #1637 TEST_CASE(localvaralias2); // ticket #1637
TEST_CASE(localvarasm); TEST_CASE(localvarasm);
@ -1039,6 +1040,16 @@ private:
errout.str()); 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() void localvaralias1()
{ {
functionVariableUsage("void foo()\n" functionVariableUsage("void foo()\n"