[libcxx-commits] [PATCH] D130946: [libc++][cuchar] Declare std::c8rtomb and std::mbrtoc8 in <cuchar> if available.

Tom Honermann via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Sep 11 13:30:18 PDT 2022


tahonermann added a comment.

This change was responsible for the failure of the sanitizer-ppc64be-linux5955 <https://lab.llvm.org/buildbot/#/builders/18/builds/5955> build. The build failed with the following error:

  /home/buildbots/ppc64be-sanitizer/sanitizer-ppc64be/build/llvm_build64/include/c++/v1/__config:1222:67: error: function-like macro '__GLIBC_USE' is not defined
  #    if _LIBCPP_GLIBC_PREREQ(2, 36) && (defined(__cpp_char8_t) || __GLIBC_USE(ISOC2X))
                                                                    ^

It seems that this CI configuration is run with a relatively ancient glibc version earlier than 2.25 (2.25 was released on 2017-02-01 and is the version that introduced the `__GLIBC_USE` macro). For the short term, I'm going to commit the following trivial change to allow the build to pass.

  diff --git a/libcxx/include/__config b/libcxx/include/__config
  index a6f3b4e88aa1..681c10306420 100644
  --- a/libcxx/include/__config
  +++ b/libcxx/include/__config
  @@ -1218,7 +1218,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
   // determining the latter depends on internal GNU libc details. If the
   // __cpp_char8_t feature test macro is not defined, then a char8_t typedef
   // will be declared as well.
  -#  if defined(_LIBCPP_GLIBC_PREREQ)
  +#  if defined(_LIBCPP_GLIBC_PREREQ) && defined(__GLIBC_USE)
   #    if _LIBCPP_GLIBC_PREREQ(2, 36) && (defined(__cpp_char8_t) || __GLIBC_USE(ISOC2X))
   #      undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
   #    endif

However, investigating this lead me to realize that the check for `__GLIBC_USE(ISOC2X)` will not work long term. Eventually, `ISOC2X` will be renamed to `ISOC23` and this check will stop working. We have a couple of options available:

1. We can remove the `__GLIBC_USE(ISOC2X))` check. This check is only relevant when builtin support for `char8_t` is disabled (when `__cpp_char8_t` is not defined). If this check is removed, then we'll have the situation that `c8rtomb()` and `mbrtoc8()` will be declared in the global namespace but not in the `std` namespace when targeting c++17 or earlier without `-fchar8_t` (or equivalent) or when targeting C++20 or later with `-fno-char8_t` (or equivalent).
2. We can assume that `ISOC2X` will be renamed to `ISOC23` and check for `__GLIBC_USE(ISOC2X) || __GLIBC_USE(ISOC23)`.

I'm inclined toward option 1 for two reasons: 1) use of glibc internal details like this is inherently fragile, and 2) There is no need for the C++ library to expose the C23 `char8_t` related declarations when builtin `char8_t` support is disabled.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130946/new/

https://reviews.llvm.org/D130946



More information about the libcxx-commits mailing list