ValueFlow: Better handling when casting calculation result
This commit is contained in:
parent
f0d91fb74b
commit
f40bdddbab
|
@ -309,7 +309,7 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
|
||||||
if (!parent)
|
if (!parent)
|
||||||
return;
|
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);
|
const ValueType &valueType = ValueType::parseDecl(parent->next(), settings);
|
||||||
if (valueType.pointer)
|
if (valueType.pointer)
|
||||||
setTokenValue(parent,value,settings);
|
setTokenValue(parent,value,settings);
|
||||||
|
|
|
@ -381,6 +381,7 @@ private:
|
||||||
ASSERT(tokenValues("(UNKNOWN_TYPE)1000;","(").empty()); // don't know if there is truncation, sign extension
|
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(255, valueOfTok("(unsigned char)~0;", "(").intvalue);
|
||||||
ASSERT_EQUALS(0, valueOfTok("(int)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(0, valueOfTok("(UNKNOWN_TYPE*)0;","(").intvalue);
|
||||||
ASSERT_EQUALS(100, valueOfTok("(int)100.0;", "(").intvalue);
|
ASSERT_EQUALS(100, valueOfTok("(int)100.0;", "(").intvalue);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue