[Bug c/89126] New: missing -Wtype-limits for int variables
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Jan 30 23:21:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89126
Bug ID: 89126
Summary: missing -Wtype-limits for int variables
Product: gcc
Version: 9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
GCC issues -Wtype-limits warnings for relational expressions that either cannot
be true or cannot be false due to the limits of the type of one of their
operands. This seems to work except for operands of type int where GCC fails
to issue any warnings.
$ cat u.c && gcc -S -Wall -Wextra -Wpedantic u.c
int fchar (signed char x)
{
if (x <= __SCHAR_MAX__) // -Wtype-limits (good)
return 1;
if (x > __SCHAR_MAX__) // -Wtype-limits (good)
return 1;
return 0;
}
int fshrt (short x)
{
if (x <= __SHRT_MAX__) // -Wtype-limits (good)
return 1;
if (x > __SHRT_MAX__) // -Wtype-limits (good)
return 1;
return 0;
}
int fint (int x)
{
if (x <= __INT_MAX__) // missing -Wtype-limits
return 1;
if (x > __INT_MAX__) // missing -Wtype-limits
return 1;
return 0;
}
int flong (int x)
{
if (x <= __LONG_MAX__) // -Wtype-limits (good)
return 1;
if (x > __LONG_MAX__) // -Wtype-limits (good)
return 1;
return 0;
}
u.c: In function ‘fchar’:
u.c:3:9: warning: comparison is always true due to limited range of data type
[-Wtype-limits]
3 | if (x <= __SCHAR_MAX__) // -Wtype-limits (good)
| ^~
u.c:6:9: warning: comparison is always false due to limited range of data type
[-Wtype-limits]
6 | if (x > __SCHAR_MAX__) // -Wtype-limits (good)
| ^
u.c: In function ‘fshrt’:
u.c:14:9: warning: comparison is always true due to limited range of data type
[-Wtype-limits]
14 | if (x <= __SHRT_MAX__) // -Wtype-limits (good)
| ^~
u.c:17:9: warning: comparison is always false due to limited range of data type
[-Wtype-limits]
17 | if (x > __SHRT_MAX__) // -Wtype-limits (good)
| ^
u.c: In function ‘flong’:
u.c:37:9: warning: comparison is always true due to limited range of data type
[-Wtype-limits]
37 | if (x <= __LONG_MAX__) // -Wtype-limits (good)
| ^~
u.c:40:9: warning: comparison is always false due to limited range of data type
[-Wtype-limits]
40 | if (x > __LONG_MAX__) // -Wtype-limits (good)
| ^
More information about the Gcc-bugs
mailing list