[Bug libfortran/95177] error: array subscript has type char

roland.illig at gmx dot de gcc-bugzilla@gcc.gnu.org
Wed May 20 06:19:59 GMT 2020


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

--- Comment #10 from Roland Illig <roland.illig at gmx dot de> ---
(In reply to Steve Kargl from comment #9)
> That could work.  I'm still trying to understand how an
> option names -Werror=char-subscripts could trigger an
> error.  There are no subscripts.

The C standard allows every library function to also be defined as a macro.
This also applies to the functions from <ctype.h>.

The typical implementation of the <ctype.h> functions is:

extern int __ctype_classes[1 /* for EOF */ + UCHAR_MAX];

int isalpha(int ch) {
  return (__ctype_classes + 1)[ch] & 0x0008;
}

The corresponding macro is defined like this:

#define isalpha(ch) ((__ctype_classes + 1)[(ch)] & 0x0008)

That's where the subscript comes from.

The macro has no implicit type conversion (at least on NetBSD; the GNU libc may
differ) and thus produces the warning.


More information about the Gcc-bugs mailing list