https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105775

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So let's take the 2 functions:
int is_ascii( char cChar){return cChar >= 0 && cChar <= 127;}
int is_ascii_printable( char cChar){return cChar >= 32 && cChar <= 127;}


In C, char can be either signed or unsigned depending on the implementation.
For GCC, it depends on the target ABI (which can be changed at compile time
also with -fsigned-char and -funsigned-char too). (a side note is `char` is a
distinct type from `unsigned char` and `signed char`).

So obvious for is_ascii, GCC will warn when char defaults to signed (<= 127) or
unsigned (>= 0) and for is_ascii_printable, GCC will warn when char defaults to
signed only (<= 127).

Also this is what -Wtype-limits documentation says:
https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Warning-Options.html#index-Wtype-limits
```
Warn if a comparison is always true or always false due to the limited range of
the data type, but do not warn for constant expressions. For example, warn if
an unsigned variable is compared against zero with < or >=.
```


So yes this warning is by design.

Reply via email to