https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95148
--- Comment #4 from Eyal Rozenberg <eyalroz1 at gmx dot com> --- (In reply to Jonathan Wakely from comment #3) > > I should not be getting this warning, because when x is unsigned, the > > comparison is never performed, due to the short-circuit semantics of `and`. > > Those semantics only apply at runtime. But the semantics are known at compile time, and so are the argument values. > > No less > > importantly, the author of such a line in a program clearly specified > > his/her intent here with this check. > > But `x && y` doesn't prevent y being instantiated, it only prevents it being > evaluated at runtime. You mean, it only prevents a comparison of an unsigned and signed values to actually ever being carried out? Yeah :-) > > a.cpp:5:52: warning: comparison of unsigned expression < 0 is always false > > [-Wtype-limits] > > Both branches of the condition must be instantiated by the compiler, and so > this warning (which happens in the front-end, not after optimizing the AST) > gets triggered. Well, that's a bug. If you're saying that the front-end produces the warning, then delay it to a later stage, in which you can figure out whether the warning is called for. clang doesn't produce this warning. > I think to avoid this warning the front end would have to disable this > particular warning for branches that depend on a compile-time constant. I > don't know if that's currently possible in GCC. Ok, I didn't say that the solution would be easy...