cast: remove mistaken float-equality warnings for lossless cast
This commit is contained in:
parent
d69d3766ba
commit
de282c556e
10
cast.hpp
10
cast.hpp
@ -107,6 +107,14 @@ namespace cruft::cast {
|
|||||||
lossless (const SrcT &src)
|
lossless (const SrcT &src)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
#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);
|
auto dst = static_cast<DstT> (src);
|
||||||
|
|
||||||
if constexpr (std::is_floating_point_v<SrcT>) {
|
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
|
// Cast dst back to src to check round-trip conversion
|
||||||
// is lossless.
|
// is lossless.
|
||||||
CHECK_EQ (static_cast<SrcT> (dst), src);
|
CHECK_EQ (static_cast<SrcT> (dst), src);
|
||||||
|
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
return dst;
|
return dst;
|
||||||
#else
|
#else
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
|
Loading…
Reference in New Issue
Block a user