Fixed ticket #529 (Tokenizer: simplify if((x==0)))

http://sourceforge.net/apps/trac/cppcheck/ticket/529
This commit is contained in:
Reijo Tomperi 2009-07-30 00:37:01 +03:00
parent 050b85c5eb
commit b56fdb83da
2 changed files with 8 additions and 0 deletions

View File

@ -2558,6 +2558,12 @@ bool Tokenizer::simplifyIfNot()
if (tok->str() == "(" || tok->str() == "||" || tok->str() == "&&")
{
tok = tok->next();
while (tok && tok->str() == "(")
tok = tok->next();
if (!tok)
break;
if (Token::simpleMatch(tok, "0 == (") ||
Token::Match(tok, "0 == %var%"))
{

View File

@ -1005,6 +1005,8 @@ private:
ASSERT_EQUALS("if ( b ( ) && ! a )", simplifyIfNot("if( b() && 0 == a )"));
ASSERT_EQUALS("if ( ! ( a = b ) )", simplifyIfNot("if((a=b)==0)"));
ASSERT_EQUALS("if ( ! x . y )", simplifyIfNot("if(x.y==0)"));
ASSERT_EQUALS("if ( ( ! x ) )", simplifyIfNot("if((x==0))"));
ASSERT_EQUALS("if ( ( ! x ) && ! y )", simplifyIfNot("if((x==0) && y==0)"));
}