public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/27257] New: Error integer compare in g++ 4.1.0
@ 2006-04-22 4:56 johnzhang at tencent dot com
2006-04-22 8:23 ` [Bug c++/27257] " pluto at agmk dot net
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: johnzhang at tencent dot com @ 2006-04-22 4:56 UTC (permalink / raw)
To: gcc-bugs
0X80000000 - 10 < 0 and 10 - 0X80000000 < 0
gcc version 3.3.4 gets a right result of comparing between 10 and 0X80000000,
but gcc version 4.1.0 fails.
the test code followed:
#include <stdio.h>
int main()
{
int b = 0X80000000;
if ((10 - b) < 0)
{
printf("(10 - b) = %d < 0 is True\n", 10 - b);
}
else
{
printf("(10 - b) = %d < 0 is False\n", 10 - b);
}
if ((b - 10) < 0)
{
printf("(b - 10) = %d < 0 is True\n", b - 10);
}
else
{
printf("(b - 10) = %d < 0 is False\n", b - 10);
}
return 0;
}
I had tested the code and got the result:
bingo@sttest:~/tmp> ../bin/g++ t.cpp
bingo@sttest:~/tmp> a.out
(10 - b) = -2147483638 < 0 is True
(b - 10) = 2147483638 < 0 is True
--
Summary: Error integer compare in g++ 4.1.0
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: johnzhang at tencent dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27257
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/27257] Error integer compare in g++ 4.1.0
2006-04-22 4:56 [Bug c++/27257] New: Error integer compare in g++ 4.1.0 johnzhang at tencent dot com
@ 2006-04-22 8:23 ` pluto at agmk dot net
2006-04-22 15:35 ` pinskia at gcc dot gnu dot org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pluto at agmk dot net @ 2006-04-22 8:23 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pluto at agmk dot net 2006-04-22 08:23 -------
(In reply to comment #0)
> int b = 0X80000000;
> if ((b - 10) < 0)
b - 10 is 0xff(...)7ffffff6 and this is an integer overflow.
[ cite: c++ standard / $5.5 ]
if during the evaluation of an expression the result isn't mathematically
defined nor in the range of representable values for its type the behaviuor
is undefined, unless such an expression is a constant expression, in which
case the program is ill-formed. (...)
[ /cite ]
so, use -fwrapv (man g++) to get not quite correct behaviour.
--
pluto at agmk dot net changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pluto at agmk dot net
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27257
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/27257] Error integer compare in g++ 4.1.0
2006-04-22 4:56 [Bug c++/27257] New: Error integer compare in g++ 4.1.0 johnzhang at tencent dot com
2006-04-22 8:23 ` [Bug c++/27257] " pluto at agmk dot net
@ 2006-04-22 15:35 ` pinskia at gcc dot gnu dot org
2006-04-28 6:36 ` johnzhang at tencent dot com
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-04-22 15:35 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2006-04-22 15:35 -------
This is signed int overflow being undefined, in fact I should I know because I
was the one who write the patch to optimize this.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27257
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/27257] Error integer compare in g++ 4.1.0
2006-04-22 4:56 [Bug c++/27257] New: Error integer compare in g++ 4.1.0 johnzhang at tencent dot com
2006-04-22 8:23 ` [Bug c++/27257] " pluto at agmk dot net
2006-04-22 15:35 ` pinskia at gcc dot gnu dot org
@ 2006-04-28 6:36 ` johnzhang at tencent dot com
2006-04-28 16:29 ` pinskia at gcc dot gnu dot org
2007-01-15 20:04 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: johnzhang at tencent dot com @ 2006-04-28 6:36 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from johnzhang at tencent dot com 2006-04-28 06:36 -------
Ok, you are right. it would be nice if g++ 4.1.0 acts as what g++ 3.3.4 does.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27257
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/27257] Error integer compare in g++ 4.1.0
2006-04-22 4:56 [Bug c++/27257] New: Error integer compare in g++ 4.1.0 johnzhang at tencent dot com
` (2 preceding siblings ...)
2006-04-28 6:36 ` johnzhang at tencent dot com
@ 2006-04-28 16:29 ` pinskia at gcc dot gnu dot org
2007-01-15 20:04 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-04-28 16:29 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from pinskia at gcc dot gnu dot org 2006-04-28 16:29 -------
(In reply to comment #3)
> Ok, you are right. it would be nice if g++ 4.1.0 acts as what g++ 3.3.4 does.
Use -fwrapv if you want defined wrapping.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27257
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/27257] Error integer compare in g++ 4.1.0
2006-04-22 4:56 [Bug c++/27257] New: Error integer compare in g++ 4.1.0 johnzhang at tencent dot com
` (3 preceding siblings ...)
2006-04-28 16:29 ` pinskia at gcc dot gnu dot org
@ 2007-01-15 20:04 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-01-15 20:04 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from pinskia at gcc dot gnu dot org 2007-01-15 20:04 -------
*** Bug 30475 has been marked as a duplicate of this bug. ***
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |felix-gcc at fefe dot de
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27257
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-01-15 20:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-22 4:56 [Bug c++/27257] New: Error integer compare in g++ 4.1.0 johnzhang at tencent dot com
2006-04-22 8:23 ` [Bug c++/27257] " pluto at agmk dot net
2006-04-22 15:35 ` pinskia at gcc dot gnu dot org
2006-04-28 6:36 ` johnzhang at tencent dot com
2006-04-28 16:29 ` pinskia at gcc dot gnu dot org
2007-01-15 20:04 ` pinskia at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).