-Wstrict-函数定义中的溢出警告

-Wstrict-overflow warning in a function definition

如何获得函数定义的 "assuming no signed overflow" 警告?

warning: assuming signed overflow does not occur when assuming that 
                           (X + c) < X is always false [-Wstrict-overflow]
unsigned int index(const ItemRequest& request)
             ^

可以找到函数体here

这似乎很奇怪,因为 return 值只是 ushort 或 uint。

因为函数定义包含了函数体。并且主体显然可以包含带符号的溢出。

您显示的部分在参数列表后既不包含 ; 也不包含 {,因此无论如何都不完整。

如果编译器在定位诊断的确切位置时出现问题,您可能会收到错误消息。当诊断是由优化器引起的,优化器正在处理已经经过相当多转换的代码时,这尤其常见。