Skip to content

Commit 1bdeb1b

Browse files
philnik777ldionne
authored andcommitted
[libc++] Remove vector base class
Remove the vector base class as suggested by @ldionne Reviewed By: ldionne, Quuxplusone, #libc Spies: libcxx-commits, ldionne Differential Revision: https://reviews.llvm.org/D117108 (cherry picked from commit b82da8b)
1 parent 8344ab9 commit 1bdeb1b

File tree

3 files changed

+44
-68
lines changed

3 files changed

+44
-68
lines changed

libcxx/include/__config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@
116116
# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
117117
// Remove basic_string common base
118118
# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
119+
// Remove vector base class
120+
# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
119121
#elif _LIBCPP_ABI_VERSION == 1
120122
# if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
121123
// Enable compiling copies of now inline methods into the dylib to support

libcxx/include/vector

Lines changed: 27 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -302,55 +302,10 @@ _LIBCPP_PUSH_MACROS
302302

303303
_LIBCPP_BEGIN_NAMESPACE_STD
304304

305-
template <bool>
306-
struct __vector_base_common;
307-
308-
template <>
309-
struct __vector_base_common<true> {
310-
// Both are defined in vector.cpp
311-
_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
312-
_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
313-
};
314-
315-
template <class _Tp, class _Allocator>
316-
class __vector_base
317-
: protected __vector_base_common<true> // This base class is historical, but it needs to remain for ABI compatibility
318-
{
319-
typedef _Allocator allocator_type;
320-
typedef typename allocator_traits<allocator_type>::pointer pointer;
321-
322-
protected:
323-
pointer __begin_;
324-
pointer __end_;
325-
__compressed_pair<pointer, allocator_type> __end_cap_;
326-
327-
_LIBCPP_INLINE_VISIBILITY
328-
__vector_base()
329-
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
330-
: __begin_(nullptr),
331-
__end_(nullptr),
332-
__end_cap_(nullptr, __default_init_tag()) {}
333-
334-
_LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a)
335-
: __begin_(nullptr),
336-
__end_(nullptr),
337-
__end_cap_(nullptr, __a) {}
338-
339-
#ifndef _LIBCPP_CXX03_LANG
340-
_LIBCPP_INLINE_VISIBILITY __vector_base(allocator_type&& __a) _NOEXCEPT
341-
: __begin_(nullptr),
342-
__end_(nullptr),
343-
__end_cap_(nullptr, _VSTD::move(__a)) {}
344-
#endif
345-
};
346-
347305
template <class _Tp, class _Allocator /* = allocator<_Tp> */>
348306
class _LIBCPP_TEMPLATE_VIS vector
349-
// This base class is historical, but it needs to remain for ABI compatibility.
350-
: private __vector_base<_Tp, _Allocator>
351307
{
352308
private:
353-
typedef __vector_base<_Tp, _Allocator> __base;
354309
typedef allocator<_Tp> __default_allocator_type;
355310
public:
356311
typedef vector __self;
@@ -382,7 +337,7 @@ public:
382337
#else
383338
_NOEXCEPT
384339
#endif
385-
: __base(__a)
340+
: __end_cap_(nullptr, __a)
386341
{
387342
_VSTD::__debug_db_insert_c(this);
388343
}
@@ -394,7 +349,7 @@ public:
394349

395350
template <class = __enable_if_t<__is_allocator<_Allocator>::value> >
396351
vector(size_type __n, const value_type& __x, const allocator_type& __a)
397-
: __base(__a)
352+
: __end_cap_(nullptr, __a)
398353
{
399354
_VSTD::__debug_db_insert_c(this);
400355
if (__n > 0)
@@ -691,6 +646,11 @@ public:
691646
#endif // _LIBCPP_DEBUG_LEVEL == 2
692647

693648
private:
649+
pointer __begin_ = nullptr;
650+
pointer __end_ = nullptr;
651+
__compressed_pair<pointer, allocator_type> __end_cap_ =
652+
__compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag());
653+
694654
_LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
695655
_LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
696656
void __vallocate(size_type __n);
@@ -859,20 +819,12 @@ private:
859819

860820
_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
861821
void __throw_length_error() const {
862-
#ifndef _LIBCPP_NO_EXCEPTIONS
863-
__vector_base_common<true>::__throw_length_error();
864-
#else
865-
_VSTD::abort();
866-
#endif
822+
_VSTD::__throw_length_error("vector");
867823
}
868824

869825
_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
870826
void __throw_out_of_range() const {
871-
#ifndef _LIBCPP_NO_EXCEPTIONS
872-
__vector_base_common<true>::__throw_out_of_range();
873-
#else
874-
_VSTD::abort();
875-
#endif
827+
_VSTD::__throw_out_of_range("vector");
876828
}
877829

878830
_LIBCPP_INLINE_VISIBILITY
@@ -1106,7 +1058,7 @@ vector<_Tp, _Allocator>::vector(size_type __n)
11061058
#if _LIBCPP_STD_VER > 11
11071059
template <class _Tp, class _Allocator>
11081060
vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1109-
: __base(__a)
1061+
: __end_cap_(nullptr, __a)
11101062
{
11111063
_VSTD::__debug_db_insert_c(this);
11121064
if (__n > 0)
@@ -1151,7 +1103,7 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, c
11511103
is_constructible<
11521104
value_type,
11531105
typename iterator_traits<_InputIterator>::reference>::value>::type*)
1154-
: __base(__a)
1106+
: __end_cap_(nullptr, __a)
11551107
{
11561108
_VSTD::__debug_db_insert_c(this);
11571109
for (; __first != __last; ++__first)
@@ -1183,7 +1135,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las
11831135
is_constructible<
11841136
value_type,
11851137
typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
1186-
: __base(__a)
1138+
: __end_cap_(nullptr, __a)
11871139
{
11881140
_VSTD::__debug_db_insert_c(this);
11891141
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
@@ -1196,7 +1148,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las
11961148

11971149
template <class _Tp, class _Allocator>
11981150
vector<_Tp, _Allocator>::vector(const vector& __x)
1199-
: __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1151+
: __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc()))
12001152
{
12011153
_VSTD::__debug_db_insert_c(this);
12021154
size_type __n = __x.size();
@@ -1209,7 +1161,7 @@ vector<_Tp, _Allocator>::vector(const vector& __x)
12091161

12101162
template <class _Tp, class _Allocator>
12111163
vector<_Tp, _Allocator>::vector(const vector& __x, const __identity_t<allocator_type>& __a)
1212-
: __base(__a)
1164+
: __end_cap_(nullptr, __a)
12131165
{
12141166
_VSTD::__debug_db_insert_c(this);
12151167
size_type __n = __x.size();
@@ -1230,7 +1182,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x)
12301182
#else
12311183
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
12321184
#endif
1233-
: __base(_VSTD::move(__x.__alloc()))
1185+
: __end_cap_(nullptr, _VSTD::move(__x.__alloc()))
12341186
{
12351187
_VSTD::__debug_db_insert_c(this);
12361188
#if _LIBCPP_DEBUG_LEVEL == 2
@@ -1245,7 +1197,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x)
12451197
template <class _Tp, class _Allocator>
12461198
inline _LIBCPP_INLINE_VISIBILITY
12471199
vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>& __a)
1248-
: __base(__a)
1200+
: __end_cap_(nullptr, __a)
12491201
{
12501202
_VSTD::__debug_db_insert_c(this);
12511203
if (__a == __x.__alloc())
@@ -1280,7 +1232,7 @@ vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
12801232
template <class _Tp, class _Allocator>
12811233
inline _LIBCPP_INLINE_VISIBILITY
12821234
vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1283-
: __base(__a)
1235+
: __end_cap_(nullptr, __a)
12841236
{
12851237
_VSTD::__debug_db_insert_c(this);
12861238
if (__il.size() > 0)
@@ -2079,7 +2031,6 @@ struct __has_storage_type<vector<bool, _Allocator> >
20792031

20802032
template <class _Allocator>
20812033
class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator>
2082-
: private __vector_base_common<true>
20832034
{
20842035
public:
20852036
typedef vector __self;
@@ -2348,6 +2299,16 @@ public:
23482299
bool __invariants() const;
23492300

23502301
private:
2302+
_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
2303+
void __throw_length_error() const {
2304+
_VSTD::__throw_length_error("vector");
2305+
}
2306+
2307+
_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
2308+
void __throw_out_of_range() const {
2309+
_VSTD::__throw_out_of_range("vector");
2310+
}
2311+
23512312
_LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
23522313
void __vallocate(size_type __n);
23532314
void __vdeallocate() _NOEXCEPT;

libcxx/src/vector.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,25 @@
1010

1111
_LIBCPP_BEGIN_NAMESPACE_STD
1212

13+
#ifndef _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
14+
15+
template <bool>
16+
struct __vector_base_common;
17+
18+
template <>
19+
struct __vector_base_common<true> {
20+
_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
21+
_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
22+
};
23+
1324
void __vector_base_common<true>::__throw_length_error() const {
14-
_VSTD::__throw_length_error("vector");
25+
_VSTD::__throw_length_error("vector");
1526
}
1627

1728
void __vector_base_common<true>::__throw_out_of_range() const {
18-
_VSTD::__throw_out_of_range("vector");
29+
_VSTD::__throw_out_of_range("vector");
1930
}
2031

32+
#endif // _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
33+
2134
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)