File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1191,7 +1191,8 @@ std::string Token::expressionString() const
11911191{
11921192 const Token * const top = this ;
11931193 const Token *start = top;
1194- while (start->astOperand1 () && (start->astOperand2 () || Token::simpleMatch (start, " ( )" )))
1194+ while (start->astOperand1 () &&
1195+ (start->astOperand2 () || !start->isUnaryPreOp () || Token::simpleMatch (start, " ( )" )))
11951196 start = start->astOperand1 ();
11961197 const Token *end = top;
11971198 while (end->astOperand1 () && (end->astOperand2 () || end->isUnaryPreOp ())) {
@@ -1208,7 +1209,6 @@ std::string Token::expressionString() const
12081209 ret += " " ;
12091210 }
12101211 return ret + end->str ();
1211-
12121212}
12131213
12141214static void astStringXml (const Token *tok, std::size_t indent, std::ostream &out)
Original file line number Diff line number Diff line change @@ -1521,6 +1521,13 @@ class TestCondition : public TestFixture {
15211521 " }" );
15221522 ASSERT_EQUALS (" [test.cpp:4]: (style) Condition !x is always true\n " , errout.str ());
15231523
1524+ check (" void f() {\n " // #6898 (Token::expressionString)
1525+ " int x = 0;\n "
1526+ " A(x++ == 1);\n "
1527+ " A(x++ == 2);\n "
1528+ " }" );
1529+ ASSERT_EQUALS (" [test.cpp:4]: (style) Condition x++==2 is always false\n " , errout.str ());
1530+
15241531 // Avoid FP when condition comes from macro
15251532 check (" void f() {\n "
15261533 " int x = 0;\n "
You can’t perform that action at this time.
0 commit comments