https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99950
Bug ID: 99950 Summary: Option -Wchar-subscripts leads to wrong fixes Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: roland.illig at gmx dot de Target Milestone: --- When code calls the functions from <ctype.h> with an expression of type 'char', GCC and Clang warn: > array subscript has type char Since the function prototypes expect an 'int', inexperienced programmers cast the argument to 'int', which silences the warning: https://github.com/search?q=%22isspace+int%22&type=code More experienced programmers who heard something about 'unsigned' cast the argument to 'unsigned int', which silences the warning as well: https://github.com/search?q=%22isspace+unsigned+int%22&type=code To get these programmers to fix their code properly, GCC should provide more guidance in this area. As a quick prototype I implemented a check for these wrong "fixes" in NetBSD's lint, which results in warnings like these: warning: argument to 'function from <ctype.h>' must be cast to 'unsigned char', not to 'int' [342] The implementation is here, including a test: https://github.com/NetBSD/src/blob/fdd2c09ca474/usr.bin/xlint/lint1/ckctype.c https://github.com/NetBSD/src/blob/fdd2c09ca474/tests/usr.bin/xlint/lint1/msg_341.c https://github.com/NetBSD/src/blob/fdd2c09ca474/tests/usr.bin/xlint/lint1/msg_341.exp Maybe GCC can implement a similar check to prevent these wrong fixes in the future.