由无效的职位数量转移

对于内置移位运算符,右操作数必须是非负的并且严格小于提升的左操作数的位宽。否则,行为未定义。

const int a = 42;
const int b = a << -1; // UB
const int c = a << 0;  // ok
const int d = a << 32; // UB if int is 32 bits or less
const int e = a >> 32; // also UB if int is 32 bits or less
const signed char f = 'x';
const int g = f << 10; // ok even if signed char is 10 bits or less;
                       // int must be at least 16 bits