-Wtype-limits guards a very useful, in my experience, set of warnings
including the following:

  warning: comparison of unsigned expression < 0 is always false
  warning: comparison of unsigned expression >= 0 is always true

Based on these I identified and fixed several real bugs in Wine so far
and I'd like to enable -Wtype-limits by default.  However, there is one 
caveat:  -Wtype-limits also warns about seemingly harmless code like

  bool f(unsigned i) {
    if( DEFINE_FIRST <= i || i <= DEFINE_LAST )
      return false;
    return true;
  }

in case DEFINE_FIRST evaluates to 0.

In applications like Wine there are a couple of such cases and it would 
not be good to remove the first half of the check to silence the warning 
because at a later point in time the DEFINE_FIRST might actually change,
plus the simplification is not obvious looking at the source.

So, I got a "creative" idea.  What if we disable this warning if comparing 
against 0U instead of 0?  Then we could use #define DEFINE_FIRST 0U and 
avoid the warning for cases like this, without losing real diagnostics
assuming that nobody would accidently write such code.

Ah, and we wouldn't even have to adjust any of the messages in GCC, just 
the check itself. ;-)

Thoughts?

Gerald

Reply via email to