diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e662757fa..e3bd165d4 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6544,11 +6544,17 @@ bool Tokenizer::simplifyRedundantParenthesis() ret = true; } - if (Token::Match(tok->previous(), "[(,!] ( %var% . %var% )")) { - // We have "( var . var )", remove the parenthesis - tok->deleteThis(); - tok = tok->tokAt(2); + while (Token::Match(tok->previous(), ";|{|}|[|]|(|)|.|,|! ( %var% .")) { + Token *tok2 = tok->tokAt(2); + while (Token::Match(tok2, ". %var%")) { + tok2 = tok2->tokAt(2); + } + if (tok2 != tok->link()) + break; + // We have "( var . var . ... . var )", remove the parenthesis + tok = tok->previous(); tok->deleteNext(); + tok2->deleteThis(); ret = true; continue; } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index b50f12740..9ac85cacc 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4710,8 +4710,15 @@ private: // "!(abc.a)" => "!abc.a" void removeParentheses6() { - const char code[] = "(!(abc.a))"; - ASSERT_EQUALS("( ! abc . a )", tokenizeAndStringify(code)); + { + const char code[] = "(!(abc.a))"; + ASSERT_EQUALS("( ! abc . a )", tokenizeAndStringify(code)); + } + //handle more complex member selections + { + const char code[] = "(!(a.b.c.d));"; + ASSERT_EQUALS("( ! a . b . c . d ) ;", tokenizeAndStringify(code)); + } } void removeParentheses7() {