[PATCH 1/3]: C N2653 char8_t: Language support

Tom Honermann tom@honermann.net
Mon Jun 7 02:32:01 GMT 2021

This patch implements the core language and compiler dependent library 
changes proposed in WG14 N2653 [1] for C.  The changes include:
- Use of the existing -fchar8_t and -fno-char8_t options to opt-in to
   (or opt-out of) the following changes when compiling C code.
- Change of type for UTF-8 string literals from array of char to array
   of char8_t (unsigned char).
- A new atomic_char8_t typedef.
- A new ATOMIC_CHAR8_T_LOCK_FREE macro defined in terms of a new
   predefined ATOMIC_CHAR8_T_LOCK_FREE macro.

When -fchar8_t support is enabled for non-C++ modes, the _CHAR8_T_SOURCE 
macro is predefined.  This is the mechanism proposed to glibc to opt-in 
to declarations of the char8_t typedef and c8rtomb and mbrtoc8 functions 
proposed in N2653.  See [2].

Tested on Linux x86_64.


2021-05-31  Tom Honermann  <tom@honermann.net>

          * ginclude/stdatomic.h (atomic_char8_t, ATOMIC_CHAR8_T_LOCK_FREE):
            New typedef and macro.


2021-05-31  Tom Honermann  <tom@honermann.net>

          * c-parser.c (c_parser_string_literal): Use char8_t as the type of
            CPP_UTF8STRING when char8_t support is enabled.
          * c-typeck.c (digest_init): Handle initialization of an array
            of character type by a string literal with type array of
            unsigned char.


2021-05-31  Tom Honermann  <tom@honermann.net>

          * c-cppbuiltin.c (c_cpp_builtins): Define _CHAR8_T_SOURCE if
            char8_t support is enabled in non-C++ language modes.
          * c-lex.c (lex_string): Use char8_t as the type of
            CPP_UTF8STRING when char8_t support is enabled.
          * c-opts.c (c_common_handle_option): Inform the preprocessor if
            char8_t support is enabled.
          * c.opt (fchar8_t): Enable for C language modes.


2021-05-31  Tom Honermann  <tom@honermann.net>

          * include/cpplib.h (cpp_options): Add char8.


[1]: WG14 N2653
      "char8_t: A type for UTF-8 characters and strings (Revision 1)"

[2]: C++20 P0482R6 and C2X N2653: support for char8_t, mbrtoc8(), and 
      [Patch 0]: 
      [Patch 1]: 
      [Patch 2]: 
      [Patch 3]: 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: n2653-1.patch
Type: text/x-patch
Size: 6387 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210606/9550ca09/attachment.bin>

More information about the Gcc-patches mailing list