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: unassig...@gcc.gnu.org ReportedBy: miguel.ba...@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.