[Bug c++/20019] incorrect overflow warning
igodard at pacbell dot net
gcc-bugzilla@gcc.gnu.org
Thu Feb 17 14:06:00 GMT 2005
------- Additional Comments From igodard at pacbell dot net 2005-02-17 04:10 -------
Please:
yes, the int value lwbi arising from the conversion of char(0x80) is the int
value 0xffffff80, i.e. int(-128); you are quite right about that. That value is
being *subtracted* from the int value upbi arising from the conversion of
char(0x7f) which is the value 0x0000007f, i.e. 127. If you subtract -128 from
127, i.e (127 - (-128)), the result is 255, a positive number and there is NO
overflow. This is signed subtract and it is permitted to subtract a negative
from a positive. The result is exact.
The result of the subtract is the positive number int(255). That can be
converted to size_t (which is unsigned in in this case) also without overflow.
Yet there is still a warning message.
If the problem here is not clear, please pass this report on to your other
colleagues for a second opinion. Thank you.
Ivan
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20019
More information about the Gcc-bugs
mailing list