Fixed #3473 (False positive: variable is assigned value that is never used (used in return statement))

This commit is contained in:
Daniel Marjamäki 2012-01-08 08:44:18 +01:00
parent 70c83d9ca9
commit 304980848f
2 changed files with 17 additions and 2 deletions

View File

@ -696,8 +696,14 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
} }
} }
else if (Token::Match(tok, "return|throw %var%")) else if (Token::Match(tok, "return|throw %var%")) {
variables.readAll(tok->next()->varId()); for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
if (tok2->varId())
variables.readAll(tok2->varId());
else if (tok2->str() == ";")
break;
}
}
// assignment // assignment
else if (!Token::Match(tok->tokAt(-2), "[;{}.] %var% (") && else if (!Token::Match(tok->tokAt(-2), "[;{}.] %var% (") &&

View File

@ -85,6 +85,7 @@ private:
TEST_CASE(localvar37); // ticket #3078 TEST_CASE(localvar37); // ticket #3078
TEST_CASE(localvar38); TEST_CASE(localvar38);
TEST_CASE(localvar39); // ticket #3454 TEST_CASE(localvar39); // ticket #3454
TEST_CASE(localvar40); // ticket #3473
TEST_CASE(localvaralias1); TEST_CASE(localvaralias1);
TEST_CASE(localvaralias2); // ticket #1637 TEST_CASE(localvaralias2); // ticket #1637
TEST_CASE(localvaralias3); // ticket #1639 TEST_CASE(localvaralias3); // ticket #1639
@ -1381,6 +1382,14 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void localvar40() {
functionVariableUsage("int f() {\n"
" int a = 1;\n"
" return x & a;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void localvaralias1() { void localvaralias1() {
functionVariableUsage("void foo()\n" functionVariableUsage("void foo()\n"
"{\n" "{\n"