unused variable: Fixed false positive when using '|=' assignment
This commit is contained in:
parent
dcd64a7ce6
commit
bf98b14b4f
|
@ -869,7 +869,7 @@ void CheckOther::functionVariableUsage()
|
|||
if ((Token::Match(tok,"[(=&!]") || isOp(tok)) && Token::Match(tok->next(), "%var%"))
|
||||
varUsage[ tok->strAt(1) ] |= USAGE_READ;
|
||||
|
||||
if (Token::Match(tok, "-=|+=|*=|/= %var%"))
|
||||
if (Token::Match(tok, "-=|+=|*=|/= %var%") || Token::Match(tok, "|= %var%"))
|
||||
varUsage[ tok->strAt(1) ] |= USAGE_READ;
|
||||
|
||||
if (Token::Match(tok, "%var%") && (tok->next()->str()==")" || isOp(tok->next())))
|
||||
|
|
|
@ -71,6 +71,7 @@ private:
|
|||
TEST_CASE( localvarInvert ); // Usage with inverted variable
|
||||
TEST_CASE( localvarIf ); // Usage in if
|
||||
TEST_CASE( localvarIfElse ); // return tmp1 ? tmp2 : tmp3;
|
||||
TEST_CASE( localvarOpAssign ); // a |= b;
|
||||
}
|
||||
|
||||
void structmember1()
|
||||
|
@ -264,6 +265,17 @@ private:
|
|||
ASSERT_EQUALS( std::string(""), errout.str() );
|
||||
}
|
||||
|
||||
void localvarOpAssign()
|
||||
{
|
||||
functionVariableUsage( "void foo()\n"
|
||||
"{\n"
|
||||
" int a = 1;\n"
|
||||
" int b = 2;\n"
|
||||
" a |= b;\n"
|
||||
"}\n" );
|
||||
ASSERT_EQUALS( std::string("[test.cpp:2]: Variable 'a' is assigned a value that is never used\n"), errout.str() );
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue