[Bug c/50142] There is bug when swap elements of an array via chain expression.

thomas.c.zhao at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Aug 22 03:33:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50142

--- Comment #2 from ZHAO Xiaogang <thomas.c.zhao at gmail dot com> 2011-08-22 00:36:34 UTC ---
(In reply to comment #1)
> Evaluation order is undefined since there is no sequence point involved.

I don't think so.
The associativity of operator ^= is Right to Left.

I have build the code with other compiler.
gcc 3.x is OK.
Sun cc is OK.
Microsoft VC is OK.

If there isn't any array, it's also OK when use gcc4 build.
main()
{
 int a = 1, b = 2;
 a ^= b ^= a ^= b;
 printf("a=%d b=%d\n", a, b);
}

[expected result]: a=2 b=1
[actual result]: a=2 b=1

So, I guess, the defect associated with the gcc4 new feature which optimized
array access.



More information about the Gcc-bugs mailing list