Fix ticket #448 (false positive:: resource leak)
http://sourceforge.net/apps/trac/cppcheck/ticket/448 Tokenizer improved to simplify "if( (p)==-1 )"
This commit is contained in:
parent
b2474fd980
commit
26358debcf
|
@ -2656,6 +2656,17 @@ bool Tokenizer::simplifyRedundantParanthesis()
|
|||
ret = true;
|
||||
}
|
||||
|
||||
if (Token::Match(tok->previous(), "( ( %var% )") && tok->next()->varId() != 0)
|
||||
{
|
||||
// We have "( var )", remove the paranthesis
|
||||
tok = tok->previous();
|
||||
tok->deleteNext();
|
||||
tok = tok->next();
|
||||
tok->deleteNext();
|
||||
ret = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Token::Match(tok, "( ( %bool% )") ||
|
||||
Token::Match(tok, "( ( %num% )"))
|
||||
{
|
||||
|
|
|
@ -379,6 +379,9 @@ private:
|
|||
// remove parantheses..
|
||||
ASSERT_EQUALS("= p ; ", tok("= (p);"));
|
||||
ASSERT_EQUALS("if ( a < p ) { } ", tok("if(a<(p)){}"));
|
||||
ASSERT_EQUALS("void f ( ) { int p ; if ( p == -1 ) { } } ", tok("void f(){int p; if((p)==-1){}}"));
|
||||
ASSERT_EQUALS("void f ( ) { int p ; if ( -1 == p ) { } } ", tok("void f(){int p; if(-1==(p)){}}"));
|
||||
ASSERT_EQUALS("void f ( ) { int p ; if ( p ) { } } ", tok("void f(){int p; if((p)){}}"));
|
||||
|
||||
// keep parantheses..
|
||||
ASSERT_EQUALS("= a ; ", tok("= (char)a;"));
|
||||
|
|
Loading…
Reference in New Issue