Skip to content

Commit bd8bb40

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. TODO: This will be landed in the LLVM 19 time frame, not before. TODO: This patch also needs to update the release notes for LLVM 19 once we have some.
1 parent 9ebe6e2 commit bd8bb40

File tree

3 files changed

+0
-267
lines changed

3 files changed

+0
-267
lines changed

Diff for: 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_("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 19, so please migrate off of it.")
82-
char_traits
83-
{
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 {__c1 = __c2;}
92-
static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
93-
{return __c1 == __c2;}
94-
static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
95-
{return __c1 < __c2;}
96-
97-
static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
98-
int compare(const char_type* __s1, const char_type* __s2, size_t __n) {
99-
for (; __n; --__n, ++__s1, ++__s2)
100-
{
101-
if (lt(*__s1, *__s2))
102-
return -1;
103-
if (lt(*__s2, *__s1))
104-
return 1;
105-
}
106-
return 0;
107-
}
108-
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_SINCE_CXX17
109-
size_t length(const char_type* __s) {
110-
size_t __len = 0;
111-
for (; !eq(*__s, char_type(0)); ++__s)
112-
++__len;
113-
return __len;
114-
}
115-
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_SINCE_CXX17
116-
const char_type* find(const char_type* __s, size_t __n, const char_type& __a) {
117-
for (; __n; --__n)
118-
{
119-
if (eq(*__s, __a))
120-
return __s;
121-
++__s;
122-
}
123-
return nullptr;
124-
}
125-
static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
126-
char_type* move(char_type* __s1, const char_type* __s2, size_t __n) {
127-
if (__n == 0) return __s1;
128-
char_type* __r = __s1;
129-
if (__s1 < __s2)
130-
{
131-
for (; __n; --__n, ++__s1, ++__s2)
132-
assign(*__s1, *__s2);
133-
}
134-
else if (__s2 < __s1)
135-
{
136-
__s1 += __n;
137-
__s2 += __n;
138-
for (; __n; --__n)
139-
assign(*--__s1, *--__s2);
140-
}
141-
return __r;
142-
}
143-
_LIBCPP_INLINE_VISIBILITY
144-
static _LIBCPP_CONSTEXPR_SINCE_CXX20
145-
char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) {
146-
_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(!std::__is_pointer_in_range(__s1, __s1 + __n, __s2),
147-
"char_traits::copy: source and destination ranges overlap");
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-
#endif // !defined(_LIBCPP_CHAR_TRAITS_REMOVE_BASE_SPECIALIZATION)
174-
17575
// char_traits<char>
17676

17777
template <>

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

-21
This file was deleted.

Diff for: libcxx/test/libcxx/strings/char.traits/char.traits.specializations/arbitrary_char_type.pass.cpp

-146
This file was deleted.

0 commit comments

Comments
 (0)