This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]