diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 9fb902dd4..0aebf0d02 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -997,14 +997,8 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens) (Token::Match(tok->next(), "( %name% ) %cop%") && (tok->tokAt(2)->varId()>0 || !Token::Match(tok->tokAt(4), "[*&+-]")))) && !tok->isName() && tok->str() != ">" && - tok->str() != "]" && - tok->strAt(-1) != "operator" && - !Token::simpleMatch(tok->previous(), "* )") && - !Token::simpleMatch(tok->previous(), ") )") && - !Token::Match(tok->tokAt(-2), "* %name% )") && - !Token::Match(tok->tokAt(-2), "%type% ( ) ( %name%") && - !Token::Match(tok, ") ( %name% ) ;") - ) { + tok->str() != ")" && + tok->str() != "]") { tok->deleteNext(); tok = tok->next(); tok->deleteNext(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index c79716c0d..81a1bd8ba 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -97,6 +97,7 @@ private: TEST_CASE(removeCast14); TEST_CASE(removeCast15); // #5996 - don't remove cast in 'a+static_cast(b?60:0)' TEST_CASE(removeCast16); // #6278 + TEST_CASE(removeCast17); // #6110 - don't remove any parentheses in 'a(b)(c)' TEST_CASE(simplifyFloatCasts); // float casting a integer @@ -960,7 +961,7 @@ private: void removeCast4() { // ticket #970 const char code[] = "if (a >= (unsigned)(b)) {}"; - const char expected[] = "if ( a >= ( unsigned int ) b ) { }"; + const char expected[] = "if ( a >= ( unsigned int ) ( b ) ) { }"; ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } @@ -984,7 +985,7 @@ private: void removeCast9() { 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("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 } @@ -1039,6 +1040,11 @@ private: tokenizeAndStringify("Get((CObject*&)pArray);", true)); } + void removeCast17() { // #6110 - don't remove any parentheses in 'a(b)(c)' + ASSERT_EQUALS("if ( a ( b ) ( c ) >= 3 )", + tokenizeAndStringify("if (a(b)(c) >= 3)", true)); + } + void simplifyFloatCasts() { // float casting integers // C-style casts ASSERT_EQUALS("a = 1.0f ;", tokenizeAndStringify("a = (float)1;"));