unused var: fixed false positives when using shift operator

This commit is contained in:
Daniel Marjamäki 2009-01-17 14:32:02 +00:00
parent 673fb25e4d
commit b9b250f4cc
2 changed files with 11 additions and 1 deletions

View File

@ -914,7 +914,7 @@ void CheckOther::functionVariableUsage()
varUsage[ tok->strAt(1)] |= USAGE_WRITE;
if (Token::Match(tok, ">>|& %var%"))
varUsage[ tok->strAt(1)] |= USAGE_WRITE;
varUsage[ tok->strAt(1)] |= (USAGE_WRITE | USAGE_READ);
if ((Token::Match(tok, "[(=&!]") || isOp(tok)) && Token::Match(tok->next(), "%var%"))
varUsage[ tok->strAt(1)] |= USAGE_READ;

View File

@ -76,6 +76,7 @@ private:
TEST_CASE(localvarIfElse); // return tmp1 ? tmp2 : tmp3;
TEST_CASE(localvarOpAssign); // a |= b;
TEST_CASE(localvarFor); // for ( ; var; )
TEST_CASE(localvarShift); // 1 >> var
}
void structmember1()
@ -346,6 +347,15 @@ private:
ASSERT_EQUALS(std::string(""), errout.str());
}
void localvarShift()
{
functionVariableUsage("int foo()\n"
"{\n"
" int var = 1;\n"
" return 1 >> var;\n"
"}\n");
ASSERT_EQUALS(std::string(""), errout.str());
}
};
REGISTER_TEST(TestUnusedVar)