Q:

Storing references in object yielding wierd results

A bit of context: I was testing the compiler's optimizations when using references (they are very good at it BTW).
At some point I passed two objects by reference to a struct constructor... and things got wierd. I can see changes made to one of the objects outside the struct, but not the other.
I came with a minimal working example of what I mean by that:
//TwoInts has two references to int
//For whatever reason I can only see outside changes
//done to the int pointed by ref1 !
struct TwoInts{
    int& ref1,ref2;
    TwoInts(int& r1,int& r2):ref1(r1),ref2(r2){}
};

int foo(int select){
    int a=0,b=0;
    TwoInts two(a,b);

    switch(select){
        case 1:
            a=1; //This line changes the output
            return two.ref1; //Returns 1, ok
            break;
        case 2:
            b=2; //This line DOESN'T change the output
            return two.ref2; //Returns zero!
            break;
    }
}

Generated assembler with g++ v5.4 using -O2
foo(int):
  cmp edi, 1
  je .L3
  cmp edi, 2
  jne .L9
  xor eax, eax
  ret
.L9:
  rep ret
.L3:
  mov eax, 1
  ret

Live example here
-If I pass 1 to foo the code jumps to .L3 and returns 1, reflecting the change made to a;
-But if I pass 2 to foo the code jumps to .L9 and returns 0, ignoring the change made to b.
I have no clue why this is happening. Any thoughts on that?
[EDIT]
It is really easy to run in circles when you are working alone. Indeed, the type of ref2 is just int, not int&. Thanks for the replies!

A:

The way you have declared ref1 and ref2 makes ref1 an int reference but ref2 an int value.  
The correct declaration to have two references in your struct should be: 
int &ref1, &ref2;

