diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index eccb6b80e..e2b0f222c 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -878,11 +878,11 @@ static bool isLowerThanAnd(const Token* lower) } static bool isLowerThanShift(const Token* lower) { - return isLowerThanAnd(lower) || Token::Match(lower, "%comp%|&"); + return isLowerThanAnd(lower) || Token::Match(lower, "&"); } static bool isLowerThanPlusMinus(const Token* lower) { - return isLowerThanShift(lower) || Token::Match(lower, "<<|>>"); + return isLowerThanShift(lower) || Token::Match(lower, "%comp%|<<|>>"); } static bool isLowerThanMulDiv(const Token* lower) { diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index bee3d0419..d5d117e4e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3413,6 +3413,9 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) // combine "- %num%" concatenateNegativeNumberAndAnyPositive(); + // Combine tokens.. + combineOperators(); + #ifndef CPPCHECK2 // simplify simple calculations for (Token *tok = list.front() ? list.front()->next() : nullptr; tok; tok = tok->next()) { @@ -3439,9 +3442,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) if (!simplifyAddBraces()) return false; - // Combine tokens.. - combineOperators(); - sizeofAddParentheses(); // Simplify: 0[foo] -> *(foo) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 754475bea..7498649a3 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -2098,6 +2098,7 @@ private: ASSERT_EQUALS("x ( 1 )", tok("x(2 && 2|5<<2%4)")); // #4931 ASSERT_EQUALS("x ( -2 << 6 | 1 )", tok("x(1-3<<6|5/3)")); // #4931 ASSERT_EQUALS("x ( 2 )", tok("x(2|0*0&2>>1+0%2*1)")); // #4931 + ASSERT_EQUALS("x ( 0 & 4 != 1 )", tok("x(4%1<<1&4!=1)")); // #4931 (can be simplified further but it's not a problem) // don't remove these spaces.. ASSERT_EQUALS("new ( auto ) ( 4 ) ;", tok("new (auto)(4);"));