The following code works and it shouldn't.  It only works with passing 2
parameters from what I tested.  If I try swap(int *x) or swap(int *x, int *y,
int *z), it gives an error as expected.  But with 2 parameters it compiles and
runs.  

void swap(int *x, int *y)
{
        int temp;
        temp = *x;
        *x = *y;
        *y = temp;
}

int main()
{
        int x = 10;
        int y = 20;
        std::cout << x << " " << y << endl;
        swap(x,y);  //this compiles, runs and swaps...  it shouldn't
        std::cout << x << " " << y << endl;
}


-- 
           Summary: Function pass by reference problem, accepts parameters
                    (int, int) to an (int*, int*) function.
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: eakrohn at cs dot uiowa dot edu


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

Reply via email to