是V610“未定义的行为”是一个错误错误?

时间:2019-06-19 14:08:07

标签: pvs-studio

pvs-studio是否识别出错误?

pvs-studio v。7.02.32296,Windows 7x64

#include <stdio.h>
#include <stdint.h>

int main() {
  uint32_t a = 0xFFFFFFFF;
  uint32_t b = 0x00000000;
  uint64_t x = ((static_cast<uint64_t>(a) << 32) | static_cast<uint64_t>(b));

  printf("x: %016lX\n", x);
  return 0;
}

为什么pvs studio会注意到:

C:\projects\test\test.cpp (36): error V610: [CWE-758] Undefined behavior. Check the shift operator '<<'. The right operand '32' is greater than or equal to the length in bits of the promoted left operand

如果x是uint64_t?

0 个答案:

没有答案