diff --git a/src/tokenize.cpp b/src/tokenize.cpp index b27958a28..67ad2219d 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -2390,7 +2390,7 @@ bool Tokenizer::simplifyRedundantParanthesis() bool ret = false; for (Token *tok = _tokens; tok; tok = tok->next()) { - if (Token::simpleMatch(tok, "( (")) + while (Token::simpleMatch(tok, "( (")) { int parlevel = 0; for (Token *tok2 = tok; tok2; tok2 = tok2->next()) @@ -2407,6 +2407,7 @@ bool Tokenizer::simplifyRedundantParanthesis() { tok->deleteNext(); tok2->deleteNext(); + ret = true; } break; } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index f974a5060..b04f3ef2d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -127,7 +127,8 @@ private: TEST_CASE(simplify_function_parameters); - TEST_CASE(reduce_redundant_paranthesis); // Ticket #61 + TEST_CASE(removeParantheses1); // Ticket #61 + TEST_CASE(removeParantheses2); TEST_CASE(simplify_numeric_condition); TEST_CASE(tokenize_double); @@ -1571,7 +1572,7 @@ private: // Simplify "((..))" into "(..)" - void reduce_redundant_paranthesis() + void removeParantheses1() { const char code[] = "void foo()\n" "{\n" @@ -1591,6 +1592,28 @@ private: ASSERT_EQUALS(std::string(" void foo ( ) { free ( p ) ; }"), ostr.str()); } + void removeParantheses2() + { + const char code[] = "void foo()\n" + "{\n" + " if (__builtin_expect((s == NULL), 0))\n" + " return;\n" + "}"; + + // tokenize.. + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + tokenizer.simplifyTokenList(); + + std::ostringstream ostr; + for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) + ostr << " " << tok->str(); + ASSERT_EQUALS(std::string(" void foo ( ) { if ( ! s ) { return ; } }"), ostr.str()); + } + + void simplify_numeric_condition()