[Bug c++/106128] Bogus Warning on static_cast double to bool with -Wfloat-equal

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Jun 28 22:02:08 GMT 2022


Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>its internals

What do you mean internals?

When you do a static cast anything to a bool, it is always converted to "!= 0".
This is not an internal part of GCC but part of the language. 

GCC is not warning about the constant version because it know exactly that 0.0
!= 0.0 will be true at compile time as it is considered an constant expression
as required by the C++ standard.

clang does not have -Wfloat-equal so there is nothing to compare against here.

Also note comparing against 0.0 will have -0.0 be equal too. Which might not be
what you wnated either.

More information about the Gcc-bugs mailing list