Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable gcc warning "floating constant exceeds range" and "floating constant truncated to zero"?

These obnoxious warnings are on-by-default in current gcc, and I can't find which option is needed to disable them. They're generating warning-spam and preventing compiling with -Werror in code where the behavior gcc warns about is intentional (and comes from general-purpose macros that could not easily avoid generating such constants).

like image 844
R.. GitHub STOP HELPING ICE Avatar asked Sep 01 '25 02:09

R.. GitHub STOP HELPING ICE


2 Answers

After digging through the GCC source code, I found that the warnings you've described are part of the -Woverflow option. So just turn off that warning.

By the way, this comment is in the code for the warning:

Both C and C++ require a diagnostic for a floating constant outside the range of representable values of its type... We also give a warning if the value underflows.

like image 98
chrisaycock Avatar answered Sep 02 '25 15:09

chrisaycock


In GCC 4.8, each warning comes with a clear indicator of which flag enables it:

floating constant exceeds range of 'double' [-Woverflow]

Good job, GCC devs.