https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99950
Martin Sebor changed:
What|Removed |Added
Ever confirmed|0 |1
CC||msebor at gcc dot gnu.org
See Also||https://gcc.gnu.org/bugzill
||a/show_bug.cgi?id=78155
Last reconfirmed||2021-04-07
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
--- Comment #2 from Martin Sebor ---
Adding a note after the warning suggesting to cast the argument to unsigned
char would help. Enabling the warning also when the char argument is cast to a
wider type might also be worth considering. See also pr78155 for a related
request to enable the warning for calls to the character classification
built-ins.
$ cat pr99950.c && gcc -O2 -S -Wall -Wchar-subscripts pr99950.c
extern int a[255];
int f (char c)
{
return a[c]; // -Wchar-subscripts
}
int g (char c)
{
return a[(int)c]; // same bug, no warning
}
pr99950.c: In function ‘f’:
pr99950.c:5:11: warning: array subscript has type ‘char’ [-Wchar-subscripts]
5 | return a[c]; // -Wchar-subscripts
| ^