Skip to content

Commit 4bf8dc1

Browse files
[libc++] Remove macros for keeping std::allocator members and void specialization after C++20 (#85806)
Fixes #75975. Remove `_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS` for the LLVM 19 release, it was previously marked as deprecated in LLVM 18. I believe that `_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION` was only used by Google in conjunction with `_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS`. Removing both macros together should not cause any issues in practice, even though we did not announce the removal of `_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION` before.
1 parent 6942927 commit 4bf8dc1

22 files changed

+291
-238
lines changed

libcxx/docs/ReleaseNotes/19.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ Deprecations and Removals
7070
- The ``_LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT`` macro that changed the behavior for narrowing conversions
7171
in ``std::variant`` has been removed in LLVM 19.
7272

73-
- TODO: The ``_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS`` macro has been removed in LLVM 19.
73+
- The ``_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS`` and ``_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION``
74+
macros have been removed in LLVM 19.
7475

7576
- TODO: The ``_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES`` and ``_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES`` macros have
7677
been removed in LLVM 19. C++17 and C++20 removed features can still be re-enabled individually.

libcxx/docs/UsingLibcxx.rst

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,6 @@ C++20 Specific Configuration Macros
244244
This macro is deprecated and will be removed in LLVM-19. Use the
245245
individual macros listed below.
246246

247-
**_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS**:
248-
This macro is used to re-enable redundant members of `allocator<T>`,
249-
including `pointer`, `reference`, `rebind`, `address`, `max_size`,
250-
`construct`, `destroy`, and the two-argument overload of `allocate`.
251-
This macro has been deprecated and will be removed in LLVM-19.
252-
253-
**_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION**:
254-
This macro is used to re-enable the library-provided specializations of
255-
`allocator<void>` and `allocator<const void>`.
256-
Use it in conjunction with `_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS`
257-
to ensure that removed members of `allocator<void>` can be accessed.
258-
259247
**_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS**:
260248
This macro is used to re-enable the `argument_type`, `result_type`,
261249
`first_argument_type`, and `second_argument_type` members of class

libcxx/include/__config

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,8 +1238,6 @@ __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, c
12381238
# endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
12391239

12401240
# if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES)
1241-
# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
1242-
# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION
12431241
# define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS
12441242
# define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS
12451243
# define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR

libcxx/include/__memory/allocator.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +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-
40-
#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION)
34+
#if _LIBCPP_STD_VER <= 17
4135
// These specializations shouldn't be marked _LIBCPP_DEPRECATED_IN_CXX17.
4236
// Specializing allocator<void> is deprecated, but not using it.
4337
template <>
4438
class _LIBCPP_TEMPLATE_VIS allocator<void> {
45-
# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
39+
# if _LIBCPP_STD_VER <= 17
4640

4741
public:
4842
_LIBCPP_DEPRECATED_IN_CXX17 typedef void* pointer;
@@ -58,7 +52,7 @@ class _LIBCPP_TEMPLATE_VIS allocator<void> {
5852

5953
template <>
6054
class _LIBCPP_TEMPLATE_VIS allocator<const void> {
61-
# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
55+
# if _LIBCPP_STD_VER <= 17
6256

6357
public:
6458
_LIBCPP_DEPRECATED_IN_CXX17 typedef const void* pointer;
@@ -141,7 +135,7 @@ class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if<!is_void<_Tp>::v
141135
}
142136

143137
// C++20 Removed members
144-
#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
138+
#if _LIBCPP_STD_VER <= 17
145139
_LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp* pointer;
146140
_LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer;
147141
_LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp& reference;
@@ -221,7 +215,7 @@ class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
221215
}
222216

223217
// C++20 Removed members
224-
#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
218+
#if _LIBCPP_STD_VER <= 17
225219
_LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* pointer;
226220
_LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer;
227221
_LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& reference;

libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/address.cxx2a.pass.cpp renamed to libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/address.cxx20.pass.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
// pointer address(reference x) const;
1313
// const_pointer address(const_reference x) const;
1414

15-
// In C++20, parts of std::allocator<T> have been removed.
16-
// However, for backwards compatibility, if _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
17-
// is defined before including <memory>, then removed members will be restored.
15+
// Removed in C++20, deprecated in C++17.
1816

19-
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
17+
// REQUIRES: c++03 || c++11 || c++14 || c++17
2018
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
2119

2220
#include <memory>
@@ -25,25 +23,22 @@
2523
#include "test_macros.h"
2624

2725
template <class T>
28-
void test_address()
29-
{
30-
T* tp = new T();
31-
const T* ctp = tp;
32-
const std::allocator<T> a;
33-
assert(a.address(*tp) == tp);
34-
assert(a.address(*ctp) == tp);
35-
delete tp;
26+
void test_address() {
27+
T* tp = new T();
28+
const T* ctp = tp;
29+
const std::allocator<T> a;
30+
assert(a.address(*tp) == tp);
31+
assert(a.address(*ctp) == tp);
32+
delete tp;
3633
}
3734

38-
struct A
39-
{
40-
void operator&() const {}
35+
struct A {
36+
void operator&() const {}
4137
};
4238

43-
int main(int, char**)
44-
{
45-
test_address<int>();
46-
test_address<A>();
39+
int main(int, char**) {
40+
test_address<int>();
41+
test_address<A>();
4742

4843
return 0;
4944
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
// allocator:
12+
// pointer address(reference x) const;
13+
// const_pointer address(const_reference x) const;
14+
15+
// In C++20, parts of std::allocator<T> have been removed.
16+
// UNSUPPORTED: c++03, c++11, c++14, c++17
17+
18+
#include <memory>
19+
#include <cassert>
20+
21+
#include "test_macros.h"
22+
23+
template <class T>
24+
void test_address() {
25+
T* tp = new T();
26+
const T* ctp = tp;
27+
const std::allocator<T> a;
28+
assert(a.address(*tp) == tp); // expected-error 2 {{no member}}
29+
assert(a.address(*ctp) == tp); // expected-error 2 {{no member}}
30+
delete tp;
31+
}
32+
33+
struct A {
34+
void operator&() const {}
35+
};
36+
37+
int main(int, char**) {
38+
test_address<int>();
39+
test_address<A>();
40+
41+
return 0;
42+
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414

1515
// Deprecated in C++17
1616

17-
// UNSUPPORTED: c++03, c++11, c++14
18-
19-
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS -Wno-deprecated-pragma
17+
// REQUIRES: c++17
2018

2119
#include <memory>
2220

libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.cxx2a.pass.cpp renamed to libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.cxx20.pass.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@
1111
// allocator:
1212
// T* allocate(size_t n, const void* hint);
1313

14-
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
14+
// Removed in C++20, deprecated in C++17.
15+
16+
// REQUIRES: c++03 || c++11 || c++14 || c++17
1517
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
1618

1719
#include <memory>
1820
#include <cassert>
19-
#include <cstddef> // for std::max_align_t
21+
#include <cstddef> // for std::max_align_t
2022

2123
#include "test_macros.h"
2224
#include "count_new.h"
2325

24-
2526
#ifdef TEST_HAS_NO_ALIGNED_ALLOCATION
2627
static const bool UsingAlignedNew = false;
2728
#else
@@ -36,7 +37,6 @@ static const std::size_t MaxAligned = std::alignment_of<std::max_align_t>::value
3637

3738
static const std::size_t OverAligned = MaxAligned * 2;
3839

39-
4040
template <std::size_t Align>
4141
struct TEST_ALIGNAS(Align) AlignedType {
4242
char data;
@@ -48,19 +48,18 @@ struct TEST_ALIGNAS(Align) AlignedType {
4848
template <std::size_t Align>
4949
int AlignedType<Align>::constructed = 0;
5050

51-
5251
template <std::size_t Align>
5352
void test_aligned() {
5453
typedef AlignedType<Align> T;
5554
T::constructed = 0;
5655
globalMemCounter.reset();
5756
std::allocator<T> a;
5857
const bool IsOverAlignedType = Align > MaxAligned;
59-
const bool ExpectAligned = IsOverAlignedType && UsingAlignedNew;
58+
const bool ExpectAligned = IsOverAlignedType && UsingAlignedNew;
6059
{
61-
globalMemCounter.last_new_size = 0;
60+
globalMemCounter.last_new_size = 0;
6261
globalMemCounter.last_new_align = 0;
63-
T* ap2 = a.allocate(11, (const void*)5);
62+
T* ap2 = a.allocate(11, (const void*)5);
6463
DoNotOptimize(ap2);
6564
assert(globalMemCounter.checkOutstandingNewEq(1));
6665
assert(globalMemCounter.checkNewCalledEq(1));
@@ -80,14 +79,14 @@ void test_aligned() {
8079
}
8180

8281
int main(int, char**) {
83-
test_aligned<1>();
84-
test_aligned<2>();
85-
test_aligned<4>();
86-
test_aligned<8>();
87-
test_aligned<16>();
88-
test_aligned<MaxAligned>();
89-
test_aligned<OverAligned>();
90-
test_aligned<OverAligned * 2>();
82+
test_aligned<1>();
83+
test_aligned<2>();
84+
test_aligned<4>();
85+
test_aligned<8>();
86+
test_aligned<16>();
87+
test_aligned<MaxAligned>();
88+
test_aligned<OverAligned>();
89+
test_aligned<OverAligned * 2>();
9190

9291
return 0;
9392
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
// UNSUPPORTED: c++03, c++11, c++14, c++17
10+
11+
// <memory>
12+
13+
// allocator:
14+
// T* allocate(size_t n, const void* hint);
15+
16+
// Removed in C++20.
17+
18+
#include <memory>
19+
20+
void f() {
21+
std::allocator<int> a;
22+
a.allocate(3, nullptr); // expected-error {{too many arguments to function call}}
23+
}

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

Lines changed: 0 additions & 28 deletions
This file was deleted.

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414
// Deprecated in C++17
1515

16-
// UNSUPPORTED: c++03, c++11, c++14
17-
18-
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS -Wno-deprecated-pragma
16+
// REQUIRES: c++17
1917

2018
#include <memory>
2119

0 commit comments

Comments
 (0)