Skip to content

[libc++] Remove the allocator<const T> extension #96319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 25, 2024

Conversation

ldionne
Copy link
Member

@ldionne ldionne commented Jun 21, 2024

This effort has quite a history:

  • This was first attempted in 2022 via bed3240, which broke std::shared_ptr and caused the change to be reverted in 9138666.
  • We then re-attempted landing the change in 276ca87 after fixing std::shared_ptr, but reports were made that this broke code en masse within Google. This led to the patch being reverted again in a54d028 with the goal to land this again with a migration path for vendors.

This patch re-lands the removal while providing a migration path for vendors by providing the _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST macro. This macro will be honored for the LLVM 19 release and will be removed after that, at which point allocator will be removed unconditionally.

Fixes #73665

This effort has quite a history:
- This was first attempted in 2022 via bed3240, which broke
  std::shared_ptr<T const> and caused the change to be reverted
  in 9138666.
- We then re-attempted landing the change in 276ca87 after fixing
  std::shared_ptr, but reports were made that this broke code en masse
  within Google. This led to the patch being reverted again in a54d028
  with the goal to land this again with a migration path for vendors.

This patch re-lands the removal while providing a migration path for
vendors by providing the `_LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST` macro.
This macro will be honored for the LLVM 19 release and will be removed
after that, at which point allocator<const T> will be removed unconditionally.

Fixes llvm#73665
@ldionne ldionne added this to the LLVM 19.X Release milestone Jun 21, 2024
@ldionne ldionne requested a review from a team as a code owner June 21, 2024 15:20
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jun 21, 2024
@ldionne
Copy link
Member Author

ldionne commented Jun 21, 2024

Pinging @llvm/libcxx-vendors for awareness.

@llvmbot
Copy link
Member

llvmbot commented Jun 21, 2024

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

Changes

This effort has quite a history:

  • This was first attempted in 2022 via bed3240, which broke std::shared_ptr<T const> and caused the change to be reverted in 9138666.
  • We then re-attempted landing the change in 276ca87 after fixing std::shared_ptr, but reports were made that this broke code en masse within Google. This led to the patch being reverted again in a54d028 with the goal to land this again with a migration path for vendors.

This patch re-lands the removal while providing a migration path for vendors by providing the _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST macro. This macro will be honored for the LLVM 19 release and will be removed after that, at which point allocator<const T> will be removed unconditionally.

Fixes #73665


Patch is 20.92 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/96319.diff

17 Files Affected:

  • (modified) libcxx/docs/ReleaseNotes/19.rst (+6)
  • (modified) libcxx/include/__memory/allocator.h (+15-13)
  • (modified) libcxx/include/__memory/shared_ptr.h (+6-6)
  • (removed) libcxx/test/libcxx/containers/sequences/vector/const_T.compile.pass.cpp (-18)
  • (removed) libcxx/test/libcxx/containers/sequences/vector/const_value_type.pass.cpp (-25)
  • (modified) libcxx/test/libcxx/diagnostics/memory.nodiscard.verify.cpp (-12)
  • (modified) libcxx/test/libcxx/memory/allocator_void.trivial.compile.pass.cpp (+1-9)
  • (modified) libcxx/test/libcxx/memory/allocator_volatile.verify.cpp (+3-3)
  • (modified) libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp (-6)
  • (modified) libcxx/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp (+2-2)
  • (modified) libcxx/test/std/utilities/memory/default.allocator/allocator.dtor.pass.cpp (-6)
  • (modified) libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.constexpr.size.verify.cpp (-1)
  • (modified) libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp (-1)
  • (modified) libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx17.verify.cpp (-7)
  • (modified) libcxx/test/std/utilities/memory/default.allocator/allocator_types.pass.cpp (-3)
  • (modified) libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx20.verify.cpp (+1-1)
  • (modified) libcxx/test/std/utilities/memory/specialized.algorithms/specialized.construct/construct_at.pass.cpp (+2-2)
diff --git a/libcxx/docs/ReleaseNotes/19.rst b/libcxx/docs/ReleaseNotes/19.rst
index 71de10abb6eaa..31a2cacc2bf70 100644
--- a/libcxx/docs/ReleaseNotes/19.rst
+++ b/libcxx/docs/ReleaseNotes/19.rst
@@ -121,6 +121,12 @@ Deprecations and Removals
 - The ``_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS`` macro has been removed and is not honored anymore. Additional
   warnings provided by libc++ as a matter of QoI will now be provided unconditionally.
 
+- libc++ no longer supports ``std::allocator<const T>`` and containers of ``const``-qualified element type, such
+  as ``std::vector<const T>`` and ``std::list<const T>``. This used to be supported as an undocumented extension.
+  If you were using ``std::vector<const T>``, replace it with ``std::vector<T>`` instead. The
+  ``_LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST`` macro can be defined to temporarily re-enable this extension as
+  folks transition their code. This macro will be honored for one released and ignored starting in LLVM 20.
+
 
 Upcoming Deprecations and Removals
 ----------------------------------
diff --git a/libcxx/include/__memory/allocator.h b/libcxx/include/__memory/allocator.h
index 215d3832f9ef3..2d8624e771bce 100644
--- a/libcxx/include/__memory/allocator.h
+++ b/libcxx/include/__memory/allocator.h
@@ -14,6 +14,7 @@
 #include <__memory/addressof.h>
 #include <__memory/allocate_at_least.h>
 #include <__memory/allocator_traits.h>
+#include <__type_traits/is_const.h>
 #include <__type_traits/is_constant_evaluated.h>
 #include <__type_traits/is_same.h>
 #include <__type_traits/is_void.h>
