public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105278] New: no warning for precise literals compared with floats
@ 2022-04-14 15:41 dcb314 at hotmail dot com
  2022-04-14 17:51 ` [Bug c++/105278] " egallager at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: dcb314 at hotmail dot com @ 2022-04-14 15:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105278
           Summary: no warning for precise literals compared with floats
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcb314 at hotmail dot com
  Target Milestone: ---

For this C++ code:

extern void g( int);

void f( float a)
{
        if (a == 0.1234)
                g( 1);
}

recent gcc trunk has nothing to say:

$ /home/dcb/gcc/results/bin/gcc -c -g -O2 -Wall -Wextra -pedantic apr14b.cc
$ 

Here is clang finding the problem:

$ /home/dcb/llvm/results/bin/clang -c -g -O2 -Wall   apr14b.cc
apr14b.cc:6:8: warning: floating-point comparison is always false; constant
cannot be represented exactly in type 'float' [-Wliteral-range]
        if (a == 0.1234)
            ~ ^  ~~~~~~~~~~~
1 warning generated.

Interestingly, if float is replaced by double, the warning goes away.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-11-17 18:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-14 15:41 [Bug c++/105278] New: no warning for precise literals compared with floats dcb314 at hotmail dot com
2022-04-14 17:51 ` [Bug c++/105278] " egallager at gcc dot gnu.org
2022-04-14 18:44 ` dcb314 at hotmail dot com
2022-04-14 19:29 ` egallager at gcc dot gnu.org
2022-04-14 19:43 ` dcb314 at hotmail dot com
2022-11-16 22:52 ` pinskia at gcc dot gnu.org
2022-11-16 22:54 ` [Bug c++/105278] -Wliteral-range vs -Wfloat-equal pinskia at gcc dot gnu.org
2022-11-17 13:33 ` egallager at gcc dot gnu.org
2022-11-17 18:40 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).