diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 15fcd9258..13b7ac82c 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -926,7 +926,7 @@ void Tokenizer::simplifyTokenList() // Remove parantheses around variable.. // keep parantheses here: dynamic_cast(p); - if (!tok->isName() && tok->str() != ">" && Token::Match(tok->next(), "( %var% )")) + if (!tok->isName() && tok->str() != ">" && Token::Match(tok->next(), "( %var% ) [;),+-*/><]]")) { tok->deleteNext(); tok = tok->next(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 7a0808a11..54bdcf5a8 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -64,7 +64,7 @@ private: TEST_CASE(double_plus); TEST_CASE(redundant_plus); TEST_CASE(parantheses1); - TEST_CASE(parantheses2); + TEST_CASE(paranthesesVar); // Remove redundant parantheses around variable .. "( %var% )" TEST_CASE(elseif1); } @@ -313,10 +313,15 @@ private: ASSERT_EQUALS("<= 110 ; ", tok(code1)); } - void parantheses2() + void paranthesesVar() { - const char code1[] = "= (p);"; - ASSERT_EQUALS("= p ; ", tok(code1)); + // remove parantheses.. + ASSERT_EQUALS("= p ; ", tok("= (p);")); + ASSERT_EQUALS("if ( a < p ) { ", tok("if(a<(p))")); + + // keep parantheses.. + ASSERT_EQUALS("= ( char ) a ; ", tok("= (char)a;")); + ASSERT_EQUALS("cast < char * > ( p ) ", tok("cast(p)")); }