Fixed #6898 (Token::expressionString: wrong output when first token is post-incremented)
This commit is contained in:
parent
42a406ac5f
commit
251f6d2a15
|
@ -1191,7 +1191,8 @@ std::string Token::expressionString() const
|
||||||
{
|
{
|
||||||
const Token * const top = this;
|
const Token * const top = this;
|
||||||
const Token *start = top;
|
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();
|
start = start->astOperand1();
|
||||||
const Token *end = top;
|
const Token *end = top;
|
||||||
while (end->astOperand1() && (end->astOperand2() || end->isUnaryPreOp())) {
|
while (end->astOperand1() && (end->astOperand2() || end->isUnaryPreOp())) {
|
||||||
|
@ -1208,7 +1209,6 @@ std::string Token::expressionString() const
|
||||||
ret += " ";
|
ret += " ";
|
||||||
}
|
}
|
||||||
return ret + end->str();
|
return ret + end->str();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void astStringXml(const Token *tok, std::size_t indent, std::ostream &out)
|
static void astStringXml(const Token *tok, std::size_t indent, std::ostream &out)
|
||||||
|
|
|
@ -1521,6 +1521,13 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) Condition !x is always true\n", errout.str());
|
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
|
// Avoid FP when condition comes from macro
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" int x = 0;\n"
|
" int x = 0;\n"
|
||||||
|
|
Loading…
Reference in New Issue