diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7ed1d9461..14e5831ad 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7549,7 +7549,7 @@ bool Tokenizer::simplifyRedundantParentheses() ret = true; } - if (Token::Match(tok->previous(), "[(,;{}] ( %name% (") && + if (Token::Match(tok->previous(), "[(,;{}] ( %name% (") && !tok->next()->isKeyword() && tok->link()->previous() == tok->linkAt(2)) { // We have "( func ( *something* ))", remove the outer // parentheses diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index db96a2303..488ba5549 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -176,6 +176,7 @@ private: TEST_CASE(removeParentheses24); // Ticket #7040 TEST_CASE(removeParentheses25); // daca@home - a=(b,c) TEST_CASE(removeParentheses26); // Ticket #8875 a[0](0) + TEST_CASE(removeParentheses27); TEST_CASE(tokenize_double); TEST_CASE(tokenize_strings); @@ -1909,6 +1910,20 @@ private: ASSERT_EQUALS(exp, tokenizeAndStringify(code)); } + void removeParentheses27() { + static char code[] = "struct S { int i; };\n" + "void g(int, int);\n" + "void f(S s, int j) {\n" + " g(j, (decltype(s.i))j * s.i);\n" + "}\n"; + static const char exp[] = "struct S { int i ; } ;\n" + "void g ( int , int ) ;\n" + "void f ( S s , int j ) {\n" + "g ( j , ( decltype ( s . i ) ) j * s . i ) ;\n" + "}"; + ASSERT_EQUALS(exp, tokenizeAndStringify(code)); + } + void tokenize_double() { const char code[] = "void f() {\n" " double a = 4.2;\n"