https://gcc.gnu.org/g:cf91f4b20441700d394f52523378c5b93eead8e7
commit r16-8445-gcf91f4b20441700d394f52523378c5b93eead8e7 Author: Sandra Loosemore <[email protected]> Date: Fri Apr 3 15:02:22 2026 +0000 doc: Improve documentation of -Wchar-subscripts and char signedness [PR94182] The documentation of -Wchar-subscripts was missing cross-references to discussion elsewhere in the manual about how the char type may be either signed or unsigned. Besides adding the references, I've also done some improvements to those two other sections. gcc/ChangeLog PR other/94182 * doc/implement-c.texi (Characters implementation): Add cross-reference to more detailed discussion about signedness. * doc/invoke.texi (C Dialect Options): Combine -fsigned-char and -funsigned-char table entries since the following discussion applies to both. Add an anchor so other things can point at it. (Warning Options): Add cross-references to the above two places. Clarify that the warning is given regardless of whether char is signed or unsigned. Diff: --- gcc/doc/implement-c.texi | 4 ++-- gcc/doc/invoke.texi | 36 +++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/gcc/doc/implement-c.texi b/gcc/doc/implement-c.texi index 04d115e8a6f8..0439d88fcc9d 100644 --- a/gcc/doc/implement-c.texi +++ b/gcc/doc/implement-c.texi @@ -150,8 +150,8 @@ range, representation, and behavior as ``plain'' @code{char} (C90 @opindex fsigned-char @opindex funsigned-char Determined by ABI@. The options @option{-funsigned-char} and -@option{-fsigned-char} change the default. @xref{C Dialect Options, , -Options Controlling C Dialect}. +@option{-fsigned-char} change the default. +@xref{@code{char} type signedness}. @item @cite{The literal encoding, which maps of the characters of the diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 7749513bfb44..126978c8bbb5 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -2907,29 +2907,34 @@ declaration does not use either @code{signed} or @code{unsigned}. By default, such a bit-field is signed, because this is consistent: the basic integer types such as @code{int} are signed types. +@anchor{@code{char} type signedness} +@cindex @code{char} type signedness +@cindex signedness of @code{char} type @opindex fsigned-char @opindex fno-signed-char +@opindex funsigned-char +@opindex fno-unsigned-char @item -fsigned-char -Let the type @code{char} be signed, like @code{signed char}. +@itemx -funsigned-char +@option{-fsigned-char} lets the type @code{char} be signed, +like @code{signed char}, while @option{-funsigned-char} lets +the type @code{char} be unsigned, like @code{unsigned char}. -Note that this is equivalent to @option{-fno-unsigned-char}, which is +Note that @option{-fsigned-char} +is equivalent to @option{-fno-unsigned-char}, which is the negative form of @option{-funsigned-char}. Likewise, the option @option{-fno-signed-char} is equivalent to @option{-funsigned-char}. -@opindex funsigned-char -@opindex fno-unsigned-char -@item -funsigned-char -Let the type @code{char} be unsigned, like @code{unsigned char}. - -Each kind of machine has a default for what @code{char} should -be. It is either like @code{unsigned char} by default or like -@code{signed char} by default. +Each target supported by GCC has a default for what @code{char} should +be, which is typically specified in the processor-specific ABI +document for that target. It is either like @code{unsigned char} by +default or like @code{signed char} by default. Ideally, a portable program should always use @code{signed char} or @code{unsigned char} when it depends on the signedness of an object. But many programs have been written to use plain @code{char} and expect it to be signed, or expect it to be unsigned, depending on the -machines they were written for. This option, and its inverse, let you +machines they were written for. These options let you make such a program work with the opposite default. The type @code{char} is always a distinct type from each of @@ -7103,8 +7108,13 @@ Both diagnostics are also suppressed by @option{-fms-extensions}. @item -Wchar-subscripts Warn if an array subscript has type @code{char}. This is a common cause of error, as programmers often forget that this type is signed on some -machines. -This warning is enabled by @option{-Wall}. +machines. @xref{Characters implementation}, and +@ref{@code{char} type signedness}. + +This warning is enabled by @option{-Wall}. When enabled, the warning +is given regardless of whether @code{char} is unsigned by default on +the target, and it is also not affected by the @option{-fsigned-char} +or @option{-funsigned-char} options. @opindex Wno-coverage-mismatch @opindex Wcoverage-mismatch
