[Bug c/18128] New: REGRESSION: Wrong precedence
adamm at zombino dot com
gcc-bugzilla@gcc.gnu.org
Sun Oct 24 18:57:00 GMT 2004
Produces wrong code on both 3.3.4 and 3.4.2 (in Debian Sid). It works perfectly
with gcc 2.95.
The problem is that,
-A+B == B-A
-A()+B == B-A()
-A+B() == B()-A
but,
-A()+B() ?= B()-A()
if A or B depend on each other, the last condition is !=. Otherwise, it is ==.
This breaks any code that relies on things like stack to execute operations, for
example,
stack<int> A;
A.push(5);
A.push(2);
// do a subtraction of 5-2 and push resuls onto stack
A.push( -A.pop() + A.pop());
What it does, it actually A.pop() - A.pop() which is very wrong.
>>>>>>>>>>>>> TEST CASE >>>>>>>>>>>>>>>>>>>>>>>>>
#include <stdio.h>
double A(){
static int div;
double r = 10.0/++div+div;
printf( "A() returns: %f iteration %d\n", r, div );
return r;
}
int main()
{
/* EXECUTES A()-A() INSTEAD OF -A()+A() */
printf( "-4.0 is %f\n", -A() + A());
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
reported in Debian BTS: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=278081
--
Summary: REGRESSION: Wrong precedence
Product: gcc
Version: 3.3.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: adamm at zombino dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i386-linux
GCC host triplet: i386-linux
GCC target triplet: i386-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18128
More information about the Gcc-bugs
mailing list