This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/53382] New: incorrect associativity in expressions
- From: "miguel.barao at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 16 May 2012 23:03:31 +0000
- Subject: [Bug c/53382] New: incorrect associativity in expressions
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53382
Bug #: 53382
Summary: incorrect associativity in expressions
Classification: Unclassified
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: miguel.barao@gmail.com
I found the following behavior while writing a small RPN calculator.
The ideia is to perform a subtraction on the two top elements of a stack using
push(&mystack, -pop(&mystack) + pop(&mystack));
Since the + associativity is left-to-right, this should pop the stack, negate
this value, pop the second argument then add. But the order is reversed in gcc
leading to a wrong result.
The behavior was observed in gcc 4.4.5 (debian stable), 4.6.3 (ubuntu 12.04),
and the llvm-gcc versions shipping with MacOSX.
The clang frontend versions 1.1 (on debian stable), 3.0 (OSX and ubuntu 12.04)
work correctly.
Example:
Suppose a stack contains [Â1 2 ], the top of the stack being 2.
On gcc the above expression returns 1, the first pop executed is the second
one.
On clang the same expression returns -1, the first pop executed is the first
one as should be.