https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121879
Bug ID: 121879
Summary: -Wchar-subscripts false positive with int8_t
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: arnaud.lb at gmail dot com
Target Milestone: ---
Created attachment 62356
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62356&action=edit
Reproducer
-Wchar-subscripts may emit unnecessary warnings for array subscripts of type
int8_t, when int8_t is a typedef name for char (like on Illumos and other
Solaris derivatives [1]).
The premise of -Wchar-subscripts is that the programmer may forget that char is
signed, therefore the warning is emitted for array subscripts of type char, or
any typedef of char.
-Wchar-subscripts does not emit warnings when signedness is explicitly
specified, as it's either safe or deliverate [2].
It would make sense to apply the same heuristic for standard signed types that
may be typedef names for char, like int8_t.
[1]
https://github.com/illumos/illumos-gate/blob/608eb926e14f4ba4736b2d59e891335f1cba9e1e/usr/src/uts/common/sys/int_types.h#L75
[2]
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/c-family/c-warn.cc;h=09517d28ba11fda9678ffbd955d985cf6605be7e;hb=HEAD#l1992