ValueFlow: Improved error path for compound assignments
This commit is contained in:
parent
61e290750e
commit
50636f75ba
|
@ -990,6 +990,9 @@ static void valueFlowReverse(TokenList *tokenlist,
|
|||
bailout(tokenlist, errorLogger, tok2, "compound assignment " + tok2->str());
|
||||
break;
|
||||
}
|
||||
|
||||
const std::string info("Compound assignment '" + assignToken->str() + "', before assignment value is " + val.infoString());
|
||||
val.errorPath.push_back(ErrorPathItem(tok2, info));
|
||||
}
|
||||
|
||||
// bailout: variable is used in rhs in assignment to itself
|
||||
|
@ -1713,8 +1716,12 @@ static bool valueFlowForward(Token * const startToken,
|
|||
}
|
||||
if (ub)
|
||||
it = values.erase(it);
|
||||
else
|
||||
else {
|
||||
const std::string info("Compound assignment '" + assign + "', assigned value is " + it->infoString());
|
||||
it->errorPath.push_back(ErrorPathItem(tok2, info));
|
||||
|
||||
++it;
|
||||
}
|
||||
} else if (it->isFloatValue()) {
|
||||
if (assign == "+=")
|
||||
it->floatValue += rhsValue.intvalue;
|
||||
|
@ -1728,6 +1735,9 @@ static bool valueFlowForward(Token * const startToken,
|
|||
values.clear();
|
||||
break;
|
||||
}
|
||||
|
||||
const std::string info("Compound assignment '" + assign + "', assigned value is " + it->infoString());
|
||||
it->errorPath.push_back(ErrorPathItem(tok2, info));
|
||||
++it;
|
||||
} else {
|
||||
it = values.erase(it);
|
||||
|
|
|
@ -631,6 +631,7 @@ private:
|
|||
" if (y == 32) {}"
|
||||
"}\n";
|
||||
ASSERT_EQUALS("5,Assuming that condition 'y==32' is not redundant\n"
|
||||
"4,Compound assignment '+=', before assignment value is 20\n"
|
||||
"2,Assignment 'x=y', assigned value is 20\n",
|
||||
getErrorPathForX(code, 3U));
|
||||
|
||||
|
@ -1745,6 +1746,9 @@ private:
|
|||
" return x;\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(true, testValueOfX(code, 4U, 166));
|
||||
ASSERT_EQUALS("2,Assignment 'x=123', assigned value is 123\n"
|
||||
"3,Compound assignment '+=', assigned value is 166\n",
|
||||
getErrorPathForX(code, 4U));
|
||||
|
||||
code = "void f() {\n"
|
||||
" int x = 123;\n"
|
||||
|
|
Loading…
Reference in New Issue