diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 0eb2efbfb..7ad8bc724 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -793,7 +793,8 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens) // keep parentheses here: operator new [] (size_t); // keep parentheses here: Functor()(a ... ) // keep parentheses here: ) ( var ) ; - if (Token::Match(tok->next(), "( %var% ) ;|)|,|]|%op%") && + if ((Token::Match(tok->next(), "( %var% ) ;|)|,|]") || + (Token::Match(tok->next(), "( %var% ) %op%") && (tok->tokAt(2)->varId()>0 || !Token::Match(tok->tokAt(4), "[*&]")))) && !tok->isName() && tok->str() != ">" && tok->str() != "]" && diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index d16229e57..c85138264 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -933,7 +933,9 @@ private: } void removeCast9() { - ASSERT_EQUALS("f ( ( double ) v1 * v2 )", tokenizeAndStringify("f((double)(v1)*v2)", true)); + ASSERT_EQUALS("f ( ( double ) ( v1 ) * v2 )", tokenizeAndStringify("f((double)(v1)*v2)", true)); + ASSERT_EQUALS("int v1 ; f ( ( double ) v1 * v2 )", tokenizeAndStringify("int v1; f((double)(v1)*v2)", true)); + ASSERT_EQUALS("f ( ( A ) ( B ) & x )", tokenizeAndStringify("f((A)(B)&x)", true)); // #4439 } void removeCast10() {