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.