[llvm] [lld] [clang] [libcxx] [mlir] [openmp] [libc++] Deprecate the _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS macro (PR #77692)

Louis Dionne via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 11 13:58:38 PST 2024


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/77692

>From 6b3fd86a9949458410895a2292db935665a2ab77 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 10 Jan 2024 15:23:47 -0500
Subject: [PATCH 1/3] [libc++] Deprecate the
 _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS macro

As described in #69994, using the escape hatch makes us non-conforming
in C++20 due to incorrect constexpr-ness. It also leads to bad diagnostics
as reported by #63900. We discussed the issue in the libc++ monthly meeting
and we agreed that we should deprecate the macro in LLVM 18, and then
remove it in LLVM 19 since it causes too many problems.

This patch does the first part of this -- it deprecates the macro.

Fixes #69994
Fixes #63900
Partially addresses #75975
---
 libcxx/docs/ReleaseNotes/18.rst                |  9 +++++++++
 libcxx/include/__memory/allocator.h            |  6 ++++++
 .../address.depr_in_cxx17.verify.cpp           |  2 +-
 .../allocate.depr_in_cxx17.verify.cpp          |  2 +-
 ...ved_allocator_members.deprecated.verify.cpp | 18 ++++++++++++++++++
 5 files changed, 35 insertions(+), 2 deletions(-)
 create mode 100644 libcxx/test/libcxx/depr/depr.default.allocator/enable_removed_allocator_members.deprecated.verify.cpp

diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index 5df6242e52317a..ced632022ee497 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -117,6 +117,12 @@ Deprecations and Removals
   and ``<experimental/vector>`` have been removed in LLVM 18, as all their contents will have been
   implemented in namespace ``std`` for at least two releases.
 
+- The macro ``_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS`` has been deprecated and will be removed
+  in LLVM 19. This macro used to re-enable redundant members of ``std::allocator<T>`` like ``pointer``,
+  ``reference``, ``rebind``, ``address``, ``max_size``, ``construct``, ``destroy``, and the two-argument
+  overload of ``allocate``. However, this led to the library being non-conforming due to incorrect
+  constexpr-ness. As a result the macro is being deprecated and will be removed in LLVM 19.
+
 Upcoming Deprecations and Removals
 ----------------------------------
 
@@ -140,6 +146,9 @@ LLVM 19
 - The ``_LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT`` macro that changed the behavior for narrowing conversions
   in ``std::variant`` will be removed in LLVM 19.
 
+- The ``_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS`` macro has been deprecated in LLVM 18 and will be removed
+  entirely in LLVM 19.
+
 LLVM 20
 ~~~~~~~
 
diff --git a/libcxx/include/__memory/allocator.h b/libcxx/include/__memory/allocator.h
index 747ce30d8fef61..8d54e0f0897dda 100644
--- a/libcxx/include/__memory/allocator.h
+++ b/libcxx/include/__memory/allocator.h
@@ -31,6 +31,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 template <class _Tp>
 class allocator;
 
+#if defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
+#  pragma clang deprecated(                                                                                            \
+      _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS,                                                                  \
+      "_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS is deprecated in LLVM 18 and will be removed in LLVM 19")
+#endif
+
 #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION)
 // These specializations shouldn't be marked _LIBCPP_DEPRECATED_IN_CXX17.
 // Specializing allocator<void> is deprecated, but not using it.
diff --git a/libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/address.depr_in_cxx17.verify.cpp b/libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/address.depr_in_cxx17.verify.cpp
index 5b21cc607711e9..83d059a838ffb7 100644
--- a/libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/address.depr_in_cxx17.verify.cpp
+++ b/libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/address.depr_in_cxx17.verify.cpp
@@ -16,7 +16,7 @@
 
 // UNSUPPORTED: c++03, c++11, c++14
 
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS -Wno-deprecated-pragma
 
 #include <memory>
 
diff --git a/libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp b/libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp
index 79fd61d24c4cee..8b2e862e9503e9 100644
--- a/libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp
+++ b/libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp
@@ -15,7 +15,7 @@
 
 // UNSUPPORTED: c++03, c++11, c++14
 
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS -Wno-deprecated-pragma
 
 #include <memory>
 
diff --git a/libcxx/test/libcxx/depr/depr.default.allocator/enable_removed_allocator_members.deprecated.verify.cpp b/libcxx/test/libcxx/depr/depr.default.allocator/enable_removed_allocator_members.deprecated.verify.cpp
new file mode 100644
index 00000000000000..5d79ad339a5024
--- /dev/null
+++ b/libcxx/test/libcxx/depr/depr.default.allocator/enable_removed_allocator_members.deprecated.verify.cpp
@@ -0,0 +1,18 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// Ensure that defining _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS yields a
+// deprecation warning. We intend to issue a deprecation warning in LLVM 18
+// and remove the macro entirely in LLVM 19. As such, this test will be quite
+// short lived.
+
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
+
+#include <memory> // expected-warning@* 1+ {{macro '_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS' has been marked as deprecated}}

>From 04c8994c55d0ecf549be8f1f284d2ef480006bb8 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Thu, 11 Jan 2024 10:15:41 -0500
Subject: [PATCH 2/3] Update libcxx/docs/ReleaseNotes/18.rst

Co-authored-by: Mark de Wever <zar-rpg at xs4all.nl>
---
 libcxx/docs/ReleaseNotes/18.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index ced632022ee497..69cd38c988a6d7 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -121,7 +121,7 @@ Deprecations and Removals
   in LLVM 19. This macro used to re-enable redundant members of ``std::allocator<T>`` like ``pointer``,
   ``reference``, ``rebind``, ``address``, ``max_size``, ``construct``, ``destroy``, and the two-argument
   overload of ``allocate``. However, this led to the library being non-conforming due to incorrect
-  constexpr-ness. As a result the macro is being deprecated and will be removed in LLVM 19.
+  constexpr-ness.
 
 Upcoming Deprecations and Removals
 ----------------------------------

>From 9d43e19cf7597b9afa2fe8f3aa0c3ff760c92d7a Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Thu, 11 Jan 2024 16:58:10 -0500
Subject: [PATCH 3/3] Mark test as unsupported in clang-modules build

---
 .../enable_removed_allocator_members.deprecated.verify.cpp      | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libcxx/test/libcxx/depr/depr.default.allocator/enable_removed_allocator_members.deprecated.verify.cpp b/libcxx/test/libcxx/depr/depr.default.allocator/enable_removed_allocator_members.deprecated.verify.cpp
index 5d79ad339a5024..ab6495ea9db47c 100644
--- a/libcxx/test/libcxx/depr/depr.default.allocator/enable_removed_allocator_members.deprecated.verify.cpp
+++ b/libcxx/test/libcxx/depr/depr.default.allocator/enable_removed_allocator_members.deprecated.verify.cpp
@@ -15,4 +15,6 @@
 
 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
 
+// UNSUPPORTED: clang-modules-build
+
 #include <memory> // expected-warning@* 1+ {{macro '_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS' has been marked as deprecated}}



More information about the cfe-commits mailing list