As brought up in D39149, and post-review mails for some other commits,
the current -Wtautological-constant-compare is dumb, much like
unreachable code diagnostic.
The common complaint is that it diagnoses the comparisons between an int and
long when compiling for a 32-bit target as tautological, but not when
compiling for 64-bit targets. The underlying problem is obvious: data model.
In most cases, 64-bit target is LP64 (int is 32-bit, long and pointer are
64-bit), and the 32-bit target is ILP32 (int, long, and pointer are 32-bit).
I.e. the common pattern is: (pseudocode)
#include <limits> #include <cstdint> int main() { using T1 = long; using T2 = int; T1 r; if (r < std::numeric_limits<T2>::min()) {} if (r > std::numeric_limits<T2>::max()) {} }
The fix is simple: if the types of the values being compared are different, but
are of the same size, then we issue -Wmaybe-tautological-constant-compare
instead of -Wtautological-constant-compare.
That new diagnostic is *not* enabled by default/-Wall/-Wextra.