Skip to content

Commit

Permalink
enabled and fixed -Wfloat-conversion Clang warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Jan 1, 2025
1 parent 047b725 commit 2fe39e2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 0 additions & 1 deletion cmake/compileroptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options_safe(-Wno-shadow-uncaptured-local)
add_compile_options_safe(-Wno-implicit-float-conversion)
add_compile_options_safe(-Wno-switch-enum)
add_compile_options_safe(-Wno-float-conversion)
add_compile_options_safe(-Wno-date-time)
add_compile_options(-Wno-disabled-macro-expansion)
add_compile_options_safe(-Wno-bitwise-instead-of-logical)
Expand Down
2 changes: 1 addition & 1 deletion gui/statsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void StatsDialog::setNumberOfFilesScanned(int num)
void StatsDialog::setScanDuration(double seconds)
{
// Factor the duration into units (days/hours/minutes/seconds)
int secs = seconds;
int secs = static_cast<int>(seconds);
const int days = secs / (24 * 60 * 60);
secs -= days * (24 * 60 * 60);
const int hours = secs / (60 * 60);
Expand Down
2 changes: 2 additions & 0 deletions lib/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ SUPPRESS_WARNING_CLANG_PUSH("-Wtautological-type-limit-compare")
SUPPRESS_WARNING_CLANG_PUSH("-Wextra-semi-stmt")
SUPPRESS_WARNING_CLANG_PUSH("-Wzero-as-null-pointer-constant")
SUPPRESS_WARNING_CLANG_PUSH("-Wformat")
SUPPRESS_WARNING_CLANG_PUSH("-Wfloat-conversion")

#define PICOJSON_USE_INT64
#include <picojson.h>
Expand All @@ -35,6 +36,7 @@ SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_GCC_POP
SUPPRESS_WARNING_POP

Expand Down
11 changes: 8 additions & 3 deletions lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,11 @@ static double asFloat(const ValueFlow::Value& value)
return value.isFloatValue() ? value.floatValue : static_cast<double>(value.intvalue);
}

static MathLib::bigint asInt(const ValueFlow::Value& value)
{
return value.isFloatValue() ? static_cast<MathLib::bigint>(value.floatValue) : value.intvalue;
}

static std::string removeAssign(const std::string& assign) {
return std::string{assign.cbegin(), assign.cend() - 1};
}
Expand All @@ -587,7 +592,7 @@ namespace {
template<class T, class U>
void operator()(T& x, const U& y) const
{
x = y;
x = static_cast<T>(y);
}
};
}
Expand Down Expand Up @@ -896,7 +901,7 @@ static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibr
return ValueFlow::Value::unknown();
ValueFlow::Value v;
combineValueProperties(args[0], args[1], v);
v.floatValue = std::scalbln(asFloat(args[0]), asFloat(args[1]));
v.floatValue = std::scalbln(asFloat(args[0]), asInt(args[1]));
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
Expand All @@ -907,7 +912,7 @@ static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibr
return ValueFlow::Value::unknown();
ValueFlow::Value v;
combineValueProperties(args[0], args[1], v);
v.floatValue = std::ldexp(asFloat(args[0]), asFloat(args[1]));
v.floatValue = std::ldexp(asFloat(args[0]), asInt(args[1]));
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
Expand Down

0 comments on commit 2fe39e2

Please sign in to comment.