Revert "Fix 8629: false negative: (style) Condition '...' is always true (#3492)"

This reverts commit b9be38aaec.
This commit is contained in:
Daniel Marjamäki 2021-10-10 21:21:21 +02:00
parent b9be38aaec
commit 6bd5f79451
2 changed files with 4 additions and 14 deletions

View File

@ -803,11 +803,11 @@ static void setTokenValue(Token* tok, ValueFlow::Value value, const Settings* se
// increment // increment
else if (parent->str() == "++") { else if (parent->str() == "++") {
for (const ValueFlow::Value &val : tok->values()) { for (const ValueFlow::Value &val : tok->values()) {
if (!val.isIntValue() && !val.isFloatValue() && !val.isSymbolicValue()) if (!val.isIntValue() && !val.isFloatValue())
continue; continue;
ValueFlow::Value v(val); ValueFlow::Value v(val);
if (parent == tok->previous()) { if (parent == tok->previous()) {
if (v.isIntValue() || v.isSymbolicValue()) if (v.isIntValue())
v.intvalue = v.intvalue + 1; v.intvalue = v.intvalue + 1;
else else
v.floatValue = v.floatValue + 1.0; v.floatValue = v.floatValue + 1.0;
@ -819,11 +819,11 @@ static void setTokenValue(Token* tok, ValueFlow::Value value, const Settings* se
// decrement // decrement
else if (parent->str() == "--") { else if (parent->str() == "--") {
for (const ValueFlow::Value &val : tok->values()) { for (const ValueFlow::Value &val : tok->values()) {
if (!val.isIntValue() && !val.isFloatValue() && !val.isSymbolicValue()) if (!val.isIntValue() && !val.isFloatValue())
continue; continue;
ValueFlow::Value v(val); ValueFlow::Value v(val);
if (parent == tok->previous()) { if (parent == tok->previous()) {
if (v.isIntValue() || v.isSymbolicValue()) if (v.isIntValue())
v.intvalue = v.intvalue - 1; v.intvalue = v.intvalue - 1;
else else
v.floatValue = v.floatValue - 1.0; v.floatValue = v.floatValue - 1.0;

View File

@ -3826,16 +3826,6 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Condition 'z<1' is always false\n", errout.str()); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Condition 'z<1' is always false\n", errout.str());
check("bool f(int &index, const int s, const double * const array, double & x) {\n"
" if (index >= s)\n"
" return false;\n"
" else {\n"
" x = array[index];\n"
" return (index++) >= s;\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (style) Condition '(index++)>=s' is always false\n", errout.str());
check("struct a {\n" check("struct a {\n"
" a *b() const;\n" " a *b() const;\n"
"} c;\n" "} c;\n"