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

Reply via email to