SummaryHarmonizing left-shift with C++14
It is not uncommon to see code such as:
signed someint_t min_value = 1 << (CHAR_BIT * sizeof(someint_t));
However, left-shifting a one bit into the sign bit is undefined behavior, despite the fact that the majority of (twos-complement) architectures handle it properly.
Suggested Technical Corrigendum
The result ofC++ addressed this in C++14 with DR1457 with identical wording modifications.
E1 << E2is
E2bit positions; vacated bits are filled with zeros. If
E1has an unsigned type, the value of the result is
E1 x 2E2, reduced modulo one more than the maximum value representable in the result type. If
E1has a signed type and nonnegative value, and
E1 x 2E2is representable in the result type, then that is the resulting value; otherwise, the behavior is undefined.