diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e0024b9d2..76d8905f0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8098,6 +8098,21 @@ bool Tokenizer::simplifyRedundantParentheses() continue; } + // Do not simplify if there is comma inside parantheses.. + if (Token::Match(tok->previous(), "%op% (") || Token::Match(tok->link(), ") %op%")) { + bool innerComma = false; + for (const Token *inner = tok->link()->previous(); inner != tok; inner = inner->previous()) { + if (inner->str() == ")") + inner = inner->link(); + if (inner->str() == ",") { + innerComma = true; + break; + } + } + if (innerComma) + continue; + } + // !!operator = ( x ) ; if (tok->strAt(-2) != "operator" && tok->previous() && tok->previous()->str() == "=" && diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 2779eda33..74b2bb2e7 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -253,6 +253,7 @@ private: TEST_CASE(removeParentheses22); TEST_CASE(removeParentheses23); // Ticket #6103 - Infinite loop upon valid input TEST_CASE(removeParentheses24); // Ticket #7040 + TEST_CASE(removeParentheses25); // daca@home - a=(b,c) TEST_CASE(tokenize_double); TEST_CASE(tokenize_strings); @@ -3463,6 +3464,12 @@ private: ASSERT_EQUALS(exp, tokenizeAndStringify(code)); } + void removeParentheses25() { // daca@home - a=(b,c) + static char code[] = "a=(b,c);"; + static char exp[] = "a = ( b , c ) ;"; + ASSERT_EQUALS(exp, tokenizeAndStringify(code)); + } + void tokenize_double() { const char code[] = "void f() {\n" " double a = 4.2;\n"