Skip to content

Commit 85da39d

Browse files
authored
[libc++] Remove the allocator<const T> extension (#102655)
In LLVM 19 removed the extension with an opt-in macro. This finally removes that option too and removes a few `const_cast`s where I know that they exist only to support this extension.
1 parent 6cbd96e commit 85da39d

File tree

3 files changed

+7
-106
lines changed

3 files changed

+7
-106
lines changed

libcxx/docs/ReleaseNotes/20.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Deprecations and Removals
6262
``_LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS`` macro that was used to re-enable this extension will be
6363
ignored in LLVM 20.
6464

65-
- TODO: The ``_LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST`` macro will no longer have an effect.
65+
- The ``_LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST`` macro no longer has any effect. ``std::allocator<const T>`` is not supported as an extension anymore, please migrate any code that uses e.g. ``std::vector<const T>`` to be standards conforming.
6666

6767
Upcoming Deprecations and Removals
6868
----------------------------------

libcxx/include/__memory/allocator.h

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,6 @@ class _LIBCPP_TEMPLATE_VIS allocator<void> {
4747
typedef allocator<_Up> other;
4848
};
4949
};
50-
51-
// TODO(LLVM 20): Remove the escape hatch
52-
# ifdef _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST
53-
template <>
54-
class _LIBCPP_TEMPLATE_VIS allocator<const void> {
55-
public:
56-
_LIBCPP_DEPRECATED_IN_CXX17 typedef const void* pointer;
57-
_LIBCPP_DEPRECATED_IN_CXX17 typedef const void* const_pointer;
58-
_LIBCPP_DEPRECATED_IN_CXX17 typedef const void value_type;
59-
60-
template <class _Up>
61-
struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {
62-
typedef allocator<_Up> other;
63-
};
64-
};
65-
# endif // _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST
6650
#endif // _LIBCPP_STD_VER <= 17
6751

6852
// This class provides a non-trivial default constructor to the class that derives from it
@@ -171,85 +155,6 @@ class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if<!is_void<_Tp>::v
171155
#endif
172156
};
173157

174-
// TODO(LLVM 20): Remove the escape hatch
175-
#ifdef _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST
176-
template <class _Tp>
177-
class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
178-
: private __non_trivial_if<!is_void<_Tp>::value, allocator<const _Tp> > {
179-
static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types");
180-
181-
public:
182-
typedef size_t size_type;
183-
typedef ptrdiff_t difference_type;
184-
typedef const _Tp value_type;
185-
typedef true_type propagate_on_container_move_assignment;
186-
# if _LIBCPP_STD_VER <= 23 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_ALLOCATOR_MEMBERS)
187-
_LIBCPP_DEPRECATED_IN_CXX23 typedef true_type is_always_equal;
188-
# endif
189-
190-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator() _NOEXCEPT = default;
191-
192-
template <class _Up>
193-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator(const allocator<_Up>&) _NOEXCEPT {}
194-
195-
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const _Tp* allocate(size_t __n) {
196-
if (__n > allocator_traits<allocator>::max_size(*this))
197-
__throw_bad_array_new_length();
198-
if (__libcpp_is_constant_evaluated()) {
199-
return static_cast<const _Tp*>(::operator new(__n * sizeof(_Tp)));
200-
} else {
201-
return static_cast<const _Tp*>(std::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
202-
}
203-
}
204-
205-
# if _LIBCPP_STD_VER >= 23
206-
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr allocation_result<const _Tp*> allocate_at_least(size_t __n) {
207-
return {allocate(__n), __n};
208-
}
209-
# endif
210-
211-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void deallocate(const _Tp* __p, size_t __n) {
212-
if (__libcpp_is_constant_evaluated()) {
213-
::operator delete(const_cast<_Tp*>(__p));
214-
} else {
215-
std::__libcpp_deallocate((void*)const_cast<_Tp*>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
216-
}
217-
}
218-
219-
// C++20 Removed members
220-
# if _LIBCPP_STD_VER <= 17
221-
_LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* pointer;
222-
_LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer;
223-
_LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& reference;
224-
_LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& const_reference;
225-
226-
template <class _Up>
227-
struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {
228-
typedef allocator<_Up> other;
229-
};
230-
231-
_LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI const_pointer address(const_reference __x) const _NOEXCEPT {
232-
return std::addressof(__x);
233-
}
234-
235-
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 const _Tp* allocate(size_t __n, const void*) {
236-
return allocate(__n);
237-
}
238-
239-
_LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
240-
return size_type(~0) / sizeof(_Tp);
241-
}
242-
243-
template <class _Up, class... _Args>
244-
_LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI void construct(_Up* __p, _Args&&... __args) {
245-
::new ((void*)__p) _Up(std::forward<_Args>(__args)...);
246-
}
247-
248-
_LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI void destroy(pointer __p) { __p->~_Tp(); }
249-
# endif
250-
};
251-
#endif // _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST
252-
253158
template <class _Tp, class _Up>
254159
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
255160
operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {

libcxx/include/__memory/uninitialized_algorithms.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -562,17 +562,13 @@ struct __allocator_has_trivial_copy_construct<allocator<_Type>, _Type> : true_ty
562562

563563
template <class _Alloc,
564564
class _In,
565-
class _RawTypeIn = __remove_const_t<_In>,
566565
class _Out,
567-
__enable_if_t<
568-
// using _RawTypeIn because of the allocator<T const> extension
569-
is_trivially_copy_constructible<_RawTypeIn>::value && is_trivially_copy_assignable<_RawTypeIn>::value &&
570-
is_same<__remove_const_t<_In>, __remove_const_t<_Out> >::value &&
571-
__allocator_has_trivial_copy_construct<_Alloc, _RawTypeIn>::value,
572-
int> = 0>
566+
__enable_if_t<is_trivially_copy_constructible<_In>::value && is_trivially_copy_assignable<_In>::value &&
567+
is_same<__remove_const_t<_In>, __remove_const_t<_Out> >::value &&
568+
__allocator_has_trivial_copy_construct<_Alloc, _In>::value,
569+
int> = 0>
573570
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Out*
574571
__uninitialized_allocator_copy_impl(_Alloc&, _In* __first1, _In* __last1, _Out* __first2) {
575-
// TODO: Remove the const_cast once we drop support for std::allocator<T const>
576572
if (__libcpp_is_constant_evaluated()) {
577573
while (__first1 != __last1) {
578574
std::__construct_at(std::__to_address(__first2), *__first1);
@@ -581,7 +577,7 @@ __uninitialized_allocator_copy_impl(_Alloc&, _In* __first1, _In* __last1, _Out*
581577
}
582578
return __first2;
583579
} else {
584-
return std::copy(__first1, __last1, const_cast<_RawTypeIn*>(__first2));
580+
return std::copy(__first1, __last1, __first2);
585581
}
586582
}
587583

@@ -642,7 +638,7 @@ __uninitialized_allocator_relocate(_Alloc& __alloc, _Tp* __first, _Tp* __last, _
642638
__guard.__complete();
643639
std::__allocator_destroy(__alloc, __first, __last);
644640
} else {
645-
__builtin_memcpy(const_cast<__remove_const_t<_Tp>*>(__result), __first, sizeof(_Tp) * (__last - __first));
641+
__builtin_memcpy(__result, __first, sizeof(_Tp) * (__last - __first));
646642
}
647643
}
648644

0 commit comments

Comments
 (0)