ValueFlow: set values for false/true

This commit is contained in:
Daniel Marjamäki 2015-07-14 18:02:26 +02:00
parent fa03a93f89
commit 405a1fba11
2 changed files with 10 additions and 6 deletions

View File

@ -455,6 +455,13 @@ static void valueFlowNumber(TokenList *tokenlist)
if (tok->isNumber() && MathLib::isInt(tok->str()))
setTokenValue(tok, ValueFlow::Value(MathLib::toLongNumber(tok->str())));
}
if (tokenlist->isCPP()) {
for (Token *tok = tokenlist->front(); tok; tok = tok->next()) {
if (tok->isName() && !tok->varId() && Token::Match(tok, "false|true"))
setTokenValue(tok, ValueFlow::Value(tok->str() == "true"));
}
}
}
static void valueFlowString(TokenList *tokenlist)

View File

@ -151,12 +151,9 @@ private:
}
void valueFlowNumber() {
const char *code;
code = "void f() {\n"
" x = 123;\n"
"}";
ASSERT_EQUALS(123, valueOfTok(code, "123").intvalue);
ASSERT_EQUALS(123, valueOfTok("x=123;", "123").intvalue);
ASSERT_EQUALS(0, valueOfTok("x=false;", "false").intvalue);
ASSERT_EQUALS(1, valueOfTok("x=true;", "true").intvalue);
}
void valueFlowString() {