Skip to content

Commit e30a148

Browse files
committed
[libc++] Remove generic char_traits implementation
This has been deprecated and should be removed now. Reviewed By: #libc, Mordante Spies: Mordante, libcxx-commits Differential Revision: https://reviews.llvm.org/D157058
1 parent 6448d5b commit e30a148

File tree

5 files changed

+7
-279
lines changed

5 files changed

+7
-279
lines changed

libcxx/docs/ReleaseNotes/18.rst

+7-10
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,20 @@ Improvements and New Features
4747
Deprecations and Removals
4848
-------------------------
4949

50+
- The base template for ``std::char_traits`` has been removed. If you are using
51+
``std::char_traits`` with types other than ``char``, ``wchar_t``, ``char8_t``,
52+
``char16_t``, ``char32_t`` or a custom character type for which you
53+
specialized ``std::char_traits``, your code will no longer work. The Standard
54+
does not mandate that a base template is provided, and such a base template is
55+
bound to be incorrect for some types, which could previously cause unexpected
56+
behavior while going undetected.
5057

5158
Upcoming Deprecations and Removals
5259
----------------------------------
5360

5461
LLVM 18
5562
~~~~~~~
5663

57-
- The base template for ``std::char_traits`` has been marked as deprecated and
58-
will be removed in LLVM 18. If you are using ``std::char_traits`` with types
59-
other than ``char``, ``wchar_t``, ``char8_t``, ``char16_t``, ``char32_t`` or
60-
a custom character type for which you specialized ``std::char_traits``, your code
61-
will stop working when we remove the base template. The Standard does not
62-
mandate that a base template is provided, and such a base template is bound
63-
to be incorrect for some types, which could currently cause unexpected
64-
behavior while going undetected.
65-
6664
- The ``_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED`` macro will not be honored anymore in LLVM 18.
6765
Please see the updated documentation about the safe libc++ mode and in particular the ``_LIBCPP_VERBOSE_ABORT``
6866
macro for details.
@@ -79,4 +77,3 @@ ABI Affecting Changes
7977

8078
Build System Changes
8179
--------------------
82-

libcxx/include/__string/char_traits.h

-100
Original file line numberDiff line numberDiff line change
@@ -71,106 +71,6 @@ exposition-only to document what members a char_traits specialization should pro
7171
};
7272
*/
7373

74-
//
75-
// Temporary extension to provide a base template for std::char_traits.
76-
// TODO(LLVM-18): Remove this class.
77-
//
78-
template <class _CharT>
79-
struct _LIBCPP_DEPRECATED_("char_traits<T> for T not equal to char, wchar_t, char8_t, char16_t or char32_t is non-standard and is provided for a temporary period. It will be removed in LLVM 18, so please migrate off of it.")
80-
char_traits
81-
{
82-
using char_type = _CharT;
83-
using int_type = int;
84-
using off_type = streamoff;
85-
using pos_type = streampos;
86-
using state_type = mbstate_t;
87-
88-
static inline void _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI
89-
assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
90-
static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
91-
{return __c1 == __c2;}
92-
static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
93-
{return __c1 < __c2;}
94-
95-
static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
96-
int compare(const char_type* __s1, const char_type* __s2, size_t __n) {
97-
for (; __n; --__n, ++__s1, ++__s2)
98-
{
99-
if (lt(*__s1, *__s2))
100-
return -1;
101-
if (lt(*__s2, *__s1))
102-
return 1;
103-
}
104-
return 0;
105-
}
106-
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_SINCE_CXX17
107-
size_t length(const char_type* __s) {
108-
size_t __len = 0;
109-
for (; !eq(*__s, char_type(0)); ++__s)
110-
++__len;
111-
return __len;
112-
}
113-
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_SINCE_CXX17
114-
const char_type* find(const char_type* __s, size_t __n, const char_type& __a) {
115-
for (; __n; --__n)
116-
{
117-
if (eq(*__s, __a))
118-
return __s;
119-
++__s;
120-
}
121-
return nullptr;
122-
}
123-
static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
124-
char_type* move(char_type* __s1, const char_type* __s2, size_t __n) {
125-
if (__n == 0) return __s1;
126-
char_type* __r = __s1;
127-
if (__s1 < __s2)
128-
{
129-
for (; __n; --__n, ++__s1, ++__s2)
130-
assign(*__s1, *__s2);
131-
}
132-
else if (__s2 < __s1)
133-
{
134-
__s1 += __n;
135-
__s2 += __n;
136-
for (; __n; --__n)
137-
assign(*--__s1, *--__s2);
138-
}
139-
return __r;
140-
}
141-
_LIBCPP_INLINE_VISIBILITY
142-
static _LIBCPP_CONSTEXPR_SINCE_CXX20
143-
char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) {
144-
if (!__libcpp_is_constant_evaluated()) {
145-
_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(
146-
__s2 < __s1 || __s2 >= __s1 + __n, "char_traits::copy overlapped range");
147-
}
148-
char_type* __r = __s1;
149-
for (; __n; --__n, ++__s1, ++__s2)
150-
assign(*__s1, *__s2);
151-
return __r;
152-
}
153-
_LIBCPP_INLINE_VISIBILITY
154-
static _LIBCPP_CONSTEXPR_SINCE_CXX20
155-
char_type* assign(char_type* __s, size_t __n, char_type __a) {
156-
char_type* __r = __s;
157-
for (; __n; --__n, ++__s)
158-
assign(*__s, __a);
159-
return __r;
160-
}
161-
162-
static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
163-
{return eq_int_type(__c, eof()) ? ~eof() : __c;}
164-
static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
165-
{return char_type(__c);}
166-
static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
167-
{return int_type(__c);}
168-
static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
169-
{return __c1 == __c2;}
170-
static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
171-
{return int_type(EOF);}
172-
};
173-
17474
// char_traits<char>
17575

17676
template <>

libcxx/test/libcxx/strings/char.traits/char.traits.specializations/arbitrary_char_type.deprecated.verify.cpp

-21
This file was deleted.

libcxx/test/libcxx/strings/char.traits/char.traits.specializations/arbitrary_char_type.pass.cpp

-146
This file was deleted.

libcxx/test/std/utilities/format/format.formattable/concept.formattable.compile.pass.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,4 @@ void test() {
412412
test<char8_t>();
413413
test<char16_t>();
414414
test<char32_t>();
415-
416-
test<int>();
417415
}

0 commit comments

Comments
 (0)