Skip to content

Commit 7db4566

Browse files
authored
enabled and fixed -Wfloat-conversion Clang warnings (danmar#7156)
1 parent ce5690a commit 7db4566

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

cmake/compileroptions.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
119119
add_compile_options_safe(-Wno-shadow-uncaptured-local)
120120
add_compile_options_safe(-Wno-implicit-float-conversion)
121121
add_compile_options_safe(-Wno-switch-enum)
122-
add_compile_options_safe(-Wno-float-conversion)
123122
add_compile_options_safe(-Wno-date-time)
124123
add_compile_options(-Wno-disabled-macro-expansion)
125124
add_compile_options_safe(-Wno-bitwise-instead-of-logical)

gui/statsdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void StatsDialog::setNumberOfFilesScanned(int num)
149149
void StatsDialog::setScanDuration(double seconds)
150150
{
151151
// Factor the duration into units (days/hours/minutes/seconds)
152-
int secs = seconds;
152+
int secs = static_cast<int>(seconds);
153153
const int days = secs / (24 * 60 * 60);
154154
secs -= days * (24 * 60 * 60);
155155
const int hours = secs / (60 * 60);

lib/json.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ SUPPRESS_WARNING_CLANG_PUSH("-Wtautological-type-limit-compare")
2727
SUPPRESS_WARNING_CLANG_PUSH("-Wextra-semi-stmt")
2828
SUPPRESS_WARNING_CLANG_PUSH("-Wzero-as-null-pointer-constant")
2929
SUPPRESS_WARNING_CLANG_PUSH("-Wformat")
30+
SUPPRESS_WARNING_CLANG_PUSH("-Wfloat-conversion")
3031

3132
#define PICOJSON_USE_INT64
3233
#include <picojson.h>
@@ -35,6 +36,7 @@ SUPPRESS_WARNING_CLANG_POP
3536
SUPPRESS_WARNING_CLANG_POP
3637
SUPPRESS_WARNING_CLANG_POP
3738
SUPPRESS_WARNING_CLANG_POP
39+
SUPPRESS_WARNING_CLANG_POP
3840
SUPPRESS_WARNING_GCC_POP
3941
SUPPRESS_WARNING_POP
4042

lib/programmemory.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,11 @@ static double asFloat(const ValueFlow::Value& value)
578578
return value.isFloatValue() ? value.floatValue : static_cast<double>(value.intvalue);
579579
}
580580

581+
static MathLib::bigint asInt(const ValueFlow::Value& value)
582+
{
583+
return value.isFloatValue() ? static_cast<MathLib::bigint>(value.floatValue) : value.intvalue;
584+
}
585+
581586
static std::string removeAssign(const std::string& assign) {
582587
return std::string{assign.cbegin(), assign.cend() - 1};
583588
}
@@ -587,7 +592,7 @@ namespace {
587592
template<class T, class U>
588593
void operator()(T& x, const U& y) const
589594
{
590-
x = y;
595+
x = static_cast<T>(y);
591596
}
592597
};
593598
}
@@ -896,7 +901,7 @@ static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibr
896901
return ValueFlow::Value::unknown();
897902
ValueFlow::Value v;
898903
combineValueProperties(args[0], args[1], v);
899-
v.floatValue = std::scalbln(asFloat(args[0]), asFloat(args[1]));
904+
v.floatValue = std::scalbln(asFloat(args[0]), asInt(args[1]));
900905
v.valueType = ValueFlow::Value::ValueType::FLOAT;
901906
return v;
902907
};
@@ -907,7 +912,7 @@ static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibr
907912
return ValueFlow::Value::unknown();
908913
ValueFlow::Value v;
909914
combineValueProperties(args[0], args[1], v);
910-
v.floatValue = std::ldexp(asFloat(args[0]), asFloat(args[1]));
915+
v.floatValue = std::ldexp(asFloat(args[0]), asInt(args[1]));
911916
v.valueType = ValueFlow::Value::ValueType::FLOAT;
912917
return v;
913918
};

0 commit comments

Comments
 (0)