Skip to content

Commit ce615e6

Browse files
committed
[libc++] Remove deprecated char_traits base template
This patch has quite a bit of history. First, it must be noted that the Standard only specifies specializations of char_traits for char, char8_t, char16_t, char32_t and wchar_t. However, before this patch, we would provide a base template that accepted anything, and as a result code like `std::basic_string<long long>` would compile but nobody knows what it really does. It basically compiles by accident. We marked the base template as deprecated in LLVM 15 or 16 and were planning on removing it in LLVM 17, which we did in e30a148. However, it turned out that the deprecation warning had never been visible in user code since Clang did not surface that warning from system headers. As a result, this caught people by surprise and we decided to reintroduce the base template in LLVM 17 in cce062d. Since then, llvm#70353 changed Clang so that such deprecation warnings would be visible from user code. Hence, this patch closes the loop and removes the deprecated specializations.
1 parent d9f1791 commit ce615e6

File tree

4 files changed

+1
-268
lines changed

4 files changed

+1
-268
lines changed

libcxx/docs/ReleaseNotes/19.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Deprecations and Removals
5656
the LLVM 19 release while also issuing a deprecation warning). See :ref:`the hardening documentation
5757
<using-hardening-modes>` for more details.
5858

59-
- TODO: The base template for ``std::char_traits`` has been removed in LLVM 19. If you are using ``std::char_traits`` with
59+
- The base template for ``std::char_traits`` has been removed in LLVM 19. If you are using ``std::char_traits`` with
6060
types other than ``char``, ``wchar_t``, ``char8_t``, ``char16_t``, ``char32_t`` or a custom character type for which you
6161
specialized ``std::char_traits``, your code will stop working. The Standard does not mandate that a base template is
6262
provided, and such a base template is bound to be incorrect for some types, which could currently cause unexpected behavior

libcxx/include/__string/char_traits.h

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

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

17777
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.

0 commit comments

Comments
 (0)