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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With