This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/47288] New: Wrong operation of call by reference
- From: "malictiamo at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 14 Jan 2011 08:36:06 +0000
- Subject: [Bug c++/47288] New: Wrong operation of call by reference
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47288
Summary: Wrong operation of call by reference
Product: gcc
Version: 4.4.3
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: malictiamo@gmail.com
I find the call variables of call by reference will fail to run the follow:
#include <stdio.h>
void swap(int &a, int &b) {
a ^= b^= a ^= b;
}
int main(void) {
int a = 3, b = 5;
swap(a, b);
printf("%d %d\n", a, b);
return 0;
}
If will print "0 3", but we want to get "5 3".
if we change the swap function:
void swap(int &a, int &b) {
a ^= b;
b ^= a;
a ^= b;
}
or directly change "swap(a, b)" to "a ^= b^= a ^= b;" in main function
They will print "5 3" correctly.
This bug I find in g++ 4.1.0, 4.4.3, 4.5.1