diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 1610a0744..80650adcd 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -455,15 +455,23 @@ static void compileTerm(Token *& tok, std::stack &op) op.push(name->next()); } } else if (Token::Match(tok, "++|--")) { - if (!op.empty() && op.top()->isOp()) { + bool pre = false; + if (tok->next() && tok->next()->isName()) + pre = true; + else if (!op.empty() && !op.top()->isOp()) + pre = false; + else + pre = true; + + if (pre) { + // pre increment/decrement + compileUnaryOp(tok, compileDot, op); + } else { // post increment/decrement tok->astOperand1(op.top()); op.pop(); op.push(tok); tok = tok->next(); - } else { - // pre increment/decrement - compileUnaryOp(tok, compileDot, op); } } else if (tok->str() == "(") { if (iscast(tok)) { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index d58d6424b..f118901ad 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -10054,6 +10054,10 @@ private: ASSERT_EQUALS("1a--+", testAst("1 + --a")); ASSERT_EQUALS("1a--+", testAst("1 + a--")); ASSERT_EQUALS("ab+!", testAst("!(a+b)")); + + // how is "--" handled here: + ASSERT_EQUALS("ab4<