unused variable: Fixed false positive when using '|=' assignment

This commit is contained in:
Daniel Marjamäki 2009-01-04 17:41:59 +00:00
parent dcd64a7ce6
commit bf98b14b4f
2 changed files with 13 additions and 1 deletions

View File

@ -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())))

View File

@ -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() );
}
};