警告 C26453

算术溢出:左移负的无符号数是未定义的行为 (io.4)

注解

此警告指示代码左移了某个带符号的负整数值,该值是不可移植的并会触发实现定义的行为。

代码分析名称:LEFTSHIFT_NEGATIVE_SIGNED_NUMBER

示例

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

  // code
}

若要更正此警告,请使用以下代码:

void leftshift(int shiftCount)
{
  const auto result = ~0u << shiftCount; // OK

  // code
}

另请参阅

26450
26451
26452
26454
ES.101:对位操作使用无符号类型
ES.102:对算术使用带符号类型