diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 67ad2219d..1be7ccf04 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -2390,9 +2390,12 @@ bool Tokenizer::simplifyRedundantParanthesis() bool ret = false; for (Token *tok = _tokens; tok; tok = tok->next()) { - while (Token::simpleMatch(tok, "( (")) + bool foundSomething = true; + while (foundSomething && Token::simpleMatch(tok, "( (")) { + foundSomething = false; int parlevel = 0; + for (Token *tok2 = tok; tok2; tok2 = tok2->next()) { if (tok2->str() == "(") @@ -2408,6 +2411,7 @@ bool Tokenizer::simplifyRedundantParanthesis() tok->deleteNext(); tok2->deleteNext(); ret = true; + foundSomething = true; } break; } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index b04f3ef2d..b84cd73eb 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -129,6 +129,7 @@ private: TEST_CASE(removeParantheses1); // Ticket #61 TEST_CASE(removeParantheses2); + TEST_CASE(removeParantheses3); TEST_CASE(simplify_numeric_condition); TEST_CASE(tokenize_double); @@ -1613,8 +1614,25 @@ private: ASSERT_EQUALS(std::string(" void foo ( ) { if ( ! s ) { return ; } }"), ostr.str()); } + void removeParantheses3() + { + const char code[] = "void foo()\n" + "{\n" + " if (( true )==true){}\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 ( ( true ) == true ) { } }"), ostr.str()); + } void simplify_numeric_condition() {