Warning C26453: Arithmetic overflow: Left shift of a negative signed number is undefined behavior

This warning indicates we are left shifting a negative signed integral value, which is a bad idea and triggers implementation defined behavior.

Example

void leftshift(int shiftCount)
{
  const auto result = -1 << shiftCount;  // C26453 reported here

  // code
}

To correct this warning, use the following code:

void leftshift(int shiftCount)
{
  const auto result = ((unsigned)-1) << shiftCount; // OK

  // code
}

See Also

ES.102: Use signed types for arithmetic