71-char-traits-deprecated.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. diff --git a/include/__string/char_traits.h b/include/__string/char_traits.h
  2. index 5880d3a..91b413a 100644
  3. --- a/include/__string/char_traits.h
  4. +++ b/include/__string/char_traits.h
  5. @@ -73,6 +73,106 @@ exposition-only to document what members a char_traits specialization should pro
  6. };
  7. */
  8. +//
  9. +// Temporary extension to provide a base template for std::char_traits.
  10. +// TODO(LLVM-19): Remove this class.
  11. +//
  12. +#if !defined(_LIBCPP_CHAR_TRAITS_REMOVE_BASE_SPECIALIZATION)
  13. +template <class _CharT>
  14. +struct _LIBCPP_DEPRECATED_(
  15. + "char_traits<T> for T not equal to char, wchar_t, char8_t, char16_t or char32_t is non-standard and is provided "
  16. + "for a temporary period. It will be removed in LLVM 19, so please migrate off of it.") char_traits {
  17. + using char_type = _CharT;
  18. + using int_type = int;
  19. + using off_type = streamoff;
  20. + using pos_type = streampos;
  21. + using state_type = mbstate_t;
  22. +
  23. + static inline void _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI
  24. + assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {
  25. + __c1 = __c2;
  26. + }
  27. + static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT {
  28. + return __c1 == __c2;
  29. + }
  30. + static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT {
  31. + return __c1 < __c2;
  32. + }
  33. +
  34. + static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 int
  35. + compare(const char_type* __s1, const char_type* __s2, size_t __n) {
  36. + for (; __n; --__n, ++__s1, ++__s2) {
  37. + if (lt(*__s1, *__s2))
  38. + return -1;
  39. + if (lt(*__s2, *__s1))
  40. + return 1;
  41. + }
  42. + return 0;
  43. + }
  44. + _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX17 size_t length(const char_type* __s) {
  45. + size_t __len = 0;
  46. + for (; !eq(*__s, char_type(0)); ++__s)
  47. + ++__len;
  48. + return __len;
  49. + }
  50. + _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX17 const char_type*
  51. + find(const char_type* __s, size_t __n, const char_type& __a) {
  52. + for (; __n; --__n) {
  53. + if (eq(*__s, __a))
  54. + return __s;
  55. + ++__s;
  56. + }
  57. + return nullptr;
  58. + }
  59. + static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 char_type*
  60. + move(char_type* __s1, const char_type* __s2, size_t __n) {
  61. + if (__n == 0)
  62. + return __s1;
  63. + char_type* __r = __s1;
  64. + if (__s1 < __s2) {
  65. + for (; __n; --__n, ++__s1, ++__s2)
  66. + assign(*__s1, *__s2);
  67. + } else if (__s2 < __s1) {
  68. + __s1 += __n;
  69. + __s2 += __n;
  70. + for (; __n; --__n)
  71. + assign(*--__s1, *--__s2);
  72. + }
  73. + return __r;
  74. + }
  75. + _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX20 char_type*
  76. + copy(char_type* __s1, const char_type* __s2, size_t __n) {
  77. + _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(!std::__is_pointer_in_range(__s1, __s1 + __n, __s2),
  78. + "char_traits::copy: source and destination ranges overlap");
  79. + char_type* __r = __s1;
  80. + for (; __n; --__n, ++__s1, ++__s2)
  81. + assign(*__s1, *__s2);
  82. + return __r;
  83. + }
  84. + _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX20 char_type*
  85. + assign(char_type* __s, size_t __n, char_type __a) {
  86. + char_type* __r = __s;
  87. + for (; __n; --__n, ++__s)
  88. + assign(*__s, __a);
  89. + return __r;
  90. + }
  91. +
  92. + static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT {
  93. + return eq_int_type(__c, eof()) ? ~eof() : __c;
  94. + }
  95. + static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT {
  96. + return char_type(__c);
  97. + }
  98. + static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT {
  99. + return int_type(__c);
  100. + }
  101. + static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT {
  102. + return __c1 == __c2;
  103. + }
  104. + static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT { return int_type(EOF); }
  105. +};
  106. +#endif // !defined(_LIBCPP_CHAR_TRAITS_REMOVE_BASE_SPECIALIZATION)
  107. +
  108. // char_traits<char>
  109. template <>