unused var: fixed false positives when using shift operator
This commit is contained in:
parent
673fb25e4d
commit
b9b250f4cc
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue