Fixed #3078 (vector::at using int causes false positive)

This commit is contained in:
Daniel Marjamäki 2011-09-04 20:48:05 +02:00
parent 0c42f46717
commit 8240422a09
2 changed files with 13 additions and 2 deletions

View File

@ -1144,8 +1144,9 @@ void CheckUnusedVar::checkFunctionVariableUsage()
variables.readAll(tok->next()->varId());
// assignment
else if (Token::Match(tok, "*| (| ++|--| %var% ++|--| )| =") ||
Token::Match(tok, "*| ( const| %type% *| ) %var% ="))
else if (!Token::Match(tok->tokAt(-2), "[;{}.] %var% (") &&
(Token::Match(tok, "*| (| ++|--| %var% ++|--| )| =") ||
Token::Match(tok, "*| ( const| %type% *| ) %var% =")))
{
bool dereference = false;
bool pre = false;

View File

@ -84,6 +84,7 @@ private:
TEST_CASE(localvar34); // ticket #2368
TEST_CASE(localvar35); // ticket #2535
TEST_CASE(localvar36); // ticket #2805
TEST_CASE(localvar37); // ticket #3078
TEST_CASE(localvaralias1);
TEST_CASE(localvaralias2); // ticket #1637
TEST_CASE(localvaralias3); // ticket #1639
@ -1400,6 +1401,15 @@ private:
ASSERT_EQUALS("", errout.str());
}
void localvar37() // ticket #3078
{
functionVariableUsage("void f() {\n"
" int a = 2;\n"
" ints.at(a) = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void localvaralias1()
{
functionVariableUsage("void foo()\n"