From f98a942e2e0af75ff027988f6615340a42d50165 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 8 Apr 2012 15:29:15 +0000 Subject: [PATCH] Unordered/hash: Avoid a gcc warning. Refs #6771 [SVN r77832] --- .../boost/functional/hash/detail/hash_float.hpp | 16 +++++++++++++++- test/Jamfile.v2 | 4 ++-- test/hash_complex_test.cpp | 4 ++++ test/hash_float_test.hpp | 4 ++++ test/hash_number_test.cpp | 4 ++++ 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/boost/functional/hash/detail/hash_float.hpp b/include/boost/functional/hash/detail/hash_float.hpp index ea1bc25..194be1c 100644 --- a/include/boost/functional/hash/detail/hash_float.hpp +++ b/include/boost/functional/hash/detail/hash_float.hpp @@ -86,10 +86,24 @@ namespace boost { namespace hash_detail { + template + inline bool is_zero(T v) + { +#if !defined(__GNUC__) + return v == 0; +#else + // GCC's '-Wfloat-equal' will complain about comparing + // v to 0, but because it disables warnings for system + // headers it won't complain if you use std::equal_to to + // compare with 0. Resulting in this silliness: + return std::equal_to()(v, 0); +#endif + } + template inline std::size_t float_hash_value(T v) { - return v == 0 ? 0 : float_hash_impl(v); + return boost::hash_detail::is_zero(v) ? 0 : float_hash_impl(v); } } } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 7b3ccd9..cf64ece 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -10,8 +10,8 @@ project hash-tests all intel:on intel:-strict-ansi - gcc:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion" - darwin:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion" + gcc:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal" + darwin:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal" msvc:on #gcc:on #darwin:on diff --git a/test/hash_complex_test.cpp b/test/hash_complex_test.cpp index 67e2aff..bb1592c 100644 --- a/test/hash_complex_test.cpp +++ b/test/hash_complex_test.cpp @@ -35,6 +35,10 @@ int main() {} #endif #endif +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + #include #include #include diff --git a/test/hash_float_test.hpp b/test/hash_float_test.hpp index dd1358e..c608915 100644 --- a/test/hash_float_test.hpp +++ b/test/hash_float_test.hpp @@ -30,6 +30,10 @@ #endif #endif +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + char const* float_type(float*) { return "float"; } char const* float_type(double*) { return "double"; } char const* float_type(long double*) { return "long double"; } diff --git a/test/hash_number_test.cpp b/test/hash_number_test.cpp index b989d22..b233c71 100644 --- a/test/hash_number_test.cpp +++ b/test/hash_number_test.cpp @@ -28,6 +28,10 @@ #pragma warning(disable:4310) // cast truncates constant value #endif +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + template void numeric_test(T*) {