Fix #776 (Tokenizer: remove useless brackets around variable assignment)

http://sourceforge.net/apps/trac/cppcheck/ticket/776
This commit is contained in:
Reijo Tomperi 2009-10-05 14:22:35 +03:00
parent fc684d7b5a
commit 5a0a5422c3
2 changed files with 5 additions and 1 deletions

View File

@ -3408,7 +3408,7 @@ bool Tokenizer::simplifyRedundantParanthesis()
ret = true; ret = true;
} }
if (Token::Match(tok->previous(), "[(!*] ( %var% )") && tok->next()->varId() != 0) if (Token::Match(tok->previous(), "[(!*;] ( %var% )") && tok->next()->varId() != 0)
{ {
// We have "( var )", remove the paranthesis // We have "( var )", remove the paranthesis
tok = tok->previous(); tok = tok->previous();

View File

@ -417,6 +417,10 @@ private:
ASSERT_EQUALS("return p ;", tok("return (p);")); ASSERT_EQUALS("return p ;", tok("return (p);"));
ASSERT_EQUALS("void f ( ) { int * p ; if ( ! * p ) { } }", tok("void f(){int *p; if (*(p) == 0) {}}")); ASSERT_EQUALS("void f ( ) { int * p ; if ( ! * p ) { } }", tok("void f(){int *p; if (*(p) == 0) {}}"));
ASSERT_EQUALS("void f ( ) { int * p ; if ( ! * p ) { } }", tok("void f(){int *p; if (*p == 0) {}}")); ASSERT_EQUALS("void f ( ) { int * p ; if ( ! * p ) { } }", tok("void f(){int *p; if (*p == 0) {}}"));
ASSERT_EQUALS("void f ( ) { int p ; p = 1 ; }", tok("void f(){int p; (p) = 1;}"));
ASSERT_EQUALS("void f ( ) { int p [ 10 ] ; p [ 0 ] = 1 ; }", tok("void f(){int p[10]; (p)[0] = 1;}"));
ASSERT_EQUALS("void f ( ) { int p ; if ( ! p ) { } }", tok("void f(){int p; if ((p) == 0) {}}"));
ASSERT_EQUALS("void f ( ) { int * p ; * p = 1 ; }", tok("void f(){int *p; *(p) = 1;}"));
// keep parantheses.. // keep parantheses..
ASSERT_EQUALS("= a ;", tok("= (char)a;")); ASSERT_EQUALS("= a ;", tok("= (char)a;"));