Fixed #6996 (ValueFlow: known and possible values)

This commit is contained in:
Frank Zingsheim 2015-10-04 10:33:43 +02:00 committed by Daniel Marjamäki
parent f5bd00f153
commit 3bc21b8138
2 changed files with 14 additions and 0 deletions

View File

@ -358,6 +358,11 @@ static bool isVariableChanged(const Token *start, const Token *end, const unsign
/** Add token value. Return true if value is added. */
static bool addValue(Token *tok, const ValueFlow::Value &value)
{
if (value.isKnown()) {
// Clear all other values since value is known
tok->values.clear();
}
// if value already exists, don't add it again
std::list<ValueFlow::Value>::iterator it;
for (it = tok->values.begin(); it != tok->values.end(); ++it) {

View File

@ -1775,6 +1775,15 @@ private:
value = valueOfTok(code, "+");
ASSERT_EQUALS(13, value.intvalue);
ASSERT(value.isPossible());
// known and possible value
code = "void f() {\n"
" int x = 1;\n"
" int y = 2 + x;\n" // <- known value, don't care about condition
" if (x == 2) {}\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 3U, 1)); // value of x can be 1
ASSERT_EQUALS(false, testValueOfX(code, 3U, 2)); // value of x can't be 2
}
};