This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/50142] There is bug when swap elements of an array via chain expression.
- From: "thomas.c.zhao at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 22 Aug 2011 00:36:34 +0000
- Subject: [Bug c/50142] There is bug when swap elements of an array via chain expression.
- Auto-submitted: auto-generated
- References: <bug-50142-4@http.gcc.gnu.org/bugzilla/>
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.