[libcxx-commits] [libcxx] cf93a3d - [libc++] Remove use of internal glibc macros to determine if c8rtomb() and mbrtoc8() are present.

Tom Honermann via libcxx-commits libcxx-commits at lists.llvm.org
Thu Feb 2 10:31:38 PST 2023


Author: Tom Honermann
Date: 2023-02-02T13:31:19-05:00
New Revision: cf93a3dd512e4912181f05790992c760378c8893

URL: https://github.com/llvm/llvm-project/commit/cf93a3dd512e4912181f05790992c760378c8893
DIFF: https://github.com/llvm/llvm-project/commit/cf93a3dd512e4912181f05790992c760378c8893.diff

LOG: [libc++] Remove use of internal glibc macros to determine if c8rtomb() and mbrtoc8() are present.

When support for declaring the c8rtomb() and mbrtoc8() functions within the
std namespace was added in commit 7e7013c5d4b1b3996c8dba668c5a94bb33b2999b,
internal glibc macros were used to determine if C2X extensions are enabled.
Specifically, a check for whether `__GLIBC_USE` is defined and whether
`__GLIBC_USE(ISOC2X)` is non-0 was added. `__GLIBC_USE` is an internal
detail of the glibc implementation that may be changed or removed in the
future potentially leading to inconsistency or compilation failures.  This
change removes the use of the internal glibc macro to avoid such problems.
Unfortunately, without another mechanism to determine if C2X extensions are
enabled, this removal will result in inconsistent declarations of the
c8rtomb() and mbrtoc8() functions; when C++ char8_t support is not enabled, but
C2X extensions are, these functions will be declared in the global namespace
but not in the std namespace. This situation will improve when C23 support
is finalized and the check can be re-implemented using `__STDC_VERSION__`.

Added: 
    

Modified: 
    libcxx/include/__config
    libcxx/test/std/strings/c.strings/no_c8rtomb_mbrtoc8.verify.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__config b/libcxx/include/__config
index a4af3f176ec37..aacaa7da80dd7 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -1227,12 +1227,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
 // functions are declared by the C library.
 #  define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
 // GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if
-// __cpp_char8_t is defined or if C2X extensions are enabled. Unfortunately,
-// 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) && defined(__GLIBC_USE)
-#    if _LIBCPP_GLIBC_PREREQ(2, 36) && (defined(__cpp_char8_t) || __GLIBC_USE(ISOC2X))
+// __cpp_char8_t is defined or if C2X extensions are enabled. Determining
+// the latter depends on internal GNU libc details that are not appropriate
+// to depend on here, so any declarations present when __cpp_char8_t is not
+// defined are ignored.
+#  if defined(_LIBCPP_GLIBC_PREREQ)
+#    if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
 #      undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
 #    endif
 #  endif

diff  --git a/libcxx/test/std/strings/c.strings/no_c8rtomb_mbrtoc8.verify.cpp b/libcxx/test/std/strings/c.strings/no_c8rtomb_mbrtoc8.verify.cpp
index f39aef43c2cb8..671953e766f75 100644
--- a/libcxx/test/std/strings/c.strings/no_c8rtomb_mbrtoc8.verify.cpp
+++ b/libcxx/test/std/strings/c.strings/no_c8rtomb_mbrtoc8.verify.cpp
@@ -17,11 +17,21 @@
 
 #include <uchar.h>
 
+#include "test_macros.h"
+
+// When C++ char8_t support is not enabled, definitions of these functions that
+// match the C2X declarations may still be present in the global namespace with
+// a char8_t typedef substituted for the C++ char8_t type. If so, these are not
+// the declarations we are looking for, so don't test for them.
+#if !defined(TEST_HAS_NO_CHAR8_T)
 using U = decltype(::c8rtomb);
 using V = decltype(::mbrtoc8);
-#if defined(_LIBCPP_HAS_NO_C8RTOMB_MBRTOC8)
+#  if defined(_LIBCPP_HAS_NO_C8RTOMB_MBRTOC8)
 // expected-error at -3 {{no member named 'c8rtomb' in the global namespace}}
 // expected-error at -3 {{no member named 'mbrtoc8' in the global namespace}}
+#  else
+// expected-no-diagnostics
+#  endif
 #else
 // expected-no-diagnostics
 #endif


        


More information about the libcxx-commits mailing list