Skip to content

Commit

Permalink
always calculate as float
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Fultz II <[email protected]>
  • Loading branch information
firewave and pfultz2 committed Jan 7, 2025
1 parent 50c53e9 commit ef3337d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 12 additions & 2 deletions lib/vf_settokenvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,19 @@ namespace ValueFlow
}
bool error = false;
if (isFloat) {
result.floatValue = calculate(parent->str(), floatValue1, floatValue2, &error);
auto val = calculate(parent->str(), floatValue1, floatValue2, &error);
if (result.isFloatValue()) {
result.floatValue = val;
} else {
result.intvalue = static_cast<MathLib::bigint>(val);
}
} else {
result.intvalue = calculate(parent->str(), intValue1(), intValue2(), &error);
auto val = calculate(parent->str(), intValue1(), intValue2(), &error);
if (result.isFloatValue()) {
result.floatValue = static_cast<double>(val);
} else {
result.intvalue = val;
}
}
if (error)
continue;
Expand Down
8 changes: 2 additions & 6 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4465,11 +4465,9 @@ class TestCondition : public TestFixture {
" float f = 9.9f;\n"
" if(f < 10) {}\n"
"}\n");
TODO_ASSERT_EQUALS(
ASSERT_EQUALS(
"[test.cpp:3]: (style) Condition 'i>9.9' is always true\n"
"[test.cpp:5]: (style) Condition 'f<10' is always true\n",
"[test.cpp:3]: (style) Condition 'i>9.9' is always false\n"
"[test.cpp:5]: (style) Condition 'f<10' is always false\n",
errout_str());
check("constexpr int f() {\n" // #11238
" return 1;\n"
Expand Down Expand Up @@ -6284,11 +6282,9 @@ class TestCondition : public TestFixture {
" if (f > 9.9) {}\n"
" if (f < 9.9) {}\n"
"}\n");
TODO_ASSERT_EQUALS(
ASSERT_EQUALS(
"[test.cpp:3]: (style) Condition 'f>9.9' is always true\n"
"[test.cpp:4]: (style) Condition 'f<9.9' is always false\n",
"[test.cpp:3]: (style) Condition 'f>9.9' is always false\n"
"[test.cpp:4]: (style) Condition 'f<9.9' is always false\n",
errout_str());

check("void foo() {\n" // #12330
Expand Down

0 comments on commit ef3337d

Please sign in to comment.