Fixed #8575 (false positive: longCastAssign)
This commit is contained in:
parent
0c6d60d202
commit
b9c1308a81
|
@ -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();
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue