Skip to content

Commit 8751bbe

Browse files
authored
[libc++] Deprecate the _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS macro (llvm#77692)
As described in llvm#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 llvm#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 llvm#69994 Fixes llvm#63900 Partially addresses llvm#75975
1 parent dec908a commit 8751bbe

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

libcxx/docs/ReleaseNotes/18.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ Deprecations and Removals
117117
and ``<experimental/vector>`` have been removed in LLVM 18, as all their contents will have been
118118
implemented in namespace ``std`` for at least two releases.
119119

120+
- The macro ``_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS`` has been deprecated and will be removed
121+
in LLVM 19. This macro used to re-enable redundant members of ``std::allocator<T>`` like ``pointer``,
122+
``reference``, ``rebind``, ``address``, ``max_size``, ``construct``, ``destroy``, and the two-argument
123+
overload of ``allocate``. However, this led to the library being non-conforming due to incorrect
124+
constexpr-ness.
125+
120126
Upcoming Deprecations and Removals
121127
----------------------------------
122128

@@ -140,6 +146,9 @@ LLVM 19
140146
- The ``_LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT`` macro that changed the behavior for narrowing conversions
141147
in ``std::variant`` will be removed in LLVM 19.
142148

149+
- The ``_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS`` macro has been deprecated in LLVM 18 and will be removed
150+
entirely in LLVM 19.
151+
143152
LLVM 20
144153
~~~~~~~
145154

libcxx/include/__memory/allocator.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3131
template <class _Tp>
3232
class allocator;
3333

34+
#if defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
35+
# pragma clang deprecated( \
36+
_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS, \
37+
"_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS is deprecated in LLVM 18 and will be removed in LLVM 19")
38+
#endif
39+
3440
#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION)
3541
// These specializations shouldn't be marked _LIBCPP_DEPRECATED_IN_CXX17.
3642
// Specializing allocator<void> is deprecated, but not using it.

libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/address.depr_in_cxx17.verify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
// UNSUPPORTED: c++03, c++11, c++14
1818

19-
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
19+
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS -Wno-deprecated-pragma
2020

2121
#include <memory>
2222

libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
// UNSUPPORTED: c++03, c++11, c++14
1717

18-
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
18+
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS -Wno-deprecated-pragma
1919

2020
#include <memory>
2121

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// <memory>
10+
11+
// Ensure that defining _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS yields a
12+
// deprecation warning. We intend to issue a deprecation warning in LLVM 18
13+
// and remove the macro entirely in LLVM 19. As such, this test will be quite
14+
// short lived.
15+
16+
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
17+
18+
// UNSUPPORTED: clang-modules-build
19+
20+
#include <memory> // expected-warning@* 1+ {{macro '_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS' has been marked as deprecated}}

0 commit comments

Comments
 (0)