According to the documentation of -Wstrict-overflow
, level 3:
Also warn[s] about other cases where a comparison is simplified. For example: x + 1 > 1 is simplified to x > 0.
The MWE shown below throws the following warning on level 3 and up, but not below, AND if optimisation is set to -O2
and up but not below. g++ versions 9.3.0 and 10.2 exhibit this.
$ g++ -O3 -Wall -Wextra -pedantic -std=c++17 -Wstrict-overflow=3 a.cpp
a.cpp: In function ‘void std::push_heap(_RAIter, _RAIter) [with _RAIter = long unsigned int*]’: a.cpp:8:1: warning: assuming signed overflow does not occur when changing X +- C1 cmp C2 to X cmp C2 -+ C1 [-Wstrict-overflow]
MWE
#include <algorithm>
int main() {
std::size_t v[] = {0,10,3};
std::make_heap(std::begin(v),std::end(v));
std::pop_heap(std::begin(v),std::end(v));
std::push_heap(std::begin(v),std::end(v)); // <---
}
Questions
- Is this a bug in the library implementation? I don't see any signed types whatsoever.
- How can I fix this while still keeping
-Wstrict-overflow
at its max level 5?