diff --git a/include/gsl/narrow b/include/gsl/narrow index bad581ca..2c3c5188 100644 --- a/include/gsl/narrow +++ b/include/gsl/narrow @@ -43,10 +43,17 @@ GSL_SUPPRESS(p.2) // NO-FORMAT: attribute // don't rely on undefined behavior // and cannot fit into the destination integral type), the resultant behavior is benign on the platforms // that we target (i.e., no hardware trap representations are hit). +#if defined(__clang__) || defined(__GNUC__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wfloat-equal" +#endif if (static_cast(t) != u || (is_different_signedness && ((t < T{}) != (u < U{})))) { throw narrowing_error{}; } +#if defined(__clang__) || defined(__GNUC__) + #pragma GCC diagnostic pop +#endif return t; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 891569be..68e18ec3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -89,6 +89,7 @@ if(MSVC) # MSVC or simulating MSVC > $<$: -Weverything + -Wfloat-equal -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-covered-switch-default # GTest @@ -122,6 +123,7 @@ else() -Wpedantic -Wshadow -Wsign-conversion + -Wfloat-equal -Wno-deprecated-declarations # Allow tests for [[deprecated]] elements $<$,$>: -Weverything @@ -227,6 +229,7 @@ if(MSVC) # MSVC or simulating MSVC > $<$: -Weverything + -Wfloat-equal -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-missing-prototypes @@ -250,6 +253,7 @@ else() -Wpedantic -Wshadow -Wsign-conversion + -Wfloat-equal $<$,$>: -Weverything -Wno-c++98-compat diff --git a/tests/utils_tests.cpp b/tests/utils_tests.cpp index 39b4ca2f..715073fe 100644 --- a/tests/utils_tests.cpp +++ b/tests/utils_tests.cpp @@ -149,5 +149,7 @@ TEST(utils_tests, narrow) EXPECT_TRUE( narrow>(std::complex(4, 2)) == std::complex(4, 2)); EXPECT_THROW(narrow>(std::complex(4.2)), narrowing_error); + + EXPECT_TRUE(narrow(float(1)) == 1); } #endif // GSL_KERNEL_MODE