[Mlir-commits] [mlir] [clang] [llvm] [lldb] [flang] [libcxx] [libc] [clang-tools-extra] [libc++][memory] P2868R1: Removing deprecated typedef `std::allocator::is_always_equal` (PR #78562)

Hristo Hristov llvmlistbot at llvm.org
Thu Jan 18 10:38:08 PST 2024


https://github.com/H-G-Hristov updated https://github.com/llvm/llvm-project/pull/78562

>From fadaafbf791d5fe78f6ac9ee3494b128339781ba Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Thu, 18 Jan 2024 09:47:40 +0200
Subject: [PATCH 1/4] [libc++][memory] P2868R1 - Removing deprecated typedef
 `std::allocator::is_always_equal`

Implements:
- https://wg21.link/P2868R1
- https://wg21.link/LWG3170
---
 libcxx/.clang-format                          |  1 +
 libcxx/docs/ReleaseNotes/18.rst               |  1 +
 libcxx/docs/Status/Cxx23Issues.csv            |  2 +-
 libcxx/docs/Status/Cxx2cPapers.csv            |  2 +-
 libcxx/docs/UsingLibcxx.rst                   |  4 ++
 libcxx/include/__memory/allocator.h           |  8 +++-
 libcxx/include/memory                         |  2 +-
 ...cator_types.deprecated_in_cxx23.verify.cpp | 44 +++++++++++++++++++
 .../allocator_types.pass.cpp                  |  2 +
 ...llocator_types.removed_in_cxx26.verify.cpp | 34 ++++++++++++++
 10 files changed, 95 insertions(+), 5 deletions(-)
 create mode 100644 libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx23.verify.cpp
 create mode 100644 libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx26.verify.cpp

diff --git a/libcxx/.clang-format b/libcxx/.clang-format
index 56bdf2b5f911659..39ae1322ffa8a63 100644
--- a/libcxx/.clang-format
+++ b/libcxx/.clang-format
@@ -28,6 +28,7 @@ AttributeMacros: [
                   '_LIBCPP_DEPRECATED_IN_CXX14',
                   '_LIBCPP_DEPRECATED_IN_CXX17',
                   '_LIBCPP_DEPRECATED_IN_CXX20',
+                  '_LIBCPP_DEPRECATED_IN_CXX23',
                   '_LIBCPP_DEPRECATED',
                   '_LIBCPP_DISABLE_EXTENTSION_WARNING',
                   '_LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION',
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index 77b7939a0c0ac96..3e2fb8727941d6b 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -60,6 +60,7 @@ Implemented Papers
 - P0521R0 - Proposed Resolution for CA 14 (``shared_ptr`` ``use_count/unique``)
 - P1759R6 - Native handles and file streams
 - P2517R1 - Add a conditional ``noexcept`` specification to ``std::apply``
+- P2868R3 - Remove Deprecated ``std::allocator`` Typedef From C++26
 
 
 Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx23Issues.csv b/libcxx/docs/Status/Cxx23Issues.csv
index b24ecc5525a1497..70480b338205804 100644
--- a/libcxx/docs/Status/Cxx23Issues.csv
+++ b/libcxx/docs/Status/Cxx23Issues.csv
@@ -15,7 +15,7 @@
 "`2743 <https://wg21.link/LWG2743>`__","P0083R3 ``node_handle`` private members missing ""exposition only"" comment","November 2020","|Nothing To Do|",""
 "`2820 <https://wg21.link/LWG2820>`__","Clarify ``<cstdint>`` macros","November 2020","|Nothing To Do|",""
 "`3120 <https://wg21.link/LWG3120>`__","Unclear behavior of ``monotonic_buffer_resource::release()``","November 2020","",""
-"`3170 <https://wg21.link/LWG3170>`__","``is_always_equal`` added to ``std::allocator`` makes the standard library treat derived types as always equal","November 2020","",""
+"`3170 <https://wg21.link/LWG3170>`__","``is_always_equal`` added to ``std::allocator`` makes the standard library treat derived types as always equal","November 2020","|Complete|","18.0"
 "`3036 <https://wg21.link/LWG3036>`__","``polymorphic_allocator::destroy`` is extraneous","November 2020","",""
 "`3171 <https://wg21.link/LWG3171>`__","LWG2989 breaks ``directory_entry`` stream insertion","November 2020","|Complete|","14.0"
 "`3306 <https://wg21.link/LWG3306>`__","``ranges::advance`` violates its preconditions","November 2020","|Complete|","14.0","|ranges|"
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv b/libcxx/docs/Status/Cxx2cPapers.csv
index 5701717f39766c6..762cbc6d487c69d 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -36,7 +36,7 @@
 "`P0952R2 <https://wg21.link/P0952R2>`__","LWG","A new specification for ``std::generate_canonical``","Kona November 2023","","",""
 "`P2447R6 <https://wg21.link/P2447R6>`__","LWG","``std::span`` over an initializer list","Kona November 2023","","",""
 "`P2821R5 <https://wg21.link/P2821R5>`__","LWG","``span.at()``","Kona November 2023","|Complete|","18.0",""
-"`P2868R3 <https://wg21.link/P2868R3>`__","LWG","Remove Deprecated ``std::allocator`` Typedef From C++26","Kona November 2023","","",""
+"`P2868R3 <https://wg21.link/P2868R3>`__","LWG","Remove Deprecated ``std::allocator`` Typedef From C++26","Kona November 2023","|Complete|","18.0",""
 "`P2870R3 <https://wg21.link/P2870R3>`__","LWG","Remove ``basic_string::reserve()`` From C++26","Kona November 2023","|Complete|","18.0",""
 "`P2871R3 <https://wg21.link/P2871R3>`__","LWG","Remove Deprecated Unicode Conversion Facets from C++26","Kona November 2023","|Complete|","18.0",""
 "`P2819R2 <https://wg21.link/P2819R2>`__","LWG","Add tuple protocol to complex","Kona November 2023","","",""
diff --git a/libcxx/docs/UsingLibcxx.rst b/libcxx/docs/UsingLibcxx.rst
index daf39c9faa449a8..44b8db6db61c04b 100644
--- a/libcxx/docs/UsingLibcxx.rst
+++ b/libcxx/docs/UsingLibcxx.rst
@@ -283,6 +283,10 @@ C++26 Specific Configuration Macros
   This macro is used to re-enable the function
   ``std::basic_string<...>::reserve()``.
 
+**_LIBCPP_ENABLE_CXX26_REMOVED_ALLOCATOR_MEMBERS**:
+  This macro is used to re-enable redundant member of `allocator<T>`
+  `is_always_equal`
+
 Libc++ Extensions
 =================
 
diff --git a/libcxx/include/__memory/allocator.h b/libcxx/include/__memory/allocator.h
index 8d54e0f0897dda8..4e6303914c38aa8 100644
--- a/libcxx/include/__memory/allocator.h
+++ b/libcxx/include/__memory/allocator.h
@@ -107,7 +107,9 @@ class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if<!is_void<_Tp>::v
   typedef ptrdiff_t difference_type;
   typedef _Tp value_type;
   typedef true_type propagate_on_container_move_assignment;
-  typedef true_type is_always_equal;
+#if _LIBCPP_STD_VER <= 23 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_ALLOCATOR_MEMBERS)
+  _LIBCPP_DEPRECATED_IN_CXX23 typedef true_type is_always_equal;
+#endif
 
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator() _NOEXCEPT = default;
 
@@ -185,7 +187,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;
-  typedef true_type is_always_equal;
+#if _LIBCPP_STD_VER <= 23 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_ALLOCATOR_MEMBERS)
+  _LIBCPP_DEPRECATED_IN_CXX23 typedef true_type is_always_equal;
+#endif
 
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator() _NOEXCEPT = default;
 
diff --git a/libcxx/include/memory b/libcxx/include/memory
index ee245d5fd2dcb2e..19c11ee94987283 100644
--- a/libcxx/include/memory
+++ b/libcxx/include/memory
@@ -139,7 +139,7 @@ public:
     template <class U> struct rebind {typedef allocator<U> other;}; // deprecated in C++17, removed in C++20
 
     typedef true_type propagate_on_container_move_assignment;
-    typedef true_type is_always_equal;
+    typedef true_type is_always_equal;                   // Deprecated in C++23, removed in C++26
 
     constexpr allocator() noexcept;                      // constexpr in C++20
     constexpr allocator(const allocator&) noexcept;      // constexpr in C++20
diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx23.verify.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx23.verify.cpp
new file mode 100644
index 000000000000000..a4b9c45d861a633
--- /dev/null
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx23.verify.cpp
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: c++23
+
+// <memory>
+
+// template <class T>
+// class allocator
+// {
+// ...
+//     typedef true_type is_always_equal; // Deprecated in C++23, removed in C++26
+// ...
+// };
+
+#include <memory>
+
+template <typename T>
+void check() {
+  typedef std::allocator<char>::is_always_equal IAE; // expected-warning {{'is_always_equal' is deprecated}}
+}
+
+void test() {
+  check<char>();
+  check<char const>();
+  check<void>();
+}
+
+// void f() {
+//   {
+//     typedef std::allocator<char>::is_always_equal IAE; // _expected-warning {{'is_always_equal' is deprecated}}
+//   }
+//   {
+//     typedef std::allocator<char const>::is_always_equal IAE; // _expected-warning {{'is_always_equal' is deprecated}}
+//   }
+//   {
+//     typedef std::allocator<void>::is_always_equal IAE; // _expected-warning {{'is_always_equal' 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 74adc6943594dcb..7085a1d3fc602fc 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
@@ -46,7 +46,9 @@ void test() {
     static_assert((std::is_same<typename Alloc::difference_type, std::ptrdiff_t>::value), "");
     static_assert((std::is_same<typename Alloc::value_type, T>::value), "");
     static_assert((std::is_same<typename Alloc::propagate_on_container_move_assignment, std::true_type>::value), "");
+#if TEST_STD_VER <= 23
     static_assert((std::is_same<typename Alloc::is_always_equal, std::true_type>::value), "");
+#endif
 
 #if TEST_STD_VER <= 17
     static_assert((std::is_same<typename Alloc::pointer, T*>::value), "");
diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx26.verify.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx26.verify.cpp
new file mode 100644
index 000000000000000..e26536f196e4f9a
--- /dev/null
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx26.verify.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, c++11, c++14, c++17, c++20, c++23
+
+// <memory>
+
+// Check that the following nested types are removed in C++20:
+
+// template <class T>
+// class allocator
+// {
+// ...
+//     typedef true_type is_always_equal; // Deprecated in C++23, removed in C++26
+// ...
+// };
+
+#include <memory>
+
+template <typename T>
+void check() {
+  using IAE = typename std::allocator<T>::is_always_equal; // expected-error 3 {{no type named 'is_always_equal'}}
+}
+
+void test() {
+  check<char>();
+  check<char const>();
+  check<void>();
+}

>From 623b38cab20e59b8bd9bcb5031a057b62e8e23d0 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Thu, 18 Jan 2024 12:58:37 +0200
Subject: [PATCH 2/4] Cleanup

---
 .../allocator_types.deprecated_in_cxx23.verify.cpp   | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx23.verify.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx23.verify.cpp
index a4b9c45d861a633..b5db7ca9648b6ee 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx23.verify.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx23.verify.cpp
@@ -30,15 +30,3 @@ void test() {
   check<char const>();
   check<void>();
 }
-
-// void f() {
-//   {
-//     typedef std::allocator<char>::is_always_equal IAE; // _expected-warning {{'is_always_equal' is deprecated}}
-//   }
-//   {
-//     typedef std::allocator<char const>::is_always_equal IAE; // _expected-warning {{'is_always_equal' is deprecated}}
-//   }
-//   {
-//     typedef std::allocator<void>::is_always_equal IAE; // _expected-warning {{'is_always_equal' is deprecated}}
-//   }
-// }

>From 9374494165b738d00fe7cee7fe660234d2ca417b Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Thu, 18 Jan 2024 13:05:04 +0200
Subject: [PATCH 3/4] Updated Release Notes

---
 libcxx/docs/ReleaseNotes/18.rst | 3 +++
 libcxx/docs/UsingLibcxx.rst     | 3 +--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index 3e2fb8727941d6b..a30451a2e19e2b3 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -90,6 +90,9 @@ Improvements and New Features
 - The ``_LIBCPP_ENABLE_CXX20_REMOVED_SHARED_PTR_UNIQUE`` macro has been added to make
   the function ``std::shared_ptr<...>::unique()`` available.
 
+- The ``_LIBCPP_ENABLE_CXX26_REMOVED_ALLOCATOR_MEMBERS`` macro has been added to make
+  the function ``allocator<T>::is_always_equal`` available.
+
 - The cmake option ``LIBCXX_ENABLE_STD_MODULES`` has been removed. The test
   infrastructure no longer depends on a modern CMake, it works with the minimal
   required LLVM version (3.20.0).
diff --git a/libcxx/docs/UsingLibcxx.rst b/libcxx/docs/UsingLibcxx.rst
index 44b8db6db61c04b..3b1be286c16981b 100644
--- a/libcxx/docs/UsingLibcxx.rst
+++ b/libcxx/docs/UsingLibcxx.rst
@@ -284,8 +284,7 @@ C++26 Specific Configuration Macros
   ``std::basic_string<...>::reserve()``.
 
 **_LIBCPP_ENABLE_CXX26_REMOVED_ALLOCATOR_MEMBERS**:
-  This macro is used to re-enable redundant member of `allocator<T>`
-  `is_always_equal`
+  This macro is used to re-enable redundant member of ``allocator<T>::is_always_equal``
 
 Libc++ Extensions
 =================

>From 714dc3c356273178fca9d6a9d9c9aee8a8f03a9f Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Thu, 18 Jan 2024 20:37:49 +0200
Subject: [PATCH 4/4] Addressed comments

---
 .../allocator_types.deprecated_in_cxx23.verify.cpp              | 2 +-
 .../allocator_types.removed_in_cxx26.verify.cpp                 | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx23.verify.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx23.verify.cpp
index b5db7ca9648b6ee..b934fdd0d578c14 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx23.verify.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx23.verify.cpp
@@ -22,7 +22,7 @@
 
 template <typename T>
 void check() {
-  typedef std::allocator<char>::is_always_equal IAE; // expected-warning {{'is_always_equal' is deprecated}}
+  typedef std::allocator<T>::is_always_equal IAE; // expected-warning {{'is_always_equal' is deprecated}}
 }
 
 void test() {
diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx26.verify.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx26.verify.cpp
index e26536f196e4f9a..72cc21402327a02 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx26.verify.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx26.verify.cpp
@@ -10,7 +10,7 @@
 
 // <memory>
 
-// Check that the following nested types are removed in C++20:
+// Check that the following nested types are removed in C++26:
 
 // template <class T>
 // class allocator



More information about the Mlir-commits mailing list