-Wstrict-overflow 不会在明显应该的地方产生任何警告

Mic*_*ahn 5 c++ gcc warnings g++

根据 g++ 手册页及其网站https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html,以下代码在使用 -O3 -Wstrict-overflow=5 编译时应产生警告:

#include <iostream>
#include <limits>

int
main() {
    int x{std::numeric_limits<int>::max()};
    if(x+1 > x) std::cout << "Hello";
}
Run Code Online (Sandbox Code Playgroud)

https://godbolt.org/z/57ccc33f3

它甚至输出“Hello”,表明它优化了 check(x+1 > x) 。但是我没有收到任何警告。我误解了这个警告的意思还是这是一个 gcc 错误?我在他们的错误数据库中找不到任何东西。

Ayx*_*xan 4

这绝对是 GCC 7.5和8.1之间引入的错误。请务必报告。这个特殊的例子甚至在文档中。