https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68816
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to David Binderman from comment #2) > (In reply to Jonathan Wakely from comment #1) > > there is no overflow in your example to detect, > > AFAIK, the if statement can only be true if overflow occurs. Right. And since you didn't call it with values that would cause an overflow (because you didn't call it at all) no overflow occurs. cppcheck is a static analyzer, so it looks at code and tries to work out what the author probably _meant_ and warns when the code does something different. GCC is a compiler, it looks at the code and works out what it *does* not what was meant. So cppcheck looks at it and says "erm, this won't work like you expect" but a compiler looks at it and says "this can never be true, the check is redundant and can be removed". So my point is that it is unsurprising to me that GCC does the latter not the former, because it isn't a static analyzer. > > I assume you're asking for the anti-pattern to be recognized and a > > "condition is always false" warning issued, rather than silently assuming > > the condition is always true and removing the check? > > Not sure what you are saying here, but I was rather hoping that > gcc could detect pointer + unsigned < same pointer and issue > a warning message about relying on undefined behaviour. Compilers assume "there is no undefined behaviour in this expression" ALL THE TIME. If they warned every time they assume addition doesn't overflow every compilation would generate hundreds of lines of diagnostics. So to warn about this particular usage would require recognising this pattern and issuing a specific warning that covers this case. I'm sure that's possible, but it would be an "enhancement request" whereas your report read more like a "missed diagnostic" bug report ("fails to detect").