From 2fe39e2cc17aae34699bcff45762a87128000156 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 24 Dec 2024 14:12:17 +0100 Subject: [PATCH] enabled and fixed `-Wfloat-conversion` Clang warnings --- cmake/compileroptions.cmake | 1 - gui/statsdialog.cpp | 2 +- lib/json.h | 2 ++ lib/programmemory.cpp | 11 ++++++++--- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake index 55ab9beefc3..e42145d8809 100644 --- a/cmake/compileroptions.cmake +++ b/cmake/compileroptions.cmake @@ -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) diff --git a/gui/statsdialog.cpp b/gui/statsdialog.cpp index 35fb1fef36b..0de32120906 100644 --- a/gui/statsdialog.cpp +++ b/gui/statsdialog.cpp @@ -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(seconds); const int days = secs / (24 * 60 * 60); secs -= days * (24 * 60 * 60); const int hours = secs / (60 * 60); diff --git a/lib/json.h b/lib/json.h index a6ae93b27c2..ce9c8f116e1 100644 --- a/lib/json.h +++ b/lib/json.h @@ -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 @@ -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 diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 580a9bef2d9..f64b919f4f9 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -578,6 +578,11 @@ static double asFloat(const ValueFlow::Value& value) return value.isFloatValue() ? value.floatValue : static_cast(value.intvalue); } +static MathLib::bigint asInt(const ValueFlow::Value& value) +{ + return value.isFloatValue() ? static_cast(value.floatValue) : value.intvalue; +} + static std::string removeAssign(const std::string& assign) { return std::string{assign.cbegin(), assign.cend() - 1}; } @@ -587,7 +592,7 @@ namespace { template void operator()(T& x, const U& y) const { - x = y; + x = static_cast(y); } }; } @@ -896,7 +901,7 @@ static std::unordered_map 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; }; @@ -907,7 +912,7 @@ static std::unordered_map 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; };