Fixed #6898 (Token::expressionString: wrong output when first token is post-incremented)

This commit is contained in:
Daniel Marjamäki 2015-07-31 07:03:52 +02:00
parent 42a406ac5f
commit 251f6d2a15
2 changed files with 9 additions and 2 deletions

View File

@ -1191,7 +1191,8 @@ std::string Token::expressionString() const
{
const Token * const top = this;
const Token *start = top;
while (start->astOperand1() && (start->astOperand2() || Token::simpleMatch(start, "( )")))
while (start->astOperand1() &&
(start->astOperand2() || !start->isUnaryPreOp() || Token::simpleMatch(start, "( )")))
start = start->astOperand1();
const Token *end = top;
while (end->astOperand1() && (end->astOperand2() || end->isUnaryPreOp())) {
@ -1208,7 +1209,6 @@ std::string Token::expressionString() const
ret += " ";
}
return ret + end->str();
}
static void astStringXml(const Token *tok, std::size_t indent, std::ostream &out)

View File

@ -1521,6 +1521,13 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) Condition !x is always true\n", errout.str());
check("void f() {\n" // #6898 (Token::expressionString)
" int x = 0;\n"
" A(x++ == 1);\n"
" A(x++ == 2);\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) Condition x++==2 is always false\n", errout.str());
// Avoid FP when condition comes from macro
check("void f() {\n"
" int x = 0;\n"