diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7c15be961bc..b0c02fa4b01 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3790,7 +3790,7 @@ void Tokenizer::simplifyParenthesizedLibraryFunctions() if (!Token::simpleMatch(tok, ") (")) continue; Token *rpar = tok, *lpar = tok->link(); - if (!lpar || (Token::Match(lpar->previous(), "%name%") && !lpar->previous()->isKeyword())) + if (!lpar || (Token::Match(lpar->previous(), "%name%") && !Token::Match(lpar->previous(), "return|delete|throw"))) continue; const Token *ftok = rpar->previous(); if (mSettings.library.isNotLibraryFunction(ftok)) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index eff4a8d44f2..ee38b2a1dce 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -185,6 +185,7 @@ class TestTokenizer : public TestFixture { TEST_CASE(removeParentheses27); TEST_CASE(removeParentheses28); // #12164 - don't remove parentheses in '(expr1) ? (expr2) : (expr3);' TEST_CASE(removeParantheses29); // #13735 + TEST_CASE(removeParentheses30); TEST_CASE(tokenize_double); TEST_CASE(tokenize_strings); @@ -2192,6 +2193,19 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS(exp, tokenizeAndStringify(code)); } + void removeParentheses30() { + static char code[] = "void f (Node *node) {\n" + " if (node->data && (node->provider)->free)\n" + " (node->provider)->free (node);\n" + "}\n"; + static const char exp[] = "void f ( Node * node ) {\n" + "if ( node . data && ( node . provider ) . free ) {\n" + "node . provider . free ( node ) ; }\n" + "}"; + ASSERT_EQUALS(exp, tokenizeAndStringify(code)); + (void) errout_str(); + } + void tokenize_double() { const char code[] = "void f() {\n" " double a = 4.2;\n"