Variable usage: Fixed false positive with operators ~ and !

This commit is contained in:
Daniel Marjamäki 2009-01-04 17:27:32 +00:00
parent 9ea852eb0e
commit dcc15d7f22
2 changed files with 12 additions and 1 deletions

View File

@ -809,7 +809,7 @@ static bool isOp(const Token *tok)
tok->str() == ">" || tok->str() == ">" ||
tok->str() == ">=" || tok->str() == ">=" ||
tok->str() == "<<" || tok->str() == "<<" ||
Token::Match(tok, "[+-*/%&|,[])?:]"))); Token::Match(tok, "[+-*/%&!~|,[])?:]")));
} }
void CheckOther::functionVariableUsage() void CheckOther::functionVariableUsage()

View File

@ -65,6 +65,7 @@ private:
TEST_CASE( localvar6 ); TEST_CASE( localvar6 );
TEST_CASE( localvarMod ); // Usage with modulo TEST_CASE( localvarMod ); // Usage with modulo
TEST_CASE( localvarInvert ); // Usage with inverted variable
TEST_CASE( localvarIf ); // Usage in if TEST_CASE( localvarIf ); // Usage in if
TEST_CASE( localvarIfElse ); // return tmp1 ? tmp2 : tmp3; TEST_CASE( localvarIfElse ); // return tmp1 ? tmp2 : tmp3;
} }
@ -212,6 +213,16 @@ private:
ASSERT_EQUALS( std::string(""), errout.str() ); ASSERT_EQUALS( std::string(""), errout.str() );
} }
void localvarInvert()
{
functionVariableUsage( "int main()\n"
"{\n"
" int tmp = 10;\n"
" return ~tmp;\n"
"}\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}
void localvarIf() void localvarIf()
{ {
functionVariableUsage( "int main()\n" functionVariableUsage( "int main()\n"