[PATCH] C++ P0482R6 char8_t: declare std::c8rtomb and std::mbrtoc8 if provided by the C library

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


This patch completes implementation of the C++20 proposal P0482R6 [1] by 
adding declarations of std::c8rtomb() and std::mbrtoc8() if provided by 
the C library.

Autoconf changes determine if the C library declares c8rtomb and mbrtoc8 
at global scope when uchar.h is included and compiled with -fchar8_t; 
_GLIBCXX_USE_UCHAR_CHAR8_T is defined if so.  The <cuchar> header 
re-declares these functions in the std namespace only if available and 
the C++20 __cpp_char8_t feature test macro is defined.

Patches to glibc to implement c8rtomb and mbrtoc8 have been submitted [2].

A new test is provided.  The test passes trivially if the C library does 
not provide these functions.  Otherwise it ensures that the functions 
are declared when <cuchar> is included and -fchar8_t support is enabled.

Tested on Linux x86_64.

libstdc++-v3/ChangeLog:

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

         * acinclude.m4 (_GLIBCXX_USE_UCHAR_CHAR8_T) Define if uchar.h
           provides c8rtomb() and mbrtoc8().
         * config.h.in: Re-generate.
         * configure: Re-generate.
         * include/c_compatibility/uchar.h: Declare ::c8rtomb and ::mbrtoc8.
         * include/c_global/cuchar: Declare std::c8rtomb and std::mbrtoc8.
         * include/c_std/cuchar: Declare std::c8rtomb and std::mbrtoc8.
         * testsuite/21_strings/headers/cuchar/functions_std.cc: New test.

Tom.

[1]: WG21 P0482R6
      "char8_t: A type for UTF-8 characters and strings (Revision 6)"
      https://wg21.link/p0482r6

[2]: C++20 P0482R6 and C2X N2653: support for char8_t, mbrtoc8(), and 
c8rtomb().
      [Patch 0]: 
https://sourceware.org/pipermail/libc-alpha/2021-June/127230.html
      [Patch 1]: 
https://sourceware.org/pipermail/libc-alpha/2021-June/127231.html
      [Patch 2]: 
https://sourceware.org/pipermail/libc-alpha/2021-June/127232.html
      [Patch 3]: 
https://sourceware.org/pipermail/libc-alpha/2021-June/127233.html



-------------- next part --------------
A non-text attachment was scrubbed...
Name: p0482r6-n2653.patch
Type: text/x-patch
Size: 6687 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20210606/7a19ac13/attachment.bin>


More information about the Libstdc++ mailing list