Open
Description
#120222 added support to -Wtautological-compare
to diagnose comparisons like ptr + unsigned_offset < ptr
, which are always false due to undefined behavior on pointer overflow during addition.
However, most commonly this pattern appears when the result of the addition is stored in an intermediate variable first (because it will also be used later):
bool test(const char *ptr, size_t index) {
const char *end_ptr = ptr + index;
return end_ptr < ptr;
}
It would be great to diagnose these cases as well, using an analysis-based warning.
cc @AaronBallman @ldionne as we discussed this on Wednesday.