diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 96793402b..62f62596f 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -945,6 +945,13 @@ static void setTokenValueCast(Token *parent, const ValueType &valueType, const V setTokenValue(parent, castValue(value, valueType.sign, settings->long_bit), settings); else if (valueType.type == ValueType::Type::LONGLONG) setTokenValue(parent, castValue(value, valueType.sign, settings->long_long_bit), settings); + else if (valueType.isFloat()) { + ValueFlow::Value floatValue = value; + floatValue.valueType = ValueFlow::Value::ValueType::FLOAT; + if (value.isIntValue()) + floatValue.floatValue = value.intvalue; + setTokenValue(parent, floatValue, settings); + } else if (value.isIntValue()) { const long long charMax = settings->signedCharMax(); const long long charMin = settings->signedCharMin(); diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 38a486cd2..af4f239b6 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -519,6 +519,8 @@ private: ASSERT_EQUALS((int)('\n'), valueOfTok("x='\\n';", "'\\n'").intvalue); TODO_ASSERT_EQUALS( 0xFFFFFFFF00000000, -1, valueOfTok("x=0xFFFFFFFF00000000;", "0xFFFFFFFF00000000").intvalue); // #7701 + ASSERT_EQUALS_DOUBLE(16, valueOfTok("x=(double)16;", "(").floatValue, 1e-5); + ASSERT_EQUALS_DOUBLE(0.0625, valueOfTok("x=1/(double)16;", "/").floatValue, 1e-5); // scope {