http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59961
Bug ID: 59961
Summary: Use of size_t in leading term of computation with
subtraction
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: olaf at robots dot ox.ac.uk
The minimalistic example further down produces a very unexpected result and no
warnings at all. I understand that size_t s1 can not be negative. However, in
my example using "-s1*..." in the leading term of the computation therefore
seems to cause an overflow.
Quite curiously, a similar bug is caused when using "unsigned int" instead of
size_t, but no bugs are caused if using "unsigned short" or "unsigned char".
The bug also does not appear if the + and - terms are swapped. All of this is
on an x86_64 platform.
Even if may be correct in a very obscure way according to some C specification,
it would be very helpful to issue a warning with -Wall -Wextra
/* compile with gcc -Wall -Wextra testcase.c */
#include
int main(int ac, char**dc)
{
ac = ac; dc = dc;
size_t s1 = 100;
size_t s2 = 200;
double d1 = 0.123;
double d2 = 0.234;
double result = -s1*d1 + s2*d2;
printf("%lf %lf\n", result, -100*0.123+200*0.234);
return 0;
}