Skip to content

Commit e7dac56

Browse files
committed
[🍒][libc++] Un-deprecate std::allocator<void>
This is a cherry-pick of 87784cc on 'main' for backporting to LLVM 12. Differential Revision: https://reviews.llvm.org/D104324
1 parent f78f530 commit e7dac56

11 files changed

+137
-141
lines changed

libcxx/include/memory

+16-16
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ struct allocator_traits
9999
};
100100
101101
template <>
102-
class allocator<void> // deprecated in C++17, removed in C++20
102+
class allocator<void> // removed in C++20
103103
{
104104
public:
105-
typedef void* pointer;
106-
typedef const void* const_pointer;
107-
typedef void value_type;
105+
typedef void* pointer; // deprecated in C++17
106+
typedef const void* const_pointer; // deprecated in C++17
107+
typedef void value_type; // deprecated in C++17
108108
109-
template <class _Up> struct rebind {typedef allocator<_Up> other;};
109+
template <class _Up> struct rebind {typedef allocator<_Up> other;}; // deprecated in C++17
110110
};
111111
112112
template <class T>
@@ -786,27 +786,27 @@ to_address(const _Pointer& __p) _NOEXCEPT
786786

787787
template <class _Tp> class allocator;
788788

789-
#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
789+
#if _LIBCPP_STD_VER <= 17
790790
template <>
791-
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 allocator<void>
791+
class _LIBCPP_TEMPLATE_VIS allocator<void>
792792
{
793793
public:
794-
typedef void* pointer;
795-
typedef const void* const_pointer;
796-
typedef void value_type;
794+
_LIBCPP_DEPRECATED_IN_CXX17 typedef void* pointer;
795+
_LIBCPP_DEPRECATED_IN_CXX17 typedef const void* const_pointer;
796+
_LIBCPP_DEPRECATED_IN_CXX17 typedef void value_type;
797797

798-
template <class _Up> struct rebind {typedef allocator<_Up> other;};
798+
template <class _Up> struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {typedef allocator<_Up> other;};
799799
};
800800

801801
template <>
802-
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 allocator<const void>
802+
class _LIBCPP_TEMPLATE_VIS allocator<const void>
803803
{
804804
public:
805-
typedef const void* pointer;
806-
typedef const void* const_pointer;
807-
typedef const void value_type;
805+
_LIBCPP_DEPRECATED_IN_CXX17 typedef const void* pointer;
806+
_LIBCPP_DEPRECATED_IN_CXX17 typedef const void* const_pointer;
807+
_LIBCPP_DEPRECATED_IN_CXX17 typedef const void value_type;
808808

809-
template <class _Up> struct rebind {typedef allocator<_Up> other;};
809+
template <class _Up> struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {typedef allocator<_Up> other;};
810810
};
811811
#endif
812812

libcxx/test/libcxx/depr/depr.default.allocator/allocator_types.cxx2a.pass.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@
3333
#include <type_traits>
3434
#include <cstddef>
3535

