gcc/libstdc++-v3/include/c_global/cuchar

109 lines
2.8 KiB
Plaintext
Raw Normal View History

// -*- C++ -*- forwarding header.
2022-01-03 10:42:10 +01:00
// Copyright (C) 2015-2022 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file include/cuchar
* This is a Standard C++ Library file. You should @c \#include this file
* in your programs, rather than any of the @a *.h implementation files.
*
* This is the C++ version of the Standard C Library header @c uchar.h,
* and its contents are (mostly) the same as that header, but are all
* contained in the namespace @c std (except for names which are defined
* as macros in C).
*/
//
// ISO C++ 14882:2011 21.8
//
#ifndef _GLIBCXX_CUCHAR
#define _GLIBCXX_CUCHAR 1
#pragma GCC system_header
#if __cplusplus < 201103L
# include <bits/c++0x_warning.h>
#else
#include <bits/c++config.h>
#include <cwchar>
libstdc++: Declare std::c8rtomb and std::mbrtoc8 if provided by the C library This patch completes implementation of the C++20 proposal P0482R6 [1] by adding declarations of std::c8rtomb() and std::mbrtoc8() in <cuchar> if provided by the C library in <uchar.h>. This patch addresses feedback provided in response to a previous patch submission [2]. Autoconf changes determine if the C library declares c8rtomb and mbrtoc8 at global scope when uchar.h is included and compiled with either -fchar8_t or -std=c++20. New _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_FCHAR8_T and _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_CXX20 configuration macros reflect the probe results. The <cuchar> header declares these functions in the std namespace only if available and the _GLIBCXX_USE_CHAR8_T configuration macro is defined (by default it is defined if the C++20 __cpp_char8_t feature test macro is defined) Patches to glibc to implement c8rtomb and mbrtoc8 have been submitted [3]. New tests validate the presence of these declarations. The tests pass trivially if the C library does not provide these functions. Otherwise they ensure that the functions are declared when <cuchar> is included and either -fchar8_t or -std=c++20 is enabled. 1]: WG21 P0482R6 "char8_t: A type for UTF-8 characters and strings (Revision 6)" https://wg21.link/p0482r6 [2]: [PATCH] C++ P0482R6 char8_t: declare std::c8rtomb and std::mbrtoc8 if provided by the C library https://gcc.gnu.org/pipermail/libstdc++/2021-June/052685.html [3]: "C++20 P0482R6 and C2X N2653" [Patch 0/3]: https://sourceware.org/pipermail/libc-alpha/2022-January/135061.html [Patch 1/3]: https://sourceware.org/pipermail/libc-alpha/2022-January/135062.html [Patch 2/3]: https://sourceware.org/pipermail/libc-alpha/2022-January/135063.html [Patch 3/3]: https://sourceware.org/pipermail/libc-alpha/2022-January/135064.html libstdc++-v3/ChangeLog: * acinclude.m4: Define config macros if uchar.h provides c8rtomb() and mbrtoc8(). * config.h.in: Regenerate. * configure: Regenerate. * include/c_compatibility/uchar.h (c8rtomb, mbrtoc8): Define. * include/c_global/cuchar (c8rtomb, mbrtoc8): Likewise. * include/c_std/cuchar (c8rtomb, mbrtoc8): Likewise. * testsuite/21_strings/headers/cuchar/functions_std_cxx20.cc: New test. * testsuite/21_strings/headers/cuchar/functions_std_fchar8_t.cc: New test.
2022-01-17 15:56:33 +01:00
#if (_GLIBCXX_USE_C11_UCHAR_CXX11 \
|| (_GLIBCXX_USE_CHAR8_T \
&& (_GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_FCHAR8_T \
|| (__cplusplus >= 202002 \
&& _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_CXX20))))
#include <uchar.h>
libstdc++: Declare std::c8rtomb and std::mbrtoc8 if provided by the C library This patch completes implementation of the C++20 proposal P0482R6 [1] by adding declarations of std::c8rtomb() and std::mbrtoc8() in <cuchar> if provided by the C library in <uchar.h>. This patch addresses feedback provided in response to a previous patch submission [2]. Autoconf changes determine if the C library declares c8rtomb and mbrtoc8 at global scope when uchar.h is included and compiled with either -fchar8_t or -std=c++20. New _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_FCHAR8_T and _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_CXX20 configuration macros reflect the probe results. The <cuchar> header declares these functions in the std namespace only if available and the _GLIBCXX_USE_CHAR8_T configuration macro is defined (by default it is defined if the C++20 __cpp_char8_t feature test macro is defined) Patches to glibc to implement c8rtomb and mbrtoc8 have been submitted [3]. New tests validate the presence of these declarations. The tests pass trivially if the C library does not provide these functions. Otherwise they ensure that the functions are declared when <cuchar> is included and either -fchar8_t or -std=c++20 is enabled. 1]: WG21 P0482R6 "char8_t: A type for UTF-8 characters and strings (Revision 6)" https://wg21.link/p0482r6 [2]: [PATCH] C++ P0482R6 char8_t: declare std::c8rtomb and std::mbrtoc8 if provided by the C library https://gcc.gnu.org/pipermail/libstdc++/2021-June/052685.html [3]: "C++20 P0482R6 and C2X N2653" [Patch 0/3]: https://sourceware.org/pipermail/libc-alpha/2022-January/135061.html [Patch 1/3]: https://sourceware.org/pipermail/libc-alpha/2022-January/135062.html [Patch 2/3]: https://sourceware.org/pipermail/libc-alpha/2022-January/135063.html [Patch 3/3]: https://sourceware.org/pipermail/libc-alpha/2022-January/135064.html libstdc++-v3/ChangeLog: * acinclude.m4: Define config macros if uchar.h provides c8rtomb() and mbrtoc8(). * config.h.in: Regenerate. * configure: Regenerate. * include/c_compatibility/uchar.h (c8rtomb, mbrtoc8): Define. * include/c_global/cuchar (c8rtomb, mbrtoc8): Likewise. * include/c_std/cuchar (c8rtomb, mbrtoc8): Likewise. * testsuite/21_strings/headers/cuchar/functions_std_cxx20.cc: New test. * testsuite/21_strings/headers/cuchar/functions_std_fchar8_t.cc: New test.
2022-01-17 15:56:33 +01:00
#endif
// Support for mbrtoc8 and c8rtomb is conditioned on support by the C library.
#if (_GLIBCXX_USE_CHAR8_T \
&& (_GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_FCHAR8_T \
|| (__cplusplus >= 202002 \
&& _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_CXX20)))
#undef mbrtoc8
#undef c8rtomb
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
using ::mbrtoc8;
using ::c8rtomb;
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
#endif // _GLIBCXX_USE_CHAR8_T
#if _GLIBCXX_USE_C11_UCHAR_CXX11
// Get rid of those macros defined in <uchar.h> in lieu of real functions.
#undef mbrtoc16
#undef c16rtomb
#undef mbrtoc32
#undef c32rtomb
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
using ::mbrtoc16;
using ::c16rtomb;
using ::mbrtoc32;
using ::c32rtomb;
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
#endif // _GLIBCXX_USE_C11_UCHAR_CXX11
#endif // C++11
#endif // _GLIBCXX_CUCHAR