[Bug c++/17645] Add a warning for potentially unsafe unsigned operations
trt at acm dot org
gcc-bugzilla@gcc.gnu.org
Fri Sep 24 14:41:00 GMT 2004
------- Additional Comments From trt at acm dot org 2004-09-24 14:41 -------
I tried a gcc with this warning on a large (35Mloc) source code base and it did
not spot any bugs. In my experience with this code base, almost any plausible
warning will spot at least a few bugs, so this is not encouraging.
The warning looked for expressions whose type changes from unsigned to signed,
which contain a NEGATE_EXPR, MINUS_EXPR, or BIT_NOT_EXPR,
and which are either widened or converted to floating point.
It did emit some warnings, mostly for code which subtracts 1 such as
/* double x; unsigned int n; */
x = 1.0 / (n-1);
In context it seems unlikely this is buggy. Suppressing the warning
for subtraction of 1 would mostly eliminate the false positives,
but that doesn't overcome the problem that it found no likely bugs.
unsigned/signed can be hazardous, but it is hard to detect that at compile time.
I think it would be more helpful for the compiler to optionally insert run-time
checks do detect the cases where signedness would affect the outcome.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17645
More information about the Gcc-bugs
mailing list