Skip to content

Commit 8339419

Browse files
committed
[libc++] Make std::allocator always trivially default constructible
1 parent 9e25a42 commit 8339419

File tree

1 file changed

+1
-29
lines changed

1 file changed

+1
-29
lines changed

libcxx/include/__memory/allocator.h

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@
1414
#include <__cstddef/ptrdiff_t.h>
1515
#include <__cstddef/size_t.h>
1616
#include <__memory/addressof.h>
17-
#include <__memory/allocate_at_least.h>
1817
#include <__memory/allocator_traits.h>
1918
#include <__new/allocate.h>
2019
#include <__new/exceptions.h>
2120
#include <__type_traits/is_const.h>
2221
#include <__type_traits/is_constant_evaluated.h>
23-
#include <__type_traits/is_same.h>
24-
#include <__type_traits/is_void.h>
2522
#include <__type_traits/is_volatile.h>
2623
#include <__utility/forward.h>
2724

@@ -51,33 +48,8 @@ class allocator<void> {
5148
};
5249
#endif // _LIBCPP_STD_VER <= 17
5350

54-
// This class provides a non-trivial default constructor to the class that derives from it
55-
// if the condition is satisfied.
56-
//
57-
// The second template parameter exists to allow giving a unique type to __non_trivial_if,
58-
// which makes it possible to avoid breaking the ABI when making this a base class of an
59-
// existing class. Without that, imagine we have classes D1 and D2, both of which used to
60-
// have no base classes, but which now derive from __non_trivial_if. The layout of a class
61-
// that inherits from both D1 and D2 will change because the two __non_trivial_if base
62-
// classes are not allowed to share the same address.
63-
//
64-
// By making those __non_trivial_if base classes unique, we work around this problem and
65-
// it is safe to start deriving from __non_trivial_if in existing classes.
66-
template <bool _Cond, class _Unique>
67-
struct __non_trivial_if {};
68-
69-
template <class _Unique>
70-
struct __non_trivial_if<true, _Unique> {
71-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __non_trivial_if() _NOEXCEPT {}
72-
};
73-
74-
// allocator
75-
//
76-
// Note: For ABI compatibility between C++20 and previous standards, we make
77-
// allocator<void> trivial in C++20.
78-
7951
template <class _Tp>
80-
class allocator : private __non_trivial_if<!is_void<_Tp>::value, allocator<_Tp> > {
52+
class allocator {
8153
static_assert(!is_const<_Tp>::value, "std::allocator does not support const types");
8254
static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types");
8355

0 commit comments

Comments
 (0)