Bug 94182 - Improve -Wchar-subscripts documentation
Summary: Improve -Wchar-subscripts documentation
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: diagnostic, documentation
Depends on:
Reported: 2020-03-15 18:53 UTC by Roland Illig
Modified: 2021-04-07 07:26 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2020-05-19 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Roland Illig 2020-03-15 18:53:52 UTC
The current documentation on the -Wchar-subscripts option is nearly useless since it doesn't explain anything. I've made an attempt to summarize and explain the situation here:


The GCC documentation should at least include some pointers where to find more information about this warning, especially since there are so many ways to fix the warning incorrectly.
Comment 2 Andrew Pinski 2020-03-15 19:50:03 UTC
Considering it is documented in another place where char is signed or unsigned.  I don't know if this needs to change.


Which of signed char or unsigned char has the same range, representation, and behavior as “plain” char (C90, C90, C99 and C11 6.2.5, C99 and C11
Determined by ABI. The options -funsigned-char and -fsigned-char change the default. See Options Controlling C Dialect.

----- CUT -----
Plus -funsigned-char/-fsigned-char
Comment 3 Roland Illig 2020-03-16 03:29:15 UTC
(In reply to Andrew Pinski from comment #2)
> Considering it is documented in another place where char is signed or
> unsigned.  I don't know if this needs to change.

Given only the compiler warning about "char subscript", how could I possibly get to the documentation you linked?

> int demo(char ch, int *data) {
>     return data[ch];
> }

When I try to compile this code, I get:

> bad.c:2:16: warning: array subscript has type 'char' [-Wchar-subscripts]

From there I can look up the documentation of that command line option. But how could I get from there to your documentation? And, considering an _average_ GCC user (instead of an active GCC developer), would I have a chance of understanding the underlying problem and fixing it correctly? The GCC documentation should at least try to educate the reader a bit.
Comment 4 Eric Gallager 2020-05-19 12:35:41 UTC
retitling to clarify what exactly the issue is, and confirming