36-
#include "test_macros.h"
37-
38-
int main(int, char**)
39-
{
40-
static_assert((std::is_same<std::allocator<char>::size_type, std::size_t>::value), "");
41-
static_assert((std::is_same<std::allocator<char>::difference_type, std::ptrdiff_t>::value), "");
42-
static_assert((std::is_same<std::allocator<char>::pointer, char*>::value), "");
43-
static_assert((std::is_same<std::allocator<char>::const_pointer, const char*>::value), "");
44-
static_assert((std::is_same<std::allocator<char>::reference, char&>::value), "");
45-
static_assert((std::is_same<std::allocator<char>::const_reference, const char&>::value), "");
46-
static_assert((std::is_same<std::allocator<char>::rebind<int>::other,
36+
template <class T>
37+
void test() {
38+
static_assert((std::is_same<typename std::allocator<T>::size_type, std::size_t>::value), "");
39+
static_assert((std::is_same<typename std::allocator<T>::difference_type, std::ptrdiff_t>::value), "");
40+
static_assert((std::is_same<typename std::allocator<T>::pointer, T*>::value), "");
41+
static_assert((std::is_same<typename std::allocator<T>::const_pointer, const T*>::value), "");
42+
static_assert((std::is_same<typename std::allocator<T>::reference, T&>::value), "");
43+
static_assert((std::is_same<typename std::allocator<T>::const_reference, const T&>::value), "");
44+
static_assert((std::is_same<typename std::allocator<T>::template rebind<int>::other,
4745
std::allocator<int> >::value), "");
46+
}
4847

48+
int main(int, char**) {
49+
test<char>();
4950
return 0;
5051
}
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+
// Make sure we can use std::allocator<void> in all Standard modes. While the
12+
// explicit specialization for std::allocator<void> was deprecated, using that
13+
// specialization was neither deprecated nor removed (in C++20 it should simply
14+
// start using the primary template).
15+
//
16+
// See https://llvm.org/PR50299.
17+
18+
#include <memory>
19+
20+
std::allocator<void> a;

libcxx/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp

+21-23
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
//===----------------------------------------------------------------------===//
88

99
// <memory>
10-
// UNSUPPORTED: c++03, c++11, c++14, c++17
1110
//
1211
// template <class T>
1312
// class allocator
1413
// {
1514
// public: // All of these are constexpr after C++17
16-
// constexpr allocator() noexcept;
17-
// constexpr allocator(const allocator&) noexcept;
18-
// template<class U> constexpr allocator(const allocator<U>&) noexcept;
15+
// allocator() noexcept;
16+
// allocator(const allocator&) noexcept;
17+
// template<class U> allocator(const allocator<U>&) noexcept;
1918
// ...
2019
// };
2120

@@ -24,28 +23,27 @@
2423

2524
#include "test_macros.h"
2625

26+
template<class T>
27+
TEST_CONSTEXPR_CXX20 bool test() {
28+
typedef std::allocator<T> A1;
29+
typedef std::allocator<long> A2;
2730

28-
int main(int, char**)
29-
{
30-
{
31-
typedef std::allocator<char> AC;
32-
typedef std::allocator<long> AL;
31+
A1 a1;
32+
A1 a1_copy = a1; (void)a1_copy;
33+
A2 a2 = a1; (void)a2;
3334

34-
constexpr AC a1;
35-
constexpr AC a2{a1};
36-
constexpr AL a3{a2};
37-
(void) a3;
38-
}
39-
{
40-
typedef std::allocator<const char> AC;
41-
typedef std::allocator<const long> AL;
42-
43-
constexpr AC a1;
44-
constexpr AC a2{a1};
45-
constexpr AL a3{a2};
46-
(void) a3;
47-
}
35+
return true;
36+
}
4837

38+
int main(int, char**) {
39+
test<char>();
40+
test<char const>();
41+
test<void>();
4942

43+
#if TEST_STD_VER > 17
44+
static_assert(test<char>());
45+
static_assert(test<char const>());
46+
static_assert(test<void>());
47+
#endif
5048
return 0;
5149
}

libcxx/test/std/utilities/memory/default.allocator/allocator.dtor.pass.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
#include <memory>
1515

16-
1716
template <typename T>
1817
constexpr bool test() {
1918
std::allocator<T> alloc;
@@ -26,11 +25,13 @@ constexpr bool test() {
2625
int main(int, char**)
2726
{
2827
test<int>();
28+
test<void>();
2929
#ifdef _LIBCPP_VERSION // extension
3030
test<int const>();
3131
#endif // _LIBCPP_VERSION
3232

3333
static_assert(test<int>());
34+
static_assert(test<void>());
3435
#ifdef _LIBCPP_VERSION // extension
3536
static_assert(test<int const>());
3637
#endif // _LIBCPP_VERSION

libcxx/test/std/utilities/memory/default.allocator/allocator_pointers.pass.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#include <memory>
1212
#include <cassert>
1313

14-
// #include <memory>
15-
1614
#include "test_macros.h"
15+
16+
// <memory>
1717
//
1818
// template <class Alloc>
1919
// struct allocator_traits

libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx17.verify.cpp

+21-14
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,27 @@
3030
// UNSUPPORTED: clang-6
3131

3232
#include <memory>
33-
#include "test_macros.h"
3433

35-
int main(int, char**)
36-
{
37-
typedef std::allocator<char>::pointer AP; // expected-warning {{'pointer' is deprecated}}
38-
typedef std::allocator<char>::const_pointer ACP; // expected-warning {{'const_pointer' is deprecated}}
39-
typedef std::allocator<char>::reference AR; // expected-warning {{'reference' is deprecated}}
40-
typedef std::allocator<char>::const_reference ACR; // expected-warning {{'const_reference' is deprecated}}
41-
typedef std::allocator<char>::rebind<int>::other ARO; // expected-warning {{'rebind<int>' is deprecated}}
42-
43-
typedef std::allocator<char const>::pointer AP2; // expected-warning {{'pointer' is deprecated}}
44-
typedef std::allocator<char const>::const_pointer ACP2; // expected-warning {{'const_pointer' is deprecated}}
45-
typedef std::allocator<char const>::reference AR2; // expected-warning {{'reference' is deprecated}}
46-
typedef std::allocator<char const>::const_reference ACR2; // expected-warning {{'const_reference' is deprecated}}
47-
typedef std::allocator<char const>::rebind<int>::other ARO2; // expected-warning {{'rebind<int>' is deprecated}}
34+
int main(int, char**) {
35+
{
36+
typedef std::allocator<char>::pointer Pointer; // expected-warning {{'pointer' is deprecated}}
37+
typedef std::allocator<char>::const_pointer ConstPointer; // expected-warning {{'const_pointer' is deprecated}}
38+
typedef std::allocator<char>::reference Reference; // expected-warning {{'reference' is deprecated}}
39+
typedef std::allocator<char>::const_reference ConstReference; // expected-warning {{'const_reference' is deprecated}}
40+
typedef std::allocator<char>::rebind<int>::other Rebind; // expected-warning {{'rebind<int>' is deprecated}}
41+
}
42+
{
43+
typedef std::allocator<char const>::pointer Pointer; // expected-warning {{'pointer' is deprecated}}
44+
typedef std::allocator<char const>::const_pointer ConstPointer; // expected-warning {{'const_pointer' is deprecated}}
45+
typedef std::allocator<char const>::reference Reference; // expected-warning {{'reference' is deprecated}}
46+
typedef std::allocator<char const>::const_reference ConstReference; // expected-warning {{'const_reference' is deprecated}}
47+
typedef std::allocator<char const>::rebind<int>::other Rebind; // expected-warning {{'rebind<int>' is deprecated}}
48+
}
49+
{
50+
typedef std::allocator<void>::pointer Pointer; // expected-warning {{'pointer' is deprecated}}
51+
typedef std::allocator<void>::const_pointer ConstPointer; // expected-warning {{'const_pointer' is deprecated}}
52+
// reference and const_reference are not provided by std::allocator<void>
53+
typedef std::allocator<void>::rebind<int>::other Rebind; // expected-warning {{'rebind<int>' is deprecated}}
54+
}
4855
return 0;
4956
}

libcxx/test/std/utilities/memory/default.allocator/allocator_types.pass.cpp

+28-26
Original file line numberDiff line numberDiff line change
@@ -18,47 +18,49 @@
1818
// typedef ptrdiff_t difference_type;
1919
// typedef T value_type;
2020
//
21+
// typedef T* pointer; // deprecated in C++17, removed in C++20
22+
// typedef T const* const_pointer; // deprecated in C++17, removed in C++20
23+
// typedef T& reference; // deprecated in C++17, removed in C++20
24+
// typedef T const& const_reference; // deprecated in C++17, removed in C++20
25+
// template< class U > struct rebind { typedef allocator<U> other; }; // deprecated in C++17, removed in C++20
26+
//
2127
// typedef true_type propagate_on_container_move_assignment;
2228
// typedef true_type is_always_equal;
2329
// ...
2430
// };
2531

32+
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
33+
2634
#include <memory>
2735
#include <type_traits>
2836
#include <cstddef>
2937

3038
#include "test_macros.h"
3139

32-
template <typename T, typename U>
33-
TEST_CONSTEXPR_CXX20 bool test()
34-
{
35-
static_assert((std::is_same<typename std::allocator<T>::size_type, std::size_t>::value), "");
36-
static_assert((std::is_same<typename std::allocator<T>::difference_type, std::ptrdiff_t>::value), "");
37-
static_assert((std::is_same<typename std::allocator<T>::value_type, T>::value), "");
38-
static_assert((std::is_same<typename std::allocator<T>::propagate_on_container_move_assignment, std::true_type>::value), "");
39-
static_assert((std::is_same<typename std::allocator<T>::is_always_equal, std::true_type>::value), "");
40+
struct U;
4041

41-
std::allocator<T> a;
42-
std::allocator<T> a2 = a;
43-
a2 = a;
44-
std::allocator<U> a3 = a2;
45-
(void)a3;
42+
template <typename T>
43+
void test() {
44+
typedef std::allocator<T> Alloc;
45+
static_assert((std::is_same<typename Alloc::size_type, std::size_t>::value), "");
46+
static_assert((std::is_same<typename Alloc::difference_type, std::ptrdiff_t>::value), "");
47+
static_assert((std::is_same<typename Alloc::value_type, T>::value), "");
48+
static_assert((std::is_same<typename Alloc::propagate_on_container_move_assignment, std::true_type>::value), "");
49+
static_assert((std::is_same<typename Alloc::is_always_equal, std::true_type>::value), "");
4650

47-
return true;
51+
#if TEST_STD_VER <= 17
52+
static_assert((std::is_same<typename Alloc::pointer, T*>::value), "");
53+
static_assert((std::is_same<typename Alloc::const_pointer, T const*>::value), "");
54+
static_assert((std::is_same<typename Alloc::reference, T&>::value), "");
55+
static_assert((std::is_same<typename Alloc::const_reference, T const&>::value), "");
56+
static_assert((std::is_same<typename Alloc::template rebind<U>::other, std::allocator<U> >::value), "");
57+
#endif
4858
}
4959

50-
int main(int, char**)
51-
{
52-
test<char, int>();
53-
#ifdef _LIBCPP_VERSION // extension
54-
test<char const, int const>();
55-
#endif // _LIBCPP_VERSION
56-
57-
#if TEST_STD_VER > 17
58-
static_assert(test<char, int>());
59-
#ifdef _LIBCPP_VERSION // extension
60-
static_assert(test<char const, int const>());
61-
#endif // _LIBCPP_VERSION
60+
int main(int, char**) {
61+
test<char>();
62+
#ifdef _LIBCPP_VERSION
63+
test<char const>(); // extension
6264
#endif
6365
return 0;
6466
}

libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx20.verify.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@
3131
template <typename T>
3232
void check()
3333
{
34-
typedef typename std::allocator<T>::pointer AP; // expected-error 2 {{no type named 'pointer'}}
35-
typedef typename std::allocator<T>::const_pointer ACP; // expected-error 2 {{no type named 'const_pointer'}}
36-
typedef typename std::allocator<T>::reference AR; // expected-error 2 {{no type named 'reference'}}
37-
typedef typename std::allocator<T>::const_reference ACR; // expected-error 2 {{no type named 'const_reference'}}
38-
typedef typename std::allocator<T>::template rebind<int>::other ARO; // expected-error 2 {{no member named 'rebind'}}
34+
typedef typename std::allocator<T>::pointer AP; // expected-error 3 {{no type named 'pointer'}}
35+
typedef typename std::allocator<T>::const_pointer ACP; // expected-error 3 {{no type named 'const_pointer'}}
36+
typedef typename std::allocator<T>::reference AR; // expected-error 3 {{no type named 'reference'}}
37+
typedef typename std::allocator<T>::const_reference ACR; // expected-error 3 {{no type named 'const_reference'}}
38+
typedef typename std::allocator<T>::template rebind<int>::other ARO; // expected-error 3 {{no member named 'rebind'}}
3939
}
4040

4141
int main(int, char**)
4242
{
4343
check<char>();
4444
check<char const>();
45+
check<void>();
4546
return 0;
4647
}

libcxx/test/libcxx/depr/depr.default.allocator/allocator_void.cxx2a.pass.cpp renamed to libcxx/test/std/utilities/memory/default.allocator/allocator_types.void.compile.pass.cpp

+9-19
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// <memory>
9+
// Check that the nested types of std::allocator<void> are provided.
10+
// After C++17, those are not provided in the primary template and the
11+
// explicit specialization doesn't exist anymore, so this test is moot.
1012

11-
// Check that the following member types of allocator<void> are provided
12-
// regardless of the Standard when we request them from libc++.
13+
// REQUIRES: c++03 || c++11 || c++14 || c++17
1314

1415
// template <>
1516
// class allocator<void>
@@ -22,24 +23,13 @@
2223
// template <class _Up> struct rebind {typedef allocator<_Up> other;};
2324
// };
2425

25-
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
2626
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
2727

2828
#include <memory>
2929
#include <type_traits>
3030

31-
#include "test_macros.h"
32-
33-
int main(int, char**)
34-
{
35-
static_assert((std::is_same<std::allocator<void>::pointer, void*>::value), "");
36-
static_assert((std::is_same<std::allocator<void>::const_pointer, const void*>::value), "");
37-
static_assert((std::is_same<std::allocator<void>::value_type, void>::value), "");
38-
static_assert((std::is_same<std::allocator<void>::rebind<int>::other,
39-
std::allocator<int> >::value), "");
40-
std::allocator<void> a;
41-
std::allocator<void> a2 = a;
42-
a2 = a;
43-
44-
return 0;
45-
}
31+
static_assert((std::is_same<std::allocator<void>::pointer, void*>::value), "");
32+
static_assert((std::is_same<std::allocator<void>::const_pointer, const void*>::value), "");
33+
static_assert((std::is_same<std::allocator<void>::value_type, void>::value), "");
34+
static_assert((std::is_same<std::allocator<void>::rebind<int>::other,
35+
std::allocator<int> >::value), "");

0 commit comments

Comments
 (0)