C++ : Why is this Undefined Behavior?