diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 9d8e9035f..ca8186283 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -2263,19 +2263,12 @@ void Tokenizer::simplifyCasts() if (Token::simpleMatch(tok2, "> (")) { - Token::eraseTokens(tok, tok2->tokAt(2)); - tok2 = tok; - int parlevel = 0; - while (tok2->next() && parlevel >= 0) + Token *closeBracket = tok2->next()->link(); + if (closeBracket) { - tok2 = tok2->next(); - if (tok2->next()->str() == "(") - ++parlevel; - else if (tok2->next()->str() == ")") - --parlevel; + Token::eraseTokens(tok, tok2->tokAt(2)); + closeBracket->deleteThis(); } - if (tok2->next()) - tok2->deleteNext(); } } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index b7e0e2c51..193c57f19 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -672,8 +672,18 @@ private: ASSERT_EQUALS(expected, sizeof_(code)); } - } + { + // ticket #645 + const char code[] = "void f()\n" + "{\n" + " return dynamic_cast((bar()));\n" + "}\n"; + const std::string expected(" void f ( ) { return bar ( ) ; }"); + + ASSERT_EQUALS(expected, sizeof_(code)); + } + }