From 46fd1a60787fc5da8f6a2131736da8461a541e5d Mon Sep 17 00:00:00 2001 From: Ferry Huberts Date: Sat, 2 Sep 2023 21:40:37 +0200 Subject: [PATCH] Fix Clang compiler warnings (-Wno-float-equal) Signed-off-by: Ferry Huberts --- cmake/compiler-flags.cmake | 1 - test/oatpp/parser/json/mapping/DTOMapperTest.cpp | 6 ++++-- test/oatpp/parser/json/mapping/DeserializerTest.cpp | 12 +++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cmake/compiler-flags.cmake b/cmake/compiler-flags.cmake index 532e6fbb..8b02cc17 100644 --- a/cmake/compiler-flags.cmake +++ b/cmake/compiler-flags.cmake @@ -293,7 +293,6 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compiler_flags(10 "-Wno-documentation") add_compiler_flags(10 "-Wno-documentation-unknown-command") add_compiler_flags(10 "-Wno-exit-time-destructors") - add_compiler_flags(10 "-Wno-float-equal") add_compiler_flags(10 "-Wno-format-nonliteral") add_compiler_flags(10 "-Wno-global-constructors") add_compiler_flags(10 "-Wno-gnu-zero-variadic-macro-arguments") diff --git a/test/oatpp/parser/json/mapping/DTOMapperTest.cpp b/test/oatpp/parser/json/mapping/DTOMapperTest.cpp index 79174089..5eb1ef73 100644 --- a/test/oatpp/parser/json/mapping/DTOMapperTest.cpp +++ b/test/oatpp/parser/json/mapping/DTOMapperTest.cpp @@ -24,6 +24,8 @@ #include "DTOMapperTest.hpp" +#include + #include "oatpp/parser/json/mapping/ObjectMapper.hpp" #include "oatpp/core/data/mapping/type/Object.hpp" @@ -234,10 +236,10 @@ void DTOMapperTest::onRun(){ OATPP_ASSERT(obj1->field_int64 == test1->field_int64) OATPP_ASSERT(obj1->field_float32) - OATPP_ASSERT(obj1->field_float32 == test1->field_float32) + OATPP_ASSERT(fabsf(obj1->field_float32 - test1->field_float32) < std::numeric_limits::epsilon()) OATPP_ASSERT(obj1->field_float64) - OATPP_ASSERT(obj1->field_float64 == test1->field_float64) + OATPP_ASSERT(fabs(obj1->field_float64 - test1->field_float64) < std::numeric_limits::epsilon()) OATPP_ASSERT(obj1->field_boolean) OATPP_ASSERT(obj1->field_boolean == test1->field_boolean) diff --git a/test/oatpp/parser/json/mapping/DeserializerTest.cpp b/test/oatpp/parser/json/mapping/DeserializerTest.cpp index c481fa2d..a2122500 100644 --- a/test/oatpp/parser/json/mapping/DeserializerTest.cpp +++ b/test/oatpp/parser/json/mapping/DeserializerTest.cpp @@ -24,6 +24,8 @@ #include "DeserializerTest.hpp" +#include + #include "oatpp/parser/json/mapping/ObjectMapper.hpp" #include "oatpp/core/macro/codegen.hpp" @@ -133,7 +135,7 @@ void DeserializerTest::onRun(){ obj3 = mapper->readFromString>("{\"float32F\": 32}"); OATPP_ASSERT(obj3) - OATPP_ASSERT(obj3->float32F == 32) + OATPP_ASSERT(fabsf(obj3->float32F - 32) < std::numeric_limits::epsilon()) obj3 = mapper->readFromString>("{\"float32F\": 1.32e1}"); @@ -202,28 +204,28 @@ void DeserializerTest::onRun(){ auto dto = mapper->readFromString>(R"({"any":-1.23456789,"another":1.1})"); OATPP_ASSERT(dto) OATPP_ASSERT(dto->any.getStoredType() == Float64::Class::getType()) - OATPP_ASSERT(dto->any.retrieve() == -1.23456789) + OATPP_ASSERT(fabs(dto->any.retrieve() - -1.23456789) < std::numeric_limits::epsilon()) } OATPP_LOGD(TAG, "Any: Positive Float") { auto dto = mapper->readFromString>(R"({"any":1.23456789,"another":1.1})"); OATPP_ASSERT(dto) OATPP_ASSERT(dto->any.getStoredType() == Float64::Class::getType()) - OATPP_ASSERT(dto->any.retrieve() == 1.23456789) + OATPP_ASSERT(fabs(dto->any.retrieve() - 1.23456789) < std::numeric_limits::epsilon()) } OATPP_LOGD(TAG, "Any: Negative exponential Float") { auto dto = mapper->readFromString>(R"({"any":-1.2345e30,"another":1.1})"); OATPP_ASSERT(dto) OATPP_ASSERT(dto->any.getStoredType() == Float64::Class::getType()) - OATPP_ASSERT(dto->any.retrieve() == -1.2345e30) + OATPP_ASSERT(fabs(dto->any.retrieve() - -1.2345e30) < std::numeric_limits::epsilon()) } OATPP_LOGD(TAG, "Any: Positive exponential Float") { auto dto = mapper->readFromString>(R"({"any":1.2345e30,"another":1.1})"); OATPP_ASSERT(dto) OATPP_ASSERT(dto->any.getStoredType() == Float64::Class::getType()) - OATPP_ASSERT(dto->any.retrieve() == 1.2345e30) + OATPP_ASSERT(fabs(dto->any.retrieve() - 1.2345e30) < std::numeric_limits::epsilon()) } OATPP_LOGD(TAG, "Any: Unsigned Integer") {