ValueFlow: Better handling when casting calculation result

This commit is contained in:
Daniel Marjamäki 2016-12-20 23:09:50 +01:00
parent f0d91fb74b
commit f40bdddbab
2 changed files with 2 additions and 1 deletions

View File

@ -309,7 +309,7 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
if (!parent)
return;
if (parent->str() == "(" && tok == parent->link()->next()) {
if (parent->str() == "(" && !parent->astOperand2() && Token::Match(parent,"( %name%")) {
const ValueType &valueType = ValueType::parseDecl(parent->next(), settings);
if (valueType.pointer)
setTokenValue(parent,value,settings);

View File

@ -381,6 +381,7 @@ private:
ASSERT(tokenValues("(UNKNOWN_TYPE)1000;","(").empty()); // don't know if there is truncation, sign extension
ASSERT_EQUALS(255, valueOfTok("(unsigned char)~0;", "(").intvalue);
ASSERT_EQUALS(0, valueOfTok("(int)0;", "(").intvalue);
ASSERT_EQUALS(3, valueOfTok("(int)(1+2);", "(").intvalue);
ASSERT_EQUALS(0, valueOfTok("(UNKNOWN_TYPE*)0;","(").intvalue);
ASSERT_EQUALS(100, valueOfTok("(int)100.0;", "(").intvalue);