ValueFlow: We need better handling of casts

This commit is contained in:
Daniel Marjamäki 2016-12-10 22:09:01 +01:00
parent 2ca85a1c40
commit b098d5fbd6
3 changed files with 8 additions and 8 deletions

View File

@ -294,12 +294,13 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
if (!parent)
return;
// Cast..
// TODO: Cast..
/*
if (parent->str() == "(" && tok == parent->link()->next()) {
setTokenValue(parent,value,settings);
}
} else .. */
else if (parent->str() == ":") {
if (parent->str() == ":") {
setTokenValue(parent,value,settings);
}

View File

@ -264,11 +264,6 @@ private:
" cout << 42 / (float)0;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo() {\n"
" cout << 42 / (int)0;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero.\n", errout.str());
}
void zeroDiv2() {

View File

@ -371,6 +371,10 @@ private:
ASSERT_EQUALS(0, valueOfTok("3 < (a ? b : 2);", "<").intvalue);
ASSERT_EQUALS(0, valueOfTok("3 <= (a ? b : 2);", "<=").intvalue);
ASSERT(tokenValues("(UNKNOWN_TYPE)123;","(").empty());
ASSERT(tokenValues("(unsigned char)~0;", "(").empty()); // TODO: should get value 255
ASSERT(tokenValues("(int)0;", "(").empty()); // TODO: should get value 0
// Don't calculate if there is UB
ASSERT(tokenValues(";-1<<10;","<<").empty());
ASSERT(tokenValues(";10<<-1;","<<").empty());