diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d611df39c..2b7d5d1d1 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3635,9 +3635,17 @@ bool Tokenizer::simplifyRedundantParanthesis() if (Token::Match(tok->previous(), "[(!*;}] ( %var% )") && tok->next()->varId() != 0) { // We have "( var )", remove the paranthesis - tok = tok->previous(); + tok->deleteThis(); tok->deleteNext(); - tok = tok->next(); + ret = true; + continue; + } + + if (Token::Match(tok->previous(), "[(!] ( %var% . %var% )")) + { + // We have "( var . var )", remove the paranthesis + tok->deleteThis(); + tok = tok->tokAt(2); tok->deleteNext(); ret = true; continue; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index a67182ced..43e7dde44 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -130,6 +130,7 @@ private: TEST_CASE(removeParantheses3); TEST_CASE(removeParantheses4); // Ticket #390 TEST_CASE(removeParantheses5); // Ticket #392 + TEST_CASE(removeParantheses6); TEST_CASE(tokenize_double); TEST_CASE(tokenize_strings); @@ -2055,6 +2056,24 @@ private: } } + // "!(abc.a)" => "!abc.a" + void removeParantheses6() + { + const char code[] = "(!(abc.a))"; + + // 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(" ( ! abc . a )", ostr.str()); + } + void tokenize_double() { const char code[] = "void f()\n"