cast: remove mistaken float-equality warnings for lossless cast

This commit is contained in:
Danny Robson 2019-12-03 09:34:02 +11:00
parent d69d3766ba
commit de282c556e

View File

@ -107,6 +107,14 @@ namespace cruft::cast {
lossless (const SrcT &src)
{
#ifndef NDEBUG
// GCC insists that the initial static_cast to DstT is a floating
// point comparison if we pass in a bool and a float.
//
// The only way around this is to ignore the warning locally (we use
// almost_equal inside CHECK_EQ anyway, so it should not be a concern).
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
auto dst = static_cast<DstT> (src);
if constexpr (std::is_floating_point_v<SrcT>) {
@ -120,6 +128,8 @@ namespace cruft::cast {
// Cast dst back to src to check round-trip conversion
// is lossless.
CHECK_EQ (static_cast<SrcT> (dst), src);
#pragma GCC diagnostic pop
return dst;
#else
#pragma GCC diagnostic push