Fixed #8575 (false positive: longCastAssign)

This commit is contained in:
Daniel Marjamäki 2018-06-04 22:51:21 +02:00
parent 0c6d60d202
commit b9c1308a81
2 changed files with 12 additions and 0 deletions

View File

@ -268,6 +268,12 @@ void CheckType::checkLongCast()
if (tok->str() != "=" || !Token::Match(tok->astOperand2(), "*|<<"))
continue;
if (tok->astOperand2()->hasKnownIntValue()) {
const ValueFlow::Value &v = tok->astOperand2()->values().front();
if (_settings->isIntValue(v.intvalue))
continue;
}
const ValueType *lhstype = tok->astOperand1() ? tok->astOperand1()->valueType() : nullptr;
const ValueType *rhstype = tok->astOperand2()->valueType();

View File

@ -232,6 +232,12 @@ private:
"}\n", &settings);
ASSERT_EQUALS("[test.cpp:2]: (style) int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information.\n", errout.str());
check("long f() {\n"
" const long long ret = 256 * (1 << 10);\n"
" return ret;\n"
"}\n", &settings);
ASSERT_EQUALS("", errout.str());
// typedef
check("long f(int x, int y) {\n"
" const size_t ret = x * y;\n"