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

mckelvey at maskull dot com gcc-bugzilla@gcc.gnu.org
Tue Jun 28 21:54:25 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106128

            Bug ID: 106128
           Summary: Bogus Warning on static_cast double to bool with
                    -Wfloat-equal
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mckelvey at maskull dot com
  Target Milestone: ---

static_cast should not warn on its internals.


    int main()
    {
        double xx(0.0);

        // Warning
        bool y = static_cast<bool>(xx);

        // No warning
        bool z = static_cast<bool>(0.0);

        return 0;
    }

g++ -Wfloat-equal -c test.cc

test.cc: In function ‘int main()’:
test.cc:6:36: warning: comparing floating-point with ‘==’ or ‘!=’ is unsafe
[-Wfloat-equal]
    6 |         bool y = static_cast<bool>(xx);
      |                                    ^~

$ /usr/local/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/usr/local/bin/g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-cygwin/13.0.0/lto-wrapper.exe
Target: x86_64-pc-cygwin
Configured with: ./configure --enable-languages=c,c++ --enable-threads=posix
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.0.0 20220626 (experimental) (GCC)

$ uname
CYGWIN_NT-10.0-19044


Fails on gcc-11-20220624, gcc-12-20220625, gcc-13-20220626


More information about the Gcc-bugs mailing list