Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-Wstrict-overflow doesn't produce any warnings where it clearly should

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.

like image 717
Michael Mahn Avatar asked Oct 15 '22 21:10

Michael Mahn


1 Answers

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.

like image 123
Ayxan Haqverdili Avatar answered Nov 15 '22 11:11

Ayxan Haqverdili