@@ -36,8 +37,6 @@ class allocator;
 // Specializing allocator<void> is deprecated, but not using it.
 template <>
 class _LIBCPP_TEMPLATE_VIS allocator<void> {
-#  if _LIBCPP_STD_VER <= 17
-
 public:
   _LIBCPP_DEPRECATED_IN_CXX17 typedef void* pointer;
   _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* const_pointer;
@@ -47,13 +46,12 @@ class _LIBCPP_TEMPLATE_VIS allocator<void> {
   struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {
     typedef allocator<_Up> other;
   };
-#  endif
 };
 
+// TODO(LLVM 20): Remove the escape hatch
+#  ifdef _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST
 template <>
 class _LIBCPP_TEMPLATE_VIS allocator<const void> {
-#  if _LIBCPP_STD_VER <= 17
-
 public:
   _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* pointer;
   _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* const_pointer;
@@ -63,9 +61,9 @@ class _LIBCPP_TEMPLATE_VIS allocator<const void> {
   struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {
     typedef allocator<_Up> other;
   };
-#  endif
 };
-#endif
+#  endif // _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST
+#endif   // _LIBCPP_STD_VER <= 17
 
 // This class provides a non-trivial default constructor to the class that derives from it
 // if the condition is satisfied.
@@ -94,6 +92,7 @@ struct __non_trivial_if<true, _Unique> {
 
 template <class _Tp>
 class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if<!is_void<_Tp>::value, allocator<_Tp> > {
+  static_assert(!is_const<_Tp>::value, "std::allocator does not support const types");
   static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types");
 
 public:
@@ -170,6 +169,8 @@ class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if<!is_void<_Tp>::v
 #endif
 };
 
+// TODO(LLVM 20): Remove the escape hatch
+#ifdef _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST
 template <class _Tp>
 class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
     : private __non_trivial_if<!is_void<_Tp>::value, allocator<const _Tp> > {
@@ -180,9 +181,9 @@ class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
   typedef ptrdiff_t difference_type;
   typedef const _Tp value_type;
   typedef true_type propagate_on_container_move_assignment;
-#if _LIBCPP_STD_VER <= 23 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_ALLOCATOR_MEMBERS)
+#  if _LIBCPP_STD_VER <= 23 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_ALLOCATOR_MEMBERS)
   _LIBCPP_DEPRECATED_IN_CXX23 typedef true_type is_always_equal;
-#endif
+#  endif
 
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator() _NOEXCEPT = default;
 
@@ -199,11 +200,11 @@ class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
     }
   }
 
-#if _LIBCPP_STD_VER >= 23
+#  if _LIBCPP_STD_VER >= 23
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr allocation_result<const _Tp*> allocate_at_least(size_t __n) {
     return {allocate(__n), __n};
   }
-#endif
+#  endif
 
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void deallocate(const _Tp* __p, size_t __n) {
     if (__libcpp_is_constant_evaluated()) {
@@ -214,7 +215,7 @@ class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
   }
 
   // C++20 Removed members
-#if _LIBCPP_STD_VER <= 17
+#  if _LIBCPP_STD_VER <= 17
   _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* pointer;
   _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer;
   _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& reference;
@@ -243,8 +244,9 @@ class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
   }
 
   _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI void destroy(pointer __p) { __p->~_Tp(); }
-#endif
+#  endif
 };
+#endif // _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST
 
 template <class _Tp, class _Up>
 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
diff --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h
index 358a851958db1..a7917ae3952bf 100644
--- a/libcxx/include/__memory/shared_ptr.h
+++ b/libcxx/include/__memory/shared_ptr.h
@@ -259,7 +259,7 @@ struct __shared_ptr_emplace : __shared_weak_count {
             class _Allocator                                                                          = _Alloc,
             __enable_if_t<!is_same<typename _Allocator::value_type, __for_overwrite_tag>::value, int> = 0>
   _LIBCPP_HIDE_FROM_ABI explicit __shared_ptr_emplace(_Alloc __a, _Args&&... __args) : __storage_(std::move(__a)) {
-    using _TpAlloc = typename __allocator_traits_rebind<_Alloc, _Tp>::type;
+    using _TpAlloc = typename __allocator_traits_rebind<_Alloc, __remove_cv_t<_Tp> >::type;
     _TpAlloc __tmp(*__get_alloc());
     allocator_traits<_TpAlloc>::construct(__tmp, __get_elem(), std::forward<_Args>(__args)...);
   }
@@ -278,7 +278,7 @@ struct __shared_ptr_emplace : __shared_weak_count {
   template <class _Allocator                                                                          = _Alloc,
             __enable_if_t<!is_same<typename _Allocator::value_type, __for_overwrite_tag>::value, int> = 0>
   _LIBCPP_HIDE_FROM_ABI void __on_zero_shared_impl() _NOEXCEPT {
-    using _TpAlloc = typename __allocator_traits_rebind<_Allocator, _Tp>::type;
+    using _TpAlloc = typename __allocator_traits_rebind<_Allocator, __remove_cv_t<_Tp> >::type;
     _TpAlloc __tmp(*__get_alloc());
     allocator_traits<_TpAlloc>::destroy(__tmp, __get_elem());
   }
@@ -598,7 +598,7 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr {
 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
   template <class _Yp, __enable_if_t<is_convertible<_Yp*, element_type*>::value, int> = 0>
   _LIBCPP_HIDE_FROM_ABI shared_ptr(auto_ptr<_Yp>&& __r) : __ptr_(__r.get()) {
-    typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
+    typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<__remove_cv_t<_Yp> > > _CntrlBlk;
     __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
     __enable_weak_this(__r.get(), __r.get());
     __r.release();
@@ -776,7 +776,7 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr {
 private:
   template <class _Yp, bool = is_function<_Yp>::value>
   struct __shared_ptr_default_allocator {
-    typedef allocator<_Yp> type;
+    typedef allocator<__remove_cv_t<_Yp> > type;
   };
 
   template <class _Yp>
@@ -834,7 +834,7 @@ _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> allocate_shared(const _Alloc& __a, _Args&&
 
 template <class _Tp, class... _Args, __enable_if_t<!is_array<_Tp>::value, int> = 0>
 _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> make_shared(_Args&&... __args) {
-  return std::allocate_shared<_Tp>(allocator<_Tp>(), std::forward<_Args>(__args)...);
+  return std::allocate_shared<_Tp>(allocator<__remove_cv_t<_Tp> >(), std::forward<_Args>(__args)...);
 }
 
 #if _LIBCPP_STD_VER >= 20
@@ -848,7 +848,7 @@ _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> allocate_shared_for_overwrite(const _Alloc
 
 template <class _Tp, __enable_if_t<!is_array<_Tp>::value, int> = 0>
 _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> make_shared_for_overwrite() {
-  return std::allocate_shared_for_overwrite<_Tp>(allocator<_Tp>());
+  return std::allocate_shared_for_overwrite<_Tp>(allocator<__remove_cv_t<_Tp>>());
 }
 
 #endif // _LIBCPP_STD_VER >= 20
diff --git a/libcxx/test/libcxx/containers/sequences/vector/const_T.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/vector/const_T.compile.pass.cpp
deleted file mode 100644
index 62fff96ac5abe..0000000000000
--- a/libcxx/test/libcxx/containers/sequences/vector/const_T.compile.pass.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// Make sure that `vector<const T>` works
-
-#include <vector>
-
-void test() {
-  std::vector<const int> v;
-  v.emplace_back(1);
-  v.push_back(1);
-  v.resize(3);
-}
diff --git a/libcxx/test/libcxx/containers/sequences/vector/const_value_type.pass.cpp b/libcxx/test/libcxx/containers/sequences/vector/const_value_type.pass.cpp
deleted file mode 100644
index 1ad505a76d3fb..0000000000000
--- a/libcxx/test/libcxx/containers/sequences/vector/const_value_type.pass.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++03
-
-// <vector>
-
-// vector<const int> v;  // an extension
-
-#include <vector>
-#include <type_traits>
-
-#include "test_macros.h"
-
-int main(int, char**)
-{
-    std::vector<const int> v = {1, 2, 3};
-
-  return 0;
-}
diff --git a/libcxx/test/libcxx/diagnostics/memory.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/memory.nodiscard.verify.cpp
index 210d269c9fa23..646569e3d573a 100644
--- a/libcxx/test/libcxx/diagnostics/memory.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/memory.nodiscard.verify.cpp
@@ -39,15 +39,3 @@ void test_allocator() {
   allocator.allocate_at_least(1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
 #endif
 }
-
-void test_const_allocator() {
-  std::allocator<const int> allocator;
-  allocator.allocate(1);          // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-
-#if TEST_STD_VER <= 17
-  allocator.allocate(1, nullptr); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-#endif
-#if TEST_STD_VER >= 23
-  allocator.allocate_at_least(1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-#endif
-}
diff --git a/libcxx/test/libcxx/memory/allocator_void.trivial.compile.pass.cpp b/libcxx/test/libcxx/memory/allocator_void.trivial.compile.pass.cpp
index f9d67c065de85..69a4b8943caa6 100644
--- a/libcxx/test/libcxx/memory/allocator_void.trivial.compile.pass.cpp
+++ b/libcxx/test/libcxx/memory/allocator_void.trivial.compile.pass.cpp
@@ -17,18 +17,10 @@
 #include <type_traits>
 
 typedef std::allocator<void> A1;
-typedef std::allocator<void const> A2;
-struct A3 : std::allocator<void> { };
-struct A4 : std::allocator<void const> { };
+struct A2 : std::allocator<void> { };
 
 static_assert(std::is_trivially_default_constructible<A1>::value, "");
 static_assert(std::is_trivial<A1>::value, "");
 
 static_assert(std::is_trivially_default_constructible<A2>::value, "");
 static_assert(std::is_trivial<A2>::value, "");
-
-static_assert(std::is_trivially_default_constructible<A3>::value, "");
-static_assert(std::is_trivial<A3>::value, "");
-
-static_assert(std::is_trivially_default_constructible<A4>::value, "");
-static_assert(std::is_trivial<A4>::value, "");
diff --git a/libcxx/test/libcxx/memory/allocator_volatile.verify.cpp b/libcxx/test/libcxx/memory/allocator_volatile.verify.cpp
index 6fa7fe1b1aeda..53fdc08e7a024 100644
--- a/libcxx/test/libcxx/memory/allocator_volatile.verify.cpp
+++ b/libcxx/test/libcxx/memory/allocator_volatile.verify.cpp
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-// http://wg21.link/LWG2447 gives implementors freedom to reject volatile types in `std::allocator`.
+// http://wg21.link/LWG2447 gives implementors freedom to reject const or volatile types in `std::allocator`.
 
 #include <memory>
 
-std::allocator<volatile int> A1; // expected-error@*:* {{std::allocator does not support volatile types}}
-std::allocator<const volatile int> A2; // expected-error@*:* {{std::allocator does not support volatile types}}
+std::allocator<const int> A1; // expected-error@*:* {{std::allocator does not support const types}}
+std::allocator<volatile int> A2; // expected-error@*:* {{std::allocator does not support volatile types}}
diff --git a/libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp b/libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp
index ee1405f1f889d..6a31fb90e4da2 100644
--- a/libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp
+++ b/libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp
@@ -205,9 +205,6 @@ void test()
     test_not_const<std::array<      volatile int, 1>>();
     test_false    <std::array<const volatile int, 1>>();
     test_true     <std::deque<               int>>();
-#ifdef _LIBCPP_VERSION
-    test_true     <std::deque<const          int>>();
-#endif // _LIBCPP_VERSION
     test_true     <std::forward_list<int>>();
     test_true     <std::list<int>>();
     test_true     <std::vector<int>>();
@@ -226,9 +223,6 @@ void test()
 
     // Container adaptors
     test_true     <std::stack<               int>>();
-#ifdef _LIBCPP_VERSION
-    test_true     <std::stack<const          int>>();
-#endif // _LIBCPP_VERSION
     test_true     <std::queue<int>>();
     test_true     <std::priority_queue<int>>();
 
diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp
index 6e6ff1f2d1344..a278bc41ef761 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp
@@ -37,12 +37,12 @@ TEST_CONSTEXPR_CXX20 bool test() {
 
 int main(int, char**) {
   test<char>();
-  test<char const>();
+  test<int>();
   test<void>();
 
 #if TEST_STD_VER > 17
   static_assert(test<char>());
-  static_assert(test<char const>());
+  static_assert(test<int>());
   static_assert(test<void>());
 #endif
   return 0;
diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator.dtor.pass.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator.dtor.pass.cpp
index a095ca102491e..69c6595c98645 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator.dtor.pass.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator.dtor.pass.cpp
@@ -26,15 +26,9 @@ int main(int, char**)
 {
     test<int>();
     test<void>();
-#ifdef _LIBCPP_VERSION // extension
-    test<int const>();
-#endif // _LIBCPP_VERSION
 
     static_assert(test<int>());
     static_assert(test<void>());
-#ifdef _LIBCPP_VERSION // extension
-    static_assert(test<int const>());
-#endif // _LIBCPP_VERSION
 
     return 0;
 }
diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.constexpr.size.verify.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.constexpr.size.verify.cpp
index fbbb334fea0fd..34a89e8be8591 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.constexpr.size.verify.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.constexpr.size.verify.cpp
@@ -34,5 +34,4 @@ constexpr bool test()
 
 void f() {
     static_assert(test<double>()); // expected-error {{static assertion expression is not an integral constant expression}}
-    LIBCPP_STATIC_ASSERT(test<const double>()); // expected-error {{static assertion expression is not an integral constant expression}}
 }
diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
index 1913a0e0dcc8d..2b11bd7f48dd7 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
@@ -45,7 +45,6 @@ void test()
 int main(int, char**)
 {
     test<double>();
-    LIBCPP_ONLY(test<const double>());
 
   return 0;
 }
diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx17.verify.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx17.verify.cpp
index 917492929ecc2..96ae6427188c0 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx17.verify.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx17.verify.cpp
@@ -35,13 +35,6 @@ void f() {
         typedef std::allocator<char>::const_reference ConstReference;   // expected-warning {{'const_reference' is deprecated}}
         typedef std::allocator<char>::rebind<int>::other Rebind;        // expected-warning {{'rebind<int>' is deprecated}}
     }
-    {
-        typedef std::allocator<char const>::pointer Pointer;                  // expected-warning {{'pointer' is deprecated}}
-        typedef std::allocator<char const>::const_pointer ConstPointer;       // expected-warning {{'const_pointer' is deprecated}}
-        typedef std::allocator<char const>::reference Reference;              // expected-warning {{'reference' is deprecated}}
-        typedef std::allocator<char const>::const_reference ConstReference;   // expected-warning {{'const_reference' is deprecated}}
-        typedef std::allocator<char const>::rebind<int>::other Rebind;        // expected-warning {{'rebind<int>' is deprecated}}
-    }
     {
         typedef std::allocator<void>::pointer Pointer;                  // expected-warning {{'pointer' is deprecated}}
         typedef std::allocator<void>::const_pointer ConstPointer;       // expected-warning {{'const_pointer' is deprecated}}
diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.pass.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.pass.cpp
index 7085a1d3fc602..581bdced36a0d 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.pass.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.pass.cpp
@@ -61,8 +61,5 @@ void test() {
 
 int main(int, char**) {
     test<char>();
-#ifdef _LIBCPP_VERSION
-    test<char const>(); // extension
-#endif
     return 0;
 }
diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx20.verify.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx20.verify.cpp
index 2fb7a60c9a88f..e8c48439b9f46 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx20.verify.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx20.verify.cpp
@@ -39,6 +39,6 @@ void check()
 
 void f() {
     check<char>();
-    check<char const>();
+    check<int>();
     check<voi...
[truncated]

@zibi2
Copy link
Contributor

zibi2 commented Jun 21, 2024

We are fine with this patch. Thank you for giving us grace period.

Copy link
Contributor

@cjdb cjdb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for providing the opt-out mechanism!

@ldionne ldionne merged commit eb12d9b into llvm:main Jun 25, 2024
51 of 58 checks passed
@ldionne ldionne deleted the review/remove-allocator-const-extension branch June 25, 2024 14:19
jrguzman-ms pushed a commit to msft-mirror-aosp/platform.system.netd that referenced this pull request Jun 28, 2024
A container of const T uses std::allocator<const T>, which was an
undocumented libc++ extension that has been removed.

See llvm/llvm-project#96319.

Bug: 349681543
Test: m libnetd_server
Change-Id: I1e97b0685fd94dc11f1c58c7fa05e1dd140d8172
bherrera pushed a commit to misttech/mist-os that referenced this pull request Jul 1, 2024
In llvm/llvm-project#96319, libc++ removed the
`allocator<const T>` extension. This change removes most uses from the
Fuchsia build and suppresses the remaining ones.

Bug: 349734097
Change-Id: I31b1a29125b8175ab1cba5c89345d391e7bda404
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1072789
Fuchsia-Auto-Submit: Petr Hosek <phosek@google.com>
Reviewed-by: Jacob Rutherford <jruthe@google.com>
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
Reviewed-by: Roland McGrath <mcgrathr@google.com>
Reviewed-by: Ian McKellar <ianloic@google.com>
bherrera pushed a commit to misttech/integration that referenced this pull request Jul 1, 2024
In llvm/llvm-project#96319, libc++ removed the
`allocator<const T>` extension. This change removes most uses from the
Fuchsia build and suppresses the remaining ones.

Original-Bug: 349734097
Original-Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1072789
Original-Revision: 6844bacfeec5c5739d3c7c31cc051c4ceccb1408
GitOrigin-RevId: e5fc8ae7ee56e3cf7c51f9eb2acbe2c926d42130
Change-Id: If6baf78af711f98a04c7fee18cd1225c519d6347
AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
This effort has quite a history:
- This was first attempted in 2022 via bed3240, which broke
std::shared_ptr<T const> and caused the change to be reverted in
9138666.
- We then re-attempted landing the change in 276ca87 after fixing
std::shared_ptr, but reports were made that this broke code en masse
within Google. This led to the patch being reverted again in
a54d028 with the goal to land this again with a migration path for
vendors.

This patch re-lands the removal while providing a migration path for
vendors by providing the `_LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST` macro.
This macro will be honored for the LLVM 19 release and will be removed
after that, at which point allocator<const T> will be removed
unconditionally.

Fixes llvm#73665
hubot pushed a commit to aosp-mirror/platform_frameworks_base that referenced this pull request Jul 11, 2024
A container of const T uses std::allocator<const T>, which was an
undocumented libc++ extension that has been removed.

See llvm/llvm-project#96319.

Bug: 349681543
Test: m libaapt2
Change-Id: Ic712f8c844b05687948162e5d080af3726b322f6
hubot pushed a commit to aosp-mirror/platform_system_core that referenced this pull request Jul 12, 2024
A container of const T uses std::allocator<const T>, which was an
undocumented libc++ extension that has been removed.

See llvm/llvm-project#96319.

Bug: 349681543
Test: m libfs_mgr
Change-Id: Ic7f50453f05293b7684be22393d6e5871e493983
hubot pushed a commit to aosp-mirror/platform_system_core that referenced this pull request Jul 12, 2024
A container of const T uses std::allocator<const T>, which was an
undocumented libc++ extension that has been removed.

See llvm/llvm-project#96319.

Bug: 349681543
Test: m bootstat
Change-Id: Id338f439aa4caf8c9f3c6fc15faef19b1edc4368
jrguzman-ms pushed a commit to msft-mirror-aosp/platform.frameworks.av that referenced this pull request Jul 12, 2024
A container of const T uses std::allocator<const T>, which was an
undocumented libc++ extension that has been removed.

See llvm/llvm-project#96319.

Bug: 349681543
Test: m libstagefright_bufferpool@2.0.1
Change-Id: If562374c45fa5a48b1cf45007b6264937014dea5
jrguzman-ms pushed a commit to msft-mirror-aosp/platform.frameworks.av that referenced this pull request Jul 12, 2024
A container of const T uses std::allocator<const T>, which was an
undocumented libc++ extension that has been removed.

See llvm/llvm-project#96319.

Bug: 349681543
Test: m libstagefright
Change-Id: If6dd5edb7a6c83d5e3f37e21fd8fdfe41f1093cc
jrguzman-ms pushed a commit to msft-mirror-aosp/platform.frameworks.av that referenced this pull request Jul 12, 2024
A container of const T uses std::allocator<const T>, which was an
undocumented libc++ extension that has been removed.

See llvm/llvm-project#96319.

Bug: 349681543
Test: m libcameraservice
Change-Id: Ib3ae6b55c4e95cd458e190511a59e8d0459cf16a
jrguzman-ms pushed a commit to msft-mirror-aosp/platform.packages.modules.Connectivity that referenced this pull request Jul 12, 2024
A container of const T uses std::allocator<const T>, which was an
undocumented libc++ extension that has been removed.

See llvm/llvm-project#96319.

Bug: 349681543
Test: m libnetdutils
Change-Id: I0b0eb07a6c95b4781ad04a82068bd33aef68e33b
jrguzman-ms pushed a commit to msft-mirror-aosp/platform.hardware.interfaces that referenced this pull request Jul 13, 2024
A container of const T uses std::allocator<const T>, which was an
undocumented libc++ extension that has been removed.

See llvm/llvm-project#96319.

Bug: 349681543
Test: m libstagefright_aidl_bufferpool2
Change-Id: I6491377d6275c5d18cd91b40184d6f05cff7cb9a
jrguzman-ms pushed a commit to msft-mirror-aosp/platform.frameworks.native that referenced this pull request Jul 16, 2024
A container of const T uses std::allocator<const T>, which was an
undocumented libc++ extension that has been removed.

See llvm/llvm-project#96319.

Bug: 349681543
Test: m libdumputils
Change-Id: Ie673d1f16ebe25050e4f04a2fce797cb6a98f2d9
jrguzman-ms pushed a commit to msft-mirror-aosp/platform.frameworks.native that referenced this pull request Jul 16, 2024
A container of const T uses std::allocator<const T>, which was an
undocumented libc++ extension that has been removed.

See llvm/llvm-project#96319.

Bug: 349681543
Test: m librenderengine
Change-Id: I4c0f5adb94415777f832217bc8115e04de6186c5
jrguzman-ms pushed a commit to msft-mirror-aosp/platform.frameworks.native that referenced this pull request Jul 16, 2024
A container of const T uses std::allocator<const T>, which was an
undocumented libc++ extension that has been removed.

See llvm/llvm-project#96319.

Bug: 349681543
Test: m libcompositionengine
Change-Id: I359350a298fc9a59c0ca925a36f753ac3fb3b64e
jrguzman-ms pushed a commit to msft-mirror-aosp/platform.system.teeui that referenced this pull request Jul 19, 2024
A container of const T uses std::allocator<const T>, which was an
undocumented libc++ extension that has been removed.

See llvm/llvm-project#96319.

Bug: 349681543
Test: m android.hardware.confirmationui-lib.cuttlefish
Test: trusty/vendor/google/aosp/scripts/build.py qemu-generic-arm64-test-debug
Change-Id: I455844e2b09cfee34646bc3693867c7c1ff597e3
bherrera pushed a commit to misttech/mist-os that referenced this pull request Jul 30, 2024
llvm/llvm-project#96319 removed
the support of containers with const qualified element
type in libc++. This patch removes the const from a
container to fix the build issue.

Bug: 354872193
Change-Id: I57394ca2ba32cb6b340651d94eec5fe047cd5bed
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1087412
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
Reviewed-by: Marie Janssen <jamuraa@google.com>
Fuchsia-Auto-Submit: Gulfem Savrun Yeniceri <gulfem@google.com>
bherrera pushed a commit to misttech/integration that referenced this pull request Jul 30, 2024
llvm/llvm-project#96319 removed
the support of containers with const qualified element
type in libc++. This patch removes the const from a
container to fix the build issue.

Original-Bug: 354872193
Original-Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1087412
Original-Revision: 6044901600a19eeb80fce0fa2f8d492dc0e2cc9a
GitOrigin-RevId: 079bb67b8a4f02027e0380cbc4479a0a8ea49c5a
Change-Id: I2db7b655cc7dcba15a8de8e059b2c653321ec40a
ev-gerrit pushed a commit to Evervolv/android_packages_modules_Connectivity that referenced this pull request Dec 12, 2024
A container of const T uses std::allocator<const T>, which was an
undocumented libc++ extension that has been removed.

See llvm/llvm-project#96319.

Bug: 349681543
Test: m libnetdutils
Change-Id: I0b0eb07a6c95b4781ad04a82068bd33aef68e33b

Former-commit-id: b2d7582274fe30b9a70a9bda24b105fe970e13cf
Klozz pushed a commit to TheXPerienceProject/android_system_core that referenced this pull request Jan 25, 2025
A container of const T uses std::allocator<const T>, which was an
undocumented libc++ extension that has been removed.

See llvm/llvm-project#96319.

Bug: 349681543
Test: m libfs_mgr
Change-Id: Ic7f50453f05293b7684be22393d6e5871e493983
Klozz pushed a commit to TheXPerienceProject/android_system_core that referenced this pull request Jan 25, 2025
A container of const T uses std::allocator<const T>, which was an
undocumented libc++ extension that has been removed.

See llvm/llvm-project#96319.

Bug: 349681543
Test: m bootstat
Change-Id: Id338f439aa4caf8c9f3c6fc15faef19b1edc4368
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[libc++] Remove allocator<T const> extension
4 participants