Reputation: 797
According to the g++ man-page and their website https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html , the following code should produce a warning when compiled with -O3 -Wstrict-overflow=5 :
#include <iostream>
#include <limits>
int
main() {
int x{std::numeric_limits<int>::max()};
if(x+1 > x) std::cout << "Hello";
}
https://godbolt.org/z/57ccc33f3
It even outputs "Hello", showing that it optimized the check(x+1 > x) away. However I get no warning. Do I misunderstand what this warning is meant to do or is this a gcc bug? I couldn't find anything in their bug database.
Upvotes: 7
Views: 414
Reputation: 29985
This is definitely a bug introduced between GCC 7.5 and 8.1. Be sure to report it. This particular example is even in the docs.
Upvotes: 4