diff --git a/libcxx/include/__config b/libcxx/include/__config index 77a71b6cf1cae..2ce0c4448aae9 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -1021,14 +1021,27 @@ typedef __char32_t char32_t; // 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. +// +// picolibc 1.8.9 and newer declare the two functions unconditionally. +// +// Apple C library, Microsoft C Runtime, AIX C library and FreeBSD libc do not +// yet support these functions. # if defined(_LIBCPP_GLIBC_PREREQ) -# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t) +# if defined(__cpp_char8_t) && _LIBCPP_GLIBC_PREREQ(2, 36) # define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1 # else # define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0 # endif -# else +# elif defined(_LIBCPP_PICOLIBC_PREREQ) +# if _LIBCPP_PICOLIBC_PREREQ(1, 8, 9) +# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1 +# else +# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0 +# endif +# elif defined(__APPLE__) || defined(_MSC_VER) || defined(_LIBCPP_UCRT) || defined(_AIX) || defined(__FreeBSD__) # define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0 +# else +# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1 # endif // There are a handful of public standard library types that are intended to diff --git a/libcxx/include/__configuration/platform.h b/libcxx/include/__configuration/platform.h index f3c199dee172b..a448ca82b2935 100644 --- a/libcxx/include/__configuration/platform.h +++ b/libcxx/include/__configuration/platform.h @@ -47,6 +47,17 @@ // user code. Move code paths that need _NEWLIB_VERSION to another customization mechanism. #if __has_include() # include +# define _LIBCPP_PICOLIBC_VERSION_INT(maj, min, patch) (maj * 10000 + min * 100 + patch) +# define _LIBCPP_PICOLIBC_PREREQ(maj, min, patch) \ + _LIBCPP_PICOLIBC_VERSION_INT(__PICOLIBC__, __PICOLIBC_MINOR__, __PICOLIBC_PATCHLEVEL__) >= \ + _LIBCPP_PICOLIBC_VERSION_INT(maj, min, patch) +#endif + +#if __has_include() +# include +# if defined(_UCRT) +# define _LIBCPP_UCRT +# endif #endif #ifndef __BYTE_ORDER__