[Bug c/53603] New: abs() doesn't warn if argument is double, not even with -Wall -Wextra
gcc at richardneill dot org
Thu Jun 7 13:13:00 GMT 2012
Bug #: 53603
Summary: abs() doesn't warn if argument is double, not even
with -Wall -Wextra
I think that using abs() with an argument which isn't an int, should to trigger
a warning... but it doesn't. Not even with -Wextra.
//Compile with Wall -Wextra
//I think that gcc could spot that abs() casts x to int,
//and it could warn me that I did something stupid.
y = abs (x);
printf ("y is %f\n", y);
//get 44.000000 , expect 44.330000
Please do consider trapping this: I spent 3 hours finding a bug caused by this
one: yes, it was my fault for writing sqrt(abs(a_double)) rather than
sqrt(fabs(a_double)), but the compiler could have warned me. This type of error
is quite insidious, because it can cause subtle errors in mathematical programs
that only occur sometimes!
Imho, gcc should warn, unless I'd written:
y = abs( (int)x )
More information about the Gcc-bugs