diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 17e8fc170..ca9b72229 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -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% )")) { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 458a83936..8e1771e4f 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -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;"));