diff options
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/include/cwchar')
-rw-r--r-- | contrib/libs/cxxsupp/libcxx/include/cwchar | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/include/cwchar b/contrib/libs/cxxsupp/libcxx/include/cwchar index fb7b92b760..122af24288 100644 --- a/contrib/libs/cxxsupp/libcxx/include/cwchar +++ b/contrib/libs/cxxsupp/libcxx/include/cwchar @@ -104,7 +104,11 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len, #include <__assert> // all public C++ headers provide the assertion handler #include <__config> +#include <__type_traits/apply_cv.h> #include <__type_traits/is_constant_evaluated.h> +#include <__type_traits/is_equality_comparable.h> +#include <__type_traits/is_same.h> +#include <__type_traits/remove_cv.h> #include <cwctype> #include <wchar.h> @@ -222,21 +226,31 @@ __constexpr_wmemcmp(const wchar_t* __lhs, const wchar_t* __rhs, size_t __count) #endif } -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const wchar_t* -__constexpr_wmemchr(const wchar_t* __str, wchar_t __char, size_t __count) { -#if __has_feature(cxx_constexpr_string_builtins) - return __builtin_wmemchr(__str, __char, __count); -#else - if (!__libcpp_is_constant_evaluated()) - return std::wmemchr(__str, __char, __count); +template <class _Tp, class _Up> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __constexpr_wmemchr(_Tp* __str, _Up __value, size_t __count) { + static_assert(sizeof(_Tp) == sizeof(wchar_t)&& _LIBCPP_ALIGNOF(_Tp) >= _LIBCPP_ALIGNOF(wchar_t) && + __libcpp_is_trivially_equality_comparable<_Tp, _Tp>::value, + "Calling wmemchr on non-trivially equality comparable types is unsafe."); + +#if __has_builtin(__builtin_wmemchr) + if (!__libcpp_is_constant_evaluated()) { + wchar_t __value_buffer = 0; + __builtin_memcpy(&__value_buffer, &__value, sizeof(wchar_t)); + return reinterpret_cast<_Tp*>( + __builtin_wmemchr(reinterpret_cast<__apply_cv_t<_Tp, wchar_t>*>(__str), __value_buffer, __count)); + } +# if _LIBCPP_STD_VER >= 17 + else if constexpr (is_same_v<remove_cv_t<_Tp>, wchar_t>) + return __builtin_wmemchr(__str, __value, __count); +# endif +#endif // __has_builtin(__builtin_wmemchr) for (; __count; --__count) { - if (*__str == __char) + if (*__str == __value) return __str; ++__str; } return nullptr; -#endif } _LIBCPP_END_NAMESPACE_STD |