diff --git a/libcxx/include/__config b/libcxx/include/__config index adff13e714cb6..e6d167140c99a 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -168,6 +168,8 @@ // pointer from 16 to 8. This changes the output of std::string::max_size, // which makes it ABI breaking # define _LIBCPP_ABI_STRING_8_BYTE_ALIGNMENT +// Don't add padding from __compressed_pair +# define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING # elif _LIBCPP_ABI_VERSION == 1 # if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF)) // Enable compiling copies of now inline methods into the dylib to support diff --git a/libcxx/include/__functional/function.h b/libcxx/include/__functional/function.h index 6505bb5871739..e8c2b5040a7dd 100644 --- a/libcxx/include/__functional/function.h +++ b/libcxx/include/__functional/function.h @@ -138,45 +138,46 @@ class __default_alloc_func; template class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> { - __compressed_pair<_Fp, _Ap> __f_; + _LIBCPP_COMPRESSED_PAIR(_Fp, __func_, _Ap, __alloc_); public: typedef _LIBCPP_NODEBUG _Fp _Target; typedef _LIBCPP_NODEBUG _Ap _Alloc; - _LIBCPP_HIDE_FROM_ABI const _Target& __target() const { return __f_.first(); } + _LIBCPP_HIDE_FROM_ABI const _Target& __target() const { return __func_; } // WIN32 APIs may define __allocator, so use __get_allocator instead. - _LIBCPP_HIDE_FROM_ABI const _Alloc& __get_allocator() const { return __f_.second(); } + _LIBCPP_HIDE_FROM_ABI const _Alloc& __get_allocator() const { return __alloc_; } - _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(_Target&& __f) - : __f_(piecewise_construct, std::forward_as_tuple(std::move(__f)), std::forward_as_tuple()) {} + _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(_Target&& __f) : __func_(std::move(__f)), __alloc_() {} - _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(const _Target& __f, const _Alloc& __a) - : __f_(piecewise_construct, std::forward_as_tuple(__f), std::forward_as_tuple(__a)) {} + _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(const _Target& __f, const _Alloc& __a) : __func_(__f), __alloc_(__a) {} _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(const _Target& __f, _Alloc&& __a) - : __f_(piecewise_construct, std::forward_as_tuple(__f), std::forward_as_tuple(std::move(__a))) {} + : __func_(__f), __alloc_(std::move(__a)) {} _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(_Target&& __f, _Alloc&& __a) - : __f_(piecewise_construct, std::forward_as_tuple(std::move(__f)), std::forward_as_tuple(std::move(__a))) {} + : __func_(std::move(__f)), __alloc_(std::move(__a)) {} _LIBCPP_HIDE_FROM_ABI _Rp operator()(_ArgTypes&&... __arg) { typedef __invoke_void_return_wrapper<_Rp> _Invoker; - return _Invoker::__call(__f_.first(), std::forward<_ArgTypes>(__arg)...); + return _Invoker::__call(__func_, std::forward<_ArgTypes>(__arg)...); } _LIBCPP_HIDE_FROM_ABI __alloc_func* __clone() const { typedef allocator_traits<_Alloc> __alloc_traits; typedef __rebind_alloc<__alloc_traits, __alloc_func> _AA; - _AA __a(__f_.second()); + _AA __a(__alloc_); typedef __allocator_destructor<_AA> _Dp; unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a)); + ::new ((void*)__hold.get()) __alloc_func(__func_, _Alloc(__a)); return __hold.release(); } - _LIBCPP_HIDE_FROM_ABI void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); } + _LIBCPP_HIDE_FROM_ABI void destroy() _NOEXCEPT { + __func_.~_Fp(); + __alloc_.~_Alloc(); + } _LIBCPP_HIDE_FROM_ABI static void __destroy_and_delete(__alloc_func* __f) { typedef allocator_traits<_Alloc> __alloc_traits; diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table index 3cee48ef8538c..87fd2984aabb9 100644 --- a/libcxx/include/__hash_table +++ b/libcxx/include/__hash_table @@ -525,29 +525,29 @@ class __bucket_list_deallocator { typedef allocator_traits __alloc_traits; typedef typename __alloc_traits::size_type size_type; - __compressed_pair __data_; + _LIBCPP_COMPRESSED_PAIR(size_type, __data_, allocator_type, __alloc_); public: typedef typename __alloc_traits::pointer pointer; _LIBCPP_HIDE_FROM_ABI __bucket_list_deallocator() _NOEXCEPT_(is_nothrow_default_constructible::value) - : __data_(0, __default_init_tag()) {} + : __data_(0) {} _LIBCPP_HIDE_FROM_ABI __bucket_list_deallocator(const allocator_type& __a, size_type __size) _NOEXCEPT_(is_nothrow_copy_constructible::value) - : __data_(__size, __a) {} + : __data_(__size), __alloc_(__a) {} _LIBCPP_HIDE_FROM_ABI __bucket_list_deallocator(__bucket_list_deallocator&& __x) _NOEXCEPT_(is_nothrow_move_constructible::value) - : __data_(std::move(__x.__data_)) { + : __data_(std::move(__x.__data_)), __alloc_(std::move(__x.__alloc_)) { __x.size() = 0; } - _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __data_.first(); } - _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __data_.first(); } + _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __data_; } + _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __data_; } - _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return __data_.second(); } - _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { return __data_.second(); } + _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return __alloc_; } + _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { return __alloc_; } _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT { __alloc_traits::deallocate(__alloc(), __p, size()); } }; @@ -687,27 +687,27 @@ private: // --- Member data begin --- __bucket_list __bucket_list_; - __compressed_pair<__first_node, __node_allocator> __p1_; - __compressed_pair __p2_; - __compressed_pair __p3_; + _LIBCPP_COMPRESSED_PAIR(__first_node, __first_node_, __node_allocator, __node_alloc_); + _LIBCPP_COMPRESSED_PAIR(size_type, __size_, hasher, __hasher_); + _LIBCPP_COMPRESSED_PAIR(float, __max_load_factor_, key_equal, __key_eq_); // --- Member data end --- - _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __p2_.first(); } + _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __size_; } public: - _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __p2_.first(); } + _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size_; } - _LIBCPP_HIDE_FROM_ABI hasher& hash_function() _NOEXCEPT { return __p2_.second(); } - _LIBCPP_HIDE_FROM_ABI const hasher& hash_function() const _NOEXCEPT { return __p2_.second(); } + _LIBCPP_HIDE_FROM_ABI hasher& hash_function() _NOEXCEPT { return __hasher_; } + _LIBCPP_HIDE_FROM_ABI const hasher& hash_function() const _NOEXCEPT { return __hasher_; } - _LIBCPP_HIDE_FROM_ABI float& max_load_factor() _NOEXCEPT { return __p3_.first(); } - _LIBCPP_HIDE_FROM_ABI float max_load_factor() const _NOEXCEPT { return __p3_.first(); } + _LIBCPP_HIDE_FROM_ABI float& max_load_factor() _NOEXCEPT { return __max_load_factor_; } + _LIBCPP_HIDE_FROM_ABI float max_load_factor() const _NOEXCEPT { return __max_load_factor_; } - _LIBCPP_HIDE_FROM_ABI key_equal& key_eq() _NOEXCEPT { return __p3_.second(); } - _LIBCPP_HIDE_FROM_ABI const key_equal& key_eq() const _NOEXCEPT { return __p3_.second(); } + _LIBCPP_HIDE_FROM_ABI key_equal& key_eq() _NOEXCEPT { return __key_eq_; } + _LIBCPP_HIDE_FROM_ABI const key_equal& key_eq() const _NOEXCEPT { return __key_eq_; } - _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __p1_.second(); } - _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __p1_.second(); } + _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __node_alloc_; } + _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __node_alloc_; } public: typedef __hash_iterator<__node_pointer> iterator; @@ -991,26 +991,34 @@ inline __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table() _NOEXCEPT_( is_nothrow_default_constructible<__bucket_list>::value&& is_nothrow_default_constructible<__first_node>::value&& is_nothrow_default_constructible<__node_allocator>::value&& is_nothrow_default_constructible::value&& is_nothrow_default_constructible::value) - : __p2_(0, __default_init_tag()), __p3_(1.0f, __default_init_tag()) {} + : __size_(0), __max_load_factor_(1.0f) {} template inline __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, const key_equal& __eql) - : __bucket_list_(nullptr, __bucket_list_deleter()), __p1_(), __p2_(0, __hf), __p3_(1.0f, __eql) {} + : __bucket_list_(nullptr, __bucket_list_deleter()), + __first_node_(), + __node_alloc_(), + __size_(0), + __hasher_(__hf), + __max_load_factor_(1.0f), + __key_eq_(__eql) {} template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table( const hasher& __hf, const key_equal& __eql, const allocator_type& __a) : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), - __p1_(__default_init_tag(), __node_allocator(__a)), - __p2_(0, __hf), - __p3_(1.0f, __eql) {} + __node_alloc_(__node_allocator(__a)), + __size_(0), + __hasher_(__hf), + __max_load_factor_(1.0f), + __key_eq_(__eql) {} template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a) : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), - __p1_(__default_init_tag(), __node_allocator(__a)), - __p2_(0, __default_init_tag()), - __p3_(1.0f, __default_init_tag()) {} + __node_alloc_(__node_allocator(__a)), + __size_(0), + __max_load_factor_(1.0f) {} template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u) @@ -1018,17 +1026,20 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u) __bucket_list_deleter(allocator_traits<__pointer_allocator>::select_on_container_copy_construction( __u.__bucket_list_.get_deleter().__alloc()), 0)), - __p1_(__default_init_tag(), - allocator_traits<__node_allocator>::select_on_container_copy_construction(__u.__node_alloc())), - __p2_(0, __u.hash_function()), - __p3_(__u.__p3_) {} + __node_alloc_(allocator_traits<__node_allocator>::select_on_container_copy_construction(__u.__node_alloc())), + __size_(0), + __hasher_(__u.hash_function()), + __max_load_factor_(__u.__max_load_factor_), + __key_eq_(__u.__key_eq_) {} template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u, const allocator_type& __a) : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), - __p1_(__default_init_tag(), __node_allocator(__a)), - __p2_(0, __u.hash_function()), - __p3_(__u.__p3_) {} + __node_alloc_(__node_allocator(__a)), + __size_(0), + __hasher_(__u.hash_function()), + __max_load_factor_(__u.__max_load_factor_), + __key_eq_(__u.__key_eq_) {} template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) _NOEXCEPT_( @@ -1036,12 +1047,15 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) _NOEX is_nothrow_move_constructible<__node_allocator>::value&& is_nothrow_move_constructible::value&& is_nothrow_move_constructible::value) : __bucket_list_(std::move(__u.__bucket_list_)), - __p1_(std::move(__u.__p1_)), - __p2_(std::move(__u.__p2_)), - __p3_(std::move(__u.__p3_)) { + __first_node_(std::move(__u.__first_node_)), + __node_alloc_(std::move(__u.__node_alloc_)), + __size_(std::move(__u.__size_)), + __hasher_(std::move(__u.__hasher_)), + __max_load_factor_(__u.__max_load_factor_), + __key_eq_(std::move(__u.__key_eq_)) { if (size() > 0) { - __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); - __u.__p1_.first().__next_ = nullptr; + __bucket_list_[std::__constrain_hash(__first_node_.__next_->__hash(), bucket_count())] = __first_node_.__ptr(); + __u.__first_node_.__next_ = nullptr; __u.size() = 0; } } @@ -1049,17 +1063,19 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) _NOEX template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u, const allocator_type& __a) : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), - __p1_(__default_init_tag(), __node_allocator(__a)), - __p2_(0, std::move(__u.hash_function())), - __p3_(std::move(__u.__p3_)) { + __node_alloc_(__node_allocator(__a)), + __size_(0), + __hasher_(std::move(__u.__hasher_)), + __max_load_factor_(__u.__max_load_factor_), + __key_eq_(std::move(__u.__key_eq_)) { if (__a == allocator_type(__u.__node_alloc())) { __bucket_list_.reset(__u.__bucket_list_.release()); __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); __u.__bucket_list_.get_deleter().size() = 0; if (__u.size() > 0) { - __p1_.first().__next_ = __u.__p1_.first().__next_; - __u.__p1_.first().__next_ = nullptr; - __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); + __first_node_.__next_ = __u.__first_node_.__next_; + __u.__first_node_.__next_ = nullptr; + __bucket_list_[std::__constrain_hash(__first_node_.__next_->__hash(), bucket_count())] = __first_node_.__ptr(); size() = __u.size(); __u.size() = 0; } @@ -1073,7 +1089,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table() { static_assert((is_copy_constructible::value), "Hasher must be copy-constructible."); #endif - __deallocate_node(__p1_.first().__next_); + __deallocate_node(__first_node_.__next_); } template @@ -1119,8 +1135,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT { for (size_type __i = 0; __i < __bc; ++__i) __bucket_list_[__i] = nullptr; size() = 0; - __next_pointer __cache = __p1_.first().__next_; - __p1_.first().__next_ = nullptr; + __next_pointer __cache = __first_node_.__next_; + __first_node_.__next_ = nullptr; return __cache; } @@ -1137,10 +1153,10 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(__hash_table& __u, hash_function() = std::move(__u.hash_function()); max_load_factor() = __u.max_load_factor(); key_eq() = std::move(__u.key_eq()); - __p1_.first().__next_ = __u.__p1_.first().__next_; + __first_node_.__next_ = __u.__first_node_.__next_; if (size() > 0) { - __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); - __u.__p1_.first().__next_ = nullptr; + __bucket_list_[std::__constrain_hash(__first_node_.__next_->__hash(), bucket_count())] = __first_node_.__ptr(); + __u.__first_node_.__next_ = nullptr; __u.size() = 0; } } @@ -1257,7 +1273,7 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __f template inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT { - return iterator(__p1_.first().__next_); + return iterator(__first_node_.__next_); } template @@ -1269,7 +1285,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT { template inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT { - return const_iterator(__p1_.first().__next_); + return const_iterator(__first_node_.__next_); } template @@ -1281,8 +1297,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT { template void __hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT { if (size() > 0) { - __deallocate_node(__p1_.first().__next_); - __p1_.first().__next_ = nullptr; + __deallocate_node(__first_node_.__next_); + __first_node_.__next_ = nullptr; size_type __bc = bucket_count(); for (size_type __i = 0; __i < __bc; ++__i) __bucket_list_[__i] = nullptr; @@ -1334,7 +1350,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_perform(__node_po // insert_after __bucket_list_[__chash], or __first_node if bucket is null __next_pointer __pn = __bucket_list_[__chash]; if (__pn == nullptr) { - __pn = __p1_.first().__ptr(); + __pn = __first_node_.__ptr(); __nd->__next_ = __pn->__next_; __pn->__next_ = __nd->__ptr(); // fix up __bucket_list_ @@ -1414,7 +1430,7 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_perform( size_type __bc = bucket_count(); size_t __chash = std::__constrain_hash(__cp->__hash_, __bc); if (__pn == nullptr) { - __pn = __p1_.first().__ptr(); + __pn = __first_node_.__ptr(); __cp->__next_ = __pn->__next_; __pn->__next_ = __cp->__ptr(); // fix up __bucket_list_ @@ -1499,7 +1515,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& // insert_after __bucket_list_[__chash], or __first_node if bucket is null __next_pointer __pn = __bucket_list_[__chash]; if (__pn == nullptr) { - __pn = __p1_.first().__ptr(); + __pn = __first_node_.__ptr(); __h->__next_ = __pn->__next_; __pn->__next_ = __h.get()->__ptr(); // fix up __bucket_list_ @@ -1677,7 +1693,7 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__do_rehash(size_type __nbc) { if (__nbc > 0) { for (size_type __i = 0; __i < __nbc; ++__i) __bucket_list_[__i] = nullptr; - __next_pointer __pp = __p1_.first().__ptr(); + __next_pointer __pp = __first_node_.__ptr(); __next_pointer __cp = __pp->__next_; if (__cp != nullptr) { size_type __chash = std::__constrain_hash(__cp->__hash(), __nbc); @@ -1854,7 +1870,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT { // Fix up __bucket_list_ // if __pn is not in same bucket (before begin is not in same bucket) && // if __cn->__next_ is not in same bucket (nullptr is not in same bucket) - if (__pn == __p1_.first().__ptr() || std::__constrain_hash(__pn->__hash(), __bc) != __chash) { + if (__pn == __first_node_.__ptr() || std::__constrain_hash(__pn->__hash(), __bc) != __chash) { if (__cn->__next_ == nullptr || std::__constrain_hash(__cn->__next_->__hash(), __bc) != __chash) __bucket_list_[__chash] = nullptr; } @@ -1973,14 +1989,17 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) std::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size()); std::__swap_allocator(__bucket_list_.get_deleter().__alloc(), __u.__bucket_list_.get_deleter().__alloc()); std::__swap_allocator(__node_alloc(), __u.__node_alloc()); - std::swap(__p1_.first().__next_, __u.__p1_.first().__next_); - __p2_.swap(__u.__p2_); - __p3_.swap(__u.__p3_); + std::swap(__first_node_.__next_, __u.__first_node_.__next_); + using std::swap; + swap(__size_, __u.__size_); + swap(__hasher_, __u.__hasher_); + swap(__max_load_factor_, __u.__max_load_factor_); + swap(__key_eq_, __u.__key_eq_); if (size() > 0) - __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); + __bucket_list_[std::__constrain_hash(__first_node_.__next_->__hash(), bucket_count())] = __first_node_.__ptr(); if (__u.size() > 0) - __u.__bucket_list_[std::__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] = - __u.__p1_.first().__ptr(); + __u.__bucket_list_[std::__constrain_hash(__u.__first_node_.__next_->__hash(), __u.bucket_count())] = + __u.__first_node_.__ptr(); } template diff --git a/libcxx/include/__memory/compressed_pair.h b/libcxx/include/__memory/compressed_pair.h index e9faada2f0b23..144521bb0357c 100644 --- a/libcxx/include/__memory/compressed_pair.h +++ b/libcxx/include/__memory/compressed_pair.h @@ -11,161 +11,39 @@ #define _LIBCPP___MEMORY_COMPRESSED_PAIR_H #include <__config> -#include <__fwd/get.h> -#include <__fwd/tuple.h> -#include <__tuple/tuple_indices.h> -#include <__type_traits/decay.h> -#include <__type_traits/dependent_type.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_default_constructible.h> +#include <__type_traits/datasizeof.h> #include <__type_traits/is_empty.h> #include <__type_traits/is_final.h> -#include <__type_traits/is_same.h> -#include <__type_traits/is_swappable.h> -#include <__utility/forward.h> -#include <__utility/move.h> -#include <__utility/piecewise_construct.h> -#include +#include <__type_traits/is_object.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - _LIBCPP_BEGIN_NAMESPACE_STD -// Tag used to default initialize one or both of the pair's elements. -struct __default_init_tag {}; -struct __value_init_tag {}; - -template ::value && !__libcpp_is_final<_Tp>::value> -struct __compressed_pair_elem { - using _ParamT = _Tp; - using reference = _Tp&; - using const_reference = const _Tp&; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_() {} - - template >::value> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(_Up&& __u) - : __value_(std::forward<_Up>(__u)) {} - -#ifndef _LIBCPP_CXX03_LANG - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 explicit __compressed_pair_elem( - piecewise_construct_t, tuple<_Args...> __args, __tuple_indices<_Indices...>) - : __value_(std::forward<_Args>(std::get<_Indices>(__args))...) {} -#endif - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference __get() _NOEXCEPT { return __value_; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return __value_; } - -private: - _Tp __value_; -}; - -template -struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp { - using _ParamT = _Tp; - using reference = _Tp&; - using const_reference = const _Tp&; - using __value_type = _Tp; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem() = default; - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_type() {} - - template >::value> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(_Up&& __u) - : __value_type(std::forward<_Up>(__u)) {} - -#ifndef _LIBCPP_CXX03_LANG - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 - __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, __tuple_indices<_Indices...>) - : __value_type(std::forward<_Args>(std::get<_Indices>(__args))...) {} -#endif - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference __get() _NOEXCEPT { return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return *this; } -}; - -template -class __compressed_pair : private __compressed_pair_elem<_T1, 0>, private __compressed_pair_elem<_T2, 1> { -public: - // NOTE: This static assert should never fire because __compressed_pair - // is *almost never* used in a scenario where it's possible for T1 == T2. - // (The exception is std::function where it is possible that the function - // object and the allocator have the same type). - static_assert( - (!is_same<_T1, _T2>::value), - "__compressed_pair cannot be instantiated when T1 and T2 are the same type; " - "The current implementation is NOT ABI-compatible with the previous implementation for this configuration"); - - using _Base1 _LIBCPP_NODEBUG = __compressed_pair_elem<_T1, 0>; - using _Base2 _LIBCPP_NODEBUG = __compressed_pair_elem<_T2, 1>; - - template , _Dummy>::value && - __dependent_type, _Dummy>::value > > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair() - : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {} - - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair(_U1&& __t1, _U2&& __t2) - : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {} - -#ifndef _LIBCPP_CXX03_LANG - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 explicit __compressed_pair( - piecewise_construct_t __pc, tuple<_Args1...> __first_args, tuple<_Args2...> __second_args) - : _Base1(__pc, std::move(__first_args), typename __make_tuple_indices::type()), - _Base2(__pc, std::move(__second_args), typename __make_tuple_indices::type()) {} -#endif - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename _Base1::reference first() _NOEXCEPT { - return static_cast<_Base1&>(*this).__get(); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename _Base1::const_reference first() const _NOEXCEPT { - return static_cast<_Base1 const&>(*this).__get(); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename _Base2::reference second() _NOEXCEPT { - return static_cast<_Base2&>(*this).__get(); - } +#ifndef _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename _Base2::const_reference second() const _NOEXCEPT { - return static_cast<_Base2 const&>(*this).__get(); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static _Base1* __get_first_base(__compressed_pair* __pair) _NOEXCEPT { - return static_cast<_Base1*>(__pair); - } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static _Base2* __get_second_base(__compressed_pair* __pair) _NOEXCEPT { - return static_cast<_Base2*>(__pair); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void swap(__compressed_pair& __x) - _NOEXCEPT_(__is_nothrow_swappable<_T1>::value&& __is_nothrow_swappable<_T2>::value) { - using std::swap; - swap(first(), __x.first()); - swap(second(), __x.second()); - } +template +class __compressed_pair_padding { + char __padding_[(!is_object<_ToPad>::value || (is_empty<_ToPad>::value && !__libcpp_is_final<_ToPad>::value)) + ? 0 + : sizeof(_ToPad) - __libcpp_datasizeof<_ToPad>::value]; }; -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void -swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) - _NOEXCEPT_(__is_nothrow_swappable<_T1>::value&& __is_nothrow_swappable<_T2>::value) { - __x.swap(__y); -} +# define _LIBCPP_COMPRESSED_PAIR_PADDING(T, Name) _LIBCPP_NO_UNIQUE_ADDRESS __compressed_pair_padding Name +# define _LIBCPP_COMPRESSED_PAIR(T1, Name1, T2, Name2) \ + [[__gnu__::__aligned__(_LIBCPP_ALIGNOF(T2))]] _LIBCPP_NO_UNIQUE_ADDRESS T1 Name1; \ + _LIBCPP_COMPRESSED_PAIR_PADDING(T1, Name1##_padding_); \ + _LIBCPP_NO_UNIQUE_ADDRESS T2 Name2; \ + _LIBCPP_COMPRESSED_PAIR_PADDING(T2, Name2##_padding_) +#else +# define _LIBCPP_COMPRESSED_PAIR_PADDING(T, Name) +# define _LIBCPP_COMPRESSED_PAIR(T1, Name1, T2, Name2) \ + _LIBCPP_NO_UNIQUE_ADDRESS T1 Name1; \ + _LIBCPP_NO_UNIQUE_ADDRESS T2 Name2; +#endif // _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING _LIBCPP_END_NAMESPACE_STD -_LIBCPP_POP_MACROS - #endif // _LIBCPP___MEMORY_COMPRESSED_PAIR_H diff --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h index 9aa938b220312..e4e0fde94f269 100644 --- a/libcxx/include/__memory/shared_ptr.h +++ b/libcxx/include/__memory/shared_ptr.h @@ -196,11 +196,17 @@ class _LIBCPP_EXPORTED_FROM_ABI __shared_weak_count : private __shared_count { template class __shared_ptr_pointer : public __shared_weak_count { - __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_; + [[using __gnu__: __aligned__(_LIBCPP_ALIGNOF(_Dp)), + __aligned__(_LIBCPP_ALIGNOF(_Alloc))]] _LIBCPP_NO_UNIQUE_ADDRESS _Tp __ptr_; + _LIBCPP_COMPRESSED_PAIR_PADDING(_Tp, __ptr_padding_); + _LIBCPP_NO_UNIQUE_ADDRESS _Dp __deleter_; + _LIBCPP_COMPRESSED_PAIR_PADDING(_Dp, __deleter_padding_); + _LIBCPP_NO_UNIQUE_ADDRESS _Alloc __alloc_; + _LIBCPP_COMPRESSED_PAIR_PADDING(_Alloc, __alloc_padding_); public: _LIBCPP_HIDE_FROM_ABI __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a) - : __data_(__compressed_pair<_Tp, _Dp>(__p, std::move(__d)), std::move(__a)) {} + : __ptr_(__p), __deleter_(std::move(__d)), __alloc_(std::move(__a)) {} #ifndef _LIBCPP_HAS_NO_RTTI _LIBCPP_HIDE_FROM_ABI_VIRTUAL const void* __get_deleter(const type_info&) const _NOEXCEPT override; @@ -215,15 +221,15 @@ class __shared_ptr_pointer : public __shared_weak_count { template const void* __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT { - return __t == typeid(_Dp) ? std::addressof(__data_.first().second()) : nullptr; + return __t == typeid(_Dp) ? std::addressof(__deleter_) : nullptr; } #endif // _LIBCPP_HAS_NO_RTTI template void __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT { - __data_.first().second()(__data_.first().first()); - __data_.first().second().~_Dp(); + __deleter_(__ptr_); + __deleter_.~_Dp(); } template @@ -232,8 +238,8 @@ void __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT { typedef allocator_traits<_Al> _ATraits; typedef pointer_traits _PTraits; - _Al __a(__data_.second()); - __data_.second().~_Alloc(); + _Al __a(__alloc_); + __alloc_.~_Alloc(); __a.deallocate(_PTraits::pointer_to(*this), 1); } @@ -299,28 +305,19 @@ struct __shared_ptr_emplace : __shared_weak_count { // with Allocator construction for _Tp. To allow implementing P0674 in C++20, // we now use a properly aligned char buffer while making sure that we maintain // the same layout that we had when we used a compressed pair. - using _CompressedPair = __compressed_pair<_Alloc, _Tp>; - struct _ALIGNAS_TYPE(_CompressedPair) _Storage { - char __blob_[sizeof(_CompressedPair)]; + struct [[using __gnu__: __aligned__(_LIBCPP_ALIGNOF(_Alloc)), __aligned__(_LIBCPP_ALIGNOF(_Tp))]] _Storage { + union { + struct { + _LIBCPP_COMPRESSED_PAIR(_Alloc, __alloc_, _Tp, __elem_); + }; + }; _LIBCPP_HIDE_FROM_ABI explicit _Storage(_Alloc&& __a) { ::new ((void*)__get_alloc()) _Alloc(std::move(__a)); } _LIBCPP_HIDE_FROM_ABI ~_Storage() { __get_alloc()->~_Alloc(); } - _LIBCPP_HIDE_FROM_ABI _Alloc* __get_alloc() _NOEXCEPT { - _CompressedPair* __as_pair = reinterpret_cast<_CompressedPair*>(__blob_); - typename _CompressedPair::_Base1* __first = _CompressedPair::__get_first_base(__as_pair); - _Alloc* __alloc = reinterpret_cast<_Alloc*>(__first); - return __alloc; - } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _Tp* __get_elem() _NOEXCEPT { - _CompressedPair* __as_pair = reinterpret_cast<_CompressedPair*>(__blob_); - typename _CompressedPair::_Base2* __second = _CompressedPair::__get_second_base(__as_pair); - _Tp* __elem = reinterpret_cast<_Tp*>(__second); - return __elem; - } + _LIBCPP_HIDE_FROM_ABI _Alloc* __get_alloc() _NOEXCEPT { return std::addressof(__alloc_); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _Tp* __get_elem() _NOEXCEPT { return std::addressof(__elem_); } }; - static_assert(_LIBCPP_ALIGNOF(_Storage) == _LIBCPP_ALIGNOF(_CompressedPair), ""); - static_assert(sizeof(_Storage) == sizeof(_CompressedPair), ""); _Storage __storage_; }; diff --git a/libcxx/include/__memory/unique_ptr.h b/libcxx/include/__memory/unique_ptr.h index db473eaa50a6b..279447af41461 100644 --- a/libcxx/include/__memory/unique_ptr.h +++ b/libcxx/include/__memory/unique_ptr.h @@ -130,7 +130,7 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr { static_assert(!is_rvalue_reference::value, "the specified deleter type cannot be an rvalue reference"); private: - __compressed_pair __ptr_; + _LIBCPP_COMPRESSED_PAIR(pointer, __ptr_, deleter_type, __deleter_); typedef _LIBCPP_NODEBUG __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; @@ -164,23 +164,25 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr { public: template > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(), __deleter_() {} template > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT - : __ptr_(__value_init_tag(), __value_init_tag()) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(), __deleter_() {} template > _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit unique_ptr(pointer __p) _NOEXCEPT - : __ptr_(__p, __value_init_tag()) {} + : __ptr_(__p), + __deleter_() {} template > > _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPT - : __ptr_(__p, __d) {} + : __ptr_(__p), + __deleter_(__d) {} template > > _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT - : __ptr_(__p, std::move(__d)) { + : __ptr_(__p), + __deleter_(std::move(__d)) { static_assert(!is_reference::value, "rvalue deleter bound to reference"); } @@ -188,24 +190,26 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr { _LIBCPP_HIDE_FROM_ABI unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete; _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr&& __u) _NOEXCEPT - : __ptr_(__u.release(), std::forward(__u.get_deleter())) {} + : __ptr_(__u.release()), + __deleter_(std::forward(__u.get_deleter())) {} template , _Up>, class = _EnableIfDeleterConvertible<_Ep> > _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT - : __ptr_(__u.release(), std::forward<_Ep>(__u.get_deleter())) {} + : __ptr_(__u.release()), + __deleter_(std::forward<_Ep>(__u.get_deleter())) {} #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) template ::value && is_same<_Dp, default_delete<_Tp> >::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI unique_ptr(auto_ptr<_Up>&& __p) _NOEXCEPT : __ptr_(__p.release(), __value_init_tag()) {} + _LIBCPP_HIDE_FROM_ABI unique_ptr(auto_ptr<_Up>&& __p) _NOEXCEPT : __ptr_(__p.release()), __deleter_() {} #endif _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { reset(__u.release()); - __ptr_.second() = std::forward(__u.get_deleter()); + __deleter_ = std::forward(__u.get_deleter()); return *this; } @@ -215,7 +219,7 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr { class = _EnableIfDeleterAssignable<_Ep> > _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { reset(__u.release()); - __ptr_.second() = std::forward<_Ep>(__u.get_deleter()); + __deleter_ = std::forward<_Ep>(__u.get_deleter()); return *this; } @@ -241,32 +245,36 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr { } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __add_lvalue_reference_t<_Tp> operator*() const { - return *__ptr_.first(); + return *__ptr_; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer operator->() const _NOEXCEPT { return __ptr_.first(); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT { return __ptr_.first(); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 deleter_type& get_deleter() _NOEXCEPT { return __ptr_.second(); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer operator->() const _NOEXCEPT { return __ptr_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT { return __ptr_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 deleter_type& get_deleter() _NOEXCEPT { return __deleter_; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const deleter_type& get_deleter() const _NOEXCEPT { - return __ptr_.second(); + return __deleter_; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit operator bool() const _NOEXCEPT { - return __ptr_.first() != nullptr; + return __ptr_ != nullptr; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer release() _NOEXCEPT { - pointer __t = __ptr_.first(); - __ptr_.first() = pointer(); + pointer __t = __ptr_; + __ptr_ = pointer(); return __t; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void reset(pointer __p = pointer()) _NOEXCEPT { - pointer __tmp = __ptr_.first(); - __ptr_.first() = __p; + pointer __tmp = __ptr_; + __ptr_ = __p; if (__tmp) - __ptr_.second()(__tmp); + __deleter_(__tmp); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void swap(unique_ptr& __u) _NOEXCEPT { __ptr_.swap(__u.__ptr_); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void swap(unique_ptr& __u) _NOEXCEPT { + using std::swap; + swap(__ptr_, __u.__ptr_); + swap(__deleter_, __u.__deleter_); + } }; template @@ -277,7 +285,7 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> typedef typename __pointer<_Tp, deleter_type>::type pointer; private: - __compressed_pair __ptr_; + _LIBCPP_COMPRESSED_PAIR(pointer, __ptr_, deleter_type, __deleter_); template struct _CheckArrayPointerConversion : is_same<_From, pointer> {}; @@ -326,42 +334,46 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> public: template > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(), __deleter_() {} template > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT - : __ptr_(__value_init_tag(), __value_init_tag()) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(), __deleter_() {} template , class = _EnableIfPointerConvertible<_Pp> > _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit unique_ptr(_Pp __p) _NOEXCEPT - : __ptr_(__p, __value_init_tag()) {} + : __ptr_(__p), + __deleter_() {} template >, class = _EnableIfPointerConvertible<_Pp> > _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) _NOEXCEPT - : __ptr_(__p, __d) {} + : __ptr_(__p), + __deleter_(__d) {} template > > _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) _NOEXCEPT - : __ptr_(nullptr, __d) {} + : __ptr_(nullptr), + __deleter_(__d) {} template >, class = _EnableIfPointerConvertible<_Pp> > _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT - : __ptr_(__p, std::move(__d)) { + : __ptr_(__p), + __deleter_(std::move(__d)) { static_assert(!is_reference::value, "rvalue deleter bound to reference"); } template > > _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) _NOEXCEPT - : __ptr_(nullptr, std::move(__d)) { + : __ptr_(nullptr), + __deleter_(std::move(__d)) { static_assert(!is_reference::value, "rvalue deleter bound to reference"); } @@ -372,11 +384,12 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> _LIBCPP_HIDE_FROM_ABI unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete; _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr&& __u) _NOEXCEPT - : __ptr_(__u.release(), std::forward(__u.get_deleter())) {} + : __ptr_(__u.release()), + __deleter_(std::forward(__u.get_deleter())) {} _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { reset(__u.release()); - __ptr_.second() = std::forward(__u.get_deleter()); + __deleter_ = std::forward(__u.get_deleter()); return *this; } @@ -385,7 +398,8 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> class = _EnableIfMoveConvertible, _Up>, class = _EnableIfDeleterConvertible<_Ep> > _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT - : __ptr_(__u.release(), std::forward<_Ep>(__u.get_deleter())) {} + : __ptr_(__u.release()), + __deleter_(std::forward<_Ep>(__u.get_deleter())) {} template class = _EnableIfDeleterAssignable<_Ep> > _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { reset(__u.release()); - __ptr_.second() = std::forward<_Ep>(__u.get_deleter()); + __deleter_ = std::forward<_Ep>(__u.get_deleter()); return *this; } @@ -411,41 +425,45 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __add_lvalue_reference_t<_Tp> operator[](size_t __i) const { - return __ptr_.first()[__i]; + return __ptr_[__i]; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT { return __ptr_.first(); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT { return __ptr_; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 deleter_type& get_deleter() _NOEXCEPT { return __ptr_.second(); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 deleter_type& get_deleter() _NOEXCEPT { return __deleter_; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const deleter_type& get_deleter() const _NOEXCEPT { - return __ptr_.second(); + return __deleter_; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit operator bool() const _NOEXCEPT { - return __ptr_.first() != nullptr; + return __ptr_ != nullptr; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer release() _NOEXCEPT { - pointer __t = __ptr_.first(); - __ptr_.first() = pointer(); + pointer __t = __ptr_; + __ptr_ = pointer(); return __t; } template ::value, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void reset(_Pp __p) _NOEXCEPT { - pointer __tmp = __ptr_.first(); - __ptr_.first() = __p; + pointer __tmp = __ptr_; + __ptr_ = __p; if (__tmp) - __ptr_.second()(__tmp); + __deleter_(__tmp); } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void reset(nullptr_t = nullptr) _NOEXCEPT { - pointer __tmp = __ptr_.first(); - __ptr_.first() = nullptr; + pointer __tmp = __ptr_; + __ptr_ = nullptr; if (__tmp) - __ptr_.second()(__tmp); + __deleter_(__tmp); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void swap(unique_ptr& __u) _NOEXCEPT { __ptr_.swap(__u.__ptr_); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void swap(unique_ptr& __u) _NOEXCEPT { + using std::swap; + swap(__ptr_, __u.__ptr_); + swap(__deleter_, __u.__deleter_); + } }; template ::value, int> = 0> diff --git a/libcxx/include/__split_buffer b/libcxx/include/__split_buffer index aaf955685d2d3..bf6324611e0c9 100644 --- a/libcxx/include/__split_buffer +++ b/libcxx/include/__split_buffer @@ -68,7 +68,7 @@ public: pointer __first_; pointer __begin_; pointer __end_; - __compressed_pair __end_cap_; + _LIBCPP_COMPRESSED_PAIR(pointer, __end_cap_, allocator_type, __alloc_); using __alloc_ref = __add_lvalue_reference_t; using __alloc_const_ref = __add_lvalue_reference_t; @@ -78,13 +78,13 @@ public: _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __split_buffer() _NOEXCEPT_(is_nothrow_default_constructible::value) - : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __default_init_tag()) {} + : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr) {} _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit __split_buffer(__alloc_rr& __a) - : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a) {} + : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr), __alloc_(__a) {} _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit __split_buffer(const __alloc_rr& __a) - : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a) {} + : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr), __alloc_(__a) {} _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __split_buffer(size_type __cap, size_type __start, __alloc_rr& __a); @@ -101,15 +101,11 @@ public: _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~__split_buffer(); - _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __alloc_rr& __alloc() _NOEXCEPT { return __end_cap_.second(); } - _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const __alloc_rr& __alloc() const _NOEXCEPT { - return __end_cap_.second(); - } + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __alloc_rr& __alloc() _NOEXCEPT { return __alloc_; } + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const __alloc_rr& __alloc() const _NOEXCEPT { return __alloc_; } - _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer& __end_cap() _NOEXCEPT { return __end_cap_.first(); } - _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const pointer& __end_cap() const _NOEXCEPT { - return __end_cap_.first(); - } + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer& __end_cap() _NOEXCEPT { return __end_cap_; } + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const pointer& __end_cap() const _NOEXCEPT { return __end_cap_; } _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __begin_; } _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __begin_; } @@ -336,7 +332,7 @@ __split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, true_type template _LIBCPP_CONSTEXPR_SINCE_CXX20 __split_buffer<_Tp, _Allocator>::__split_buffer(size_type __cap, size_type __start, __alloc_rr& __a) - : __end_cap_(nullptr, __a) { + : __end_cap_(nullptr), __alloc_(__a) { if (__cap == 0) { __first_ = nullptr; } else { @@ -361,7 +357,8 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 __split_buffer<_Tp, _Allocator>::__split_buffer(__ : __first_(std::move(__c.__first_)), __begin_(std::move(__c.__begin_)), __end_(std::move(__c.__end_)), - __end_cap_(std::move(__c.__end_cap_)) { + __end_cap_(std::move(__c.__end_cap_)), + __alloc_(std::move(__c.__alloc_)) { __c.__first_ = nullptr; __c.__begin_ = nullptr; __c.__end_ = nullptr; @@ -371,7 +368,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 __split_buffer<_Tp, _Allocator>::__split_buffer(__ template _LIBCPP_CONSTEXPR_SINCE_CXX20 __split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c, const __alloc_rr& __a) - : __end_cap_(nullptr, __a) { + : __end_cap_(nullptr), __alloc_(__a) { if (__a == __c.__alloc()) { __first_ = __c.__first_; __begin_ = __c.__begin_; diff --git a/libcxx/include/__tree b/libcxx/include/__tree index 2dcc3c614d366..cf9c017ccf26b 100644 --- a/libcxx/include/__tree +++ b/libcxx/include/__tree @@ -938,21 +938,21 @@ private: private: __iter_pointer __begin_node_; - __compressed_pair<__end_node_t, __node_allocator> __pair1_; - __compressed_pair __pair3_; + _LIBCPP_COMPRESSED_PAIR(__end_node_t, __end_node_, __node_allocator, __node_alloc_); + _LIBCPP_COMPRESSED_PAIR(size_type, __size_, value_compare, __value_comp_); public: _LIBCPP_HIDE_FROM_ABI __iter_pointer __end_node() _NOEXCEPT { - return static_cast<__iter_pointer>(pointer_traits<__end_node_ptr>::pointer_to(__pair1_.first())); + return static_cast<__iter_pointer>(pointer_traits<__end_node_ptr>::pointer_to(__end_node_)); } _LIBCPP_HIDE_FROM_ABI __iter_pointer __end_node() const _NOEXCEPT { return static_cast<__iter_pointer>( - pointer_traits<__end_node_ptr>::pointer_to(const_cast<__end_node_t&>(__pair1_.first()))); + pointer_traits<__end_node_ptr>::pointer_to(const_cast<__end_node_t&>(__end_node_))); } - _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __pair1_.second(); } + _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __node_alloc_; } private: - _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __pair1_.second(); } + _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __node_alloc_; } _LIBCPP_HIDE_FROM_ABI __iter_pointer& __begin_node() _NOEXCEPT { return __begin_node_; } _LIBCPP_HIDE_FROM_ABI const __iter_pointer& __begin_node() const _NOEXCEPT { return __begin_node_; } @@ -960,12 +960,12 @@ public: _LIBCPP_HIDE_FROM_ABI allocator_type __alloc() const _NOEXCEPT { return allocator_type(__node_alloc()); } private: - _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __pair3_.first(); } + _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __size_; } public: - _LIBCPP_HIDE_FROM_ABI const size_type& size() const _NOEXCEPT { return __pair3_.first(); } - _LIBCPP_HIDE_FROM_ABI value_compare& value_comp() _NOEXCEPT { return __pair3_.second(); } - _LIBCPP_HIDE_FROM_ABI const value_compare& value_comp() const _NOEXCEPT { return __pair3_.second(); } + _LIBCPP_HIDE_FROM_ABI const size_type& size() const _NOEXCEPT { return __size_; } + _LIBCPP_HIDE_FROM_ABI value_compare& value_comp() _NOEXCEPT { return __value_comp_; } + _LIBCPP_HIDE_FROM_ABI const value_compare& value_comp() const _NOEXCEPT { return __value_comp_; } public: _LIBCPP_HIDE_FROM_ABI __node_pointer __root() const _NOEXCEPT { @@ -1331,21 +1331,19 @@ private: template __tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp) _NOEXCEPT_( is_nothrow_default_constructible<__node_allocator>::value&& is_nothrow_copy_constructible::value) - : __pair3_(0, __comp) { + : __size_(0), __value_comp_(__comp) { __begin_node() = __end_node(); } template __tree<_Tp, _Compare, _Allocator>::__tree(const allocator_type& __a) - : __begin_node_(__iter_pointer()), - __pair1_(__default_init_tag(), __node_allocator(__a)), - __pair3_(0, __default_init_tag()) { + : __begin_node_(__iter_pointer()), __node_alloc_(__node_allocator(__a)), __size_(0) { __begin_node() = __end_node(); } template __tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp, const allocator_type& __a) - : __begin_node_(__iter_pointer()), __pair1_(__default_init_tag(), __node_allocator(__a)), __pair3_(0, __comp) { + : __begin_node_(__iter_pointer()), __node_alloc_(__node_allocator(__a)), __size_(0), __value_comp_(__comp) { __begin_node() = __end_node(); } @@ -1444,8 +1442,9 @@ void __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _ template __tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t) : __begin_node_(__iter_pointer()), - __pair1_(__default_init_tag(), __node_traits::select_on_container_copy_construction(__t.__node_alloc())), - __pair3_(0, __t.value_comp()) { + __node_alloc_(__node_traits::select_on_container_copy_construction(__t.__node_alloc())), + __size_(0), + __value_comp_(__t.value_comp()) { __begin_node() = __end_node(); } @@ -1453,8 +1452,10 @@ template __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) _NOEXCEPT_( is_nothrow_move_constructible<__node_allocator>::value&& is_nothrow_move_constructible::value) : __begin_node_(std::move(__t.__begin_node_)), - __pair1_(std::move(__t.__pair1_)), - __pair3_(std::move(__t.__pair3_)) { + __end_node_(std::move(__t.__end_node_)), + __node_alloc_(std::move(__t.__node_alloc_)), + __size_(__t.__size_), + __value_comp_(std::move(__t.__value_comp_)) { if (size() == 0) __begin_node() = __end_node(); else { @@ -1467,7 +1468,7 @@ __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) _NOEXCEPT_( template __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __a) - : __pair1_(__default_init_tag(), __node_allocator(__a)), __pair3_(0, std::move(__t.value_comp())) { + : __node_alloc_(__node_allocator(__a)), __size_(0), __value_comp_(std::move(__t.value_comp())) { if (__a == __t.__alloc()) { if (__t.size() == 0) __begin_node() = __end_node(); @@ -1489,10 +1490,11 @@ template void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value&& is_nothrow_move_assignable<__node_allocator>::value) { destroy(static_cast<__node_pointer>(__end_node()->__left_)); - __begin_node_ = __t.__begin_node_; - __pair1_.first() = __t.__pair1_.first(); + __begin_node_ = __t.__begin_node_; + __end_node_ = __t.__end_node_; __move_assign_alloc(__t); - __pair3_ = std::move(__t.__pair3_); + __size_ = __t.__size_; + __value_comp_ = std::move(__t.__value_comp_); if (size() == 0) __begin_node() = __end_node(); else { @@ -1561,9 +1563,10 @@ void __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t) { using std::swap; swap(__begin_node_, __t.__begin_node_); - swap(__pair1_.first(), __t.__pair1_.first()); + swap(__end_node_, __t.__end_node_); std::__swap_allocator(__node_alloc(), __t.__node_alloc()); - __pair3_.swap(__t.__pair3_); + swap(__size_, __t.__size_); + swap(__value_comp_, __t.__value_comp_); if (size() == 0) __begin_node() = __end_node(); else diff --git a/libcxx/include/deque b/libcxx/include/deque index fca8b3d6e2c73..7d5293b8dc725 100644 --- a/libcxx/include/deque +++ b/libcxx/include/deque @@ -552,12 +552,12 @@ private: __map __map_; size_type __start_; - __compressed_pair __size_; + _LIBCPP_COMPRESSED_PAIR(size_type, __size_, allocator_type, __alloc_); public: // construct/copy/destroy: _LIBCPP_HIDE_FROM_ABI deque() _NOEXCEPT_(is_nothrow_default_constructible::value) - : __start_(0), __size_(0, __default_init_tag()) { + : __start_(0), __size_(0) { __annotate_new(0); } @@ -571,7 +571,7 @@ public: } _LIBCPP_HIDE_FROM_ABI explicit deque(const allocator_type& __a) - : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) { + : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) { __annotate_new(0); } @@ -583,7 +583,7 @@ public: template ::value> > _LIBCPP_HIDE_FROM_ABI deque(size_type __n, const value_type& __v, const allocator_type& __a) - : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) { + : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) { __annotate_new(0); if (__n > 0) __append(__n, __v); @@ -597,7 +597,7 @@ public: #if _LIBCPP_STD_VER >= 23 template <_ContainerCompatibleRange<_Tp> _Range> _LIBCPP_HIDE_FROM_ABI deque(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type()) - : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) { + : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) { if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { __append_with_size(ranges::begin(__range), ranges::distance(__range)); @@ -660,8 +660,8 @@ public: _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const value_type& __v); _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT; - _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return __size_.second(); } - _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { return __size_.second(); } + _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return __alloc_; } + _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { return __alloc_; } // iterators: @@ -700,8 +700,8 @@ public: // capacity: _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size(); } - _LIBCPP_HIDE_FROM_ABI size_type& __size() _NOEXCEPT { return __size_.first(); } - _LIBCPP_HIDE_FROM_ABI const size_type& __size() const _NOEXCEPT { return __size_.first(); } + _LIBCPP_HIDE_FROM_ABI size_type& __size() _NOEXCEPT { return __size_; } + _LIBCPP_HIDE_FROM_ABI const size_type& __size() const _NOEXCEPT { return __size_; } _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return std::min(__alloc_traits::max_size(__alloc()), numeric_limits::max()); @@ -1251,7 +1251,7 @@ deque(from_range_t, _Range&&, _Alloc = _Alloc()) -> deque -deque<_Tp, _Allocator>::deque(size_type __n) : __start_(0), __size_(0, __default_init_tag()) { +deque<_Tp, _Allocator>::deque(size_type __n) : __start_(0), __size_(0) { __annotate_new(0); if (__n > 0) __append(__n); @@ -1260,7 +1260,7 @@ deque<_Tp, _Allocator>::deque(size_type __n) : __start_(0), __size_(0, __default #if _LIBCPP_STD_VER >= 14 template deque<_Tp, _Allocator>::deque(size_type __n, const _Allocator& __a) - : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) { + : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) { __annotate_new(0); if (__n > 0) __append(__n); @@ -1268,7 +1268,7 @@ deque<_Tp, _Allocator>::deque(size_type __n, const _Allocator& __a) #endif template -deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v) : __start_(0), __size_(0, __default_init_tag()) { +deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v) : __start_(0), __size_(0) { __annotate_new(0); if (__n > 0) __append(__n, __v); @@ -1276,7 +1276,7 @@ deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v) : __start_(0 template template ::value, int> > -deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l) : __start_(0), __size_(0, __default_init_tag()) { +deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l) : __start_(0), __size_(0) { __annotate_new(0); __append(__f, __l); } @@ -1284,7 +1284,7 @@ deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l) : __start_(0), __s template template ::value, int> > deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a) - : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) { + : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) { __annotate_new(0); __append(__f, __l); } @@ -1293,14 +1293,15 @@ template deque<_Tp, _Allocator>::deque(const deque& __c) : __map_(__pointer_allocator(__alloc_traits::select_on_container_copy_construction(__c.__alloc()))), __start_(0), - __size_(0, __map_.__alloc()) { + __size_(0), + __alloc_(__map_.__alloc()) { __annotate_new(0); __append(__c.begin(), __c.end()); } template deque<_Tp, _Allocator>::deque(const deque& __c, const __type_identity_t& __a) - : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) { + : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) { __annotate_new(0); __append(__c.begin(), __c.end()); } @@ -1317,21 +1318,24 @@ deque<_Tp, _Allocator>& deque<_Tp, _Allocator>::operator=(const deque& __c) { #ifndef _LIBCPP_CXX03_LANG template -deque<_Tp, _Allocator>::deque(initializer_list __il) : __start_(0), __size_(0, __default_init_tag()) { +deque<_Tp, _Allocator>::deque(initializer_list __il) : __start_(0), __size_(0) { __annotate_new(0); __append(__il.begin(), __il.end()); } template deque<_Tp, _Allocator>::deque(initializer_list __il, const allocator_type& __a) - : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) { + : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) { __annotate_new(0); __append(__il.begin(), __il.end()); } template inline deque<_Tp, _Allocator>::deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible::value) - : __map_(std::move(__c.__map_)), __start_(std::move(__c.__start_)), __size_(std::move(__c.__size_)) { + : __map_(std::move(__c.__map_)), + __start_(std::move(__c.__start_)), + __size_(std::move(__c.__size_)), + __alloc_(std::move(__c.__alloc_)) { __c.__start_ = 0; __c.__size() = 0; } @@ -1340,7 +1344,8 @@ template inline deque<_Tp, _Allocator>::deque(deque&& __c, const __type_identity_t& __a) : __map_(std::move(__c.__map_), __pointer_allocator(__a)), __start_(std::move(__c.__start_)), - __size_(std::move(__c.__size()), __a) { + __size_(std::move(__c.__size_)), + __alloc_(__a) { if (__a == __c.__alloc()) { __c.__start_ = 0; __c.__size() = 0; diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list index 22cb0ebc2247a..0d44892202d4f 100644 --- a/libcxx/include/forward_list +++ b/libcxx/include/forward_list @@ -230,6 +230,7 @@ template #include <__type_traits/type_identity.h> #include <__utility/forward.h> #include <__utility/move.h> +#include <__utility/swap.h> #include #include // __launder #include @@ -492,27 +493,27 @@ protected: typedef __rebind_alloc, __begin_node> __begin_node_allocator; typedef typename allocator_traits<__begin_node_allocator>::pointer __begin_node_pointer; - __compressed_pair<__begin_node, __node_allocator> __before_begin_; + _LIBCPP_COMPRESSED_PAIR(__begin_node, __before_begin_, __node_allocator, __alloc_); _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __before_begin() _NOEXCEPT { - return pointer_traits<__begin_node_pointer>::pointer_to(__before_begin_.first()); + return pointer_traits<__begin_node_pointer>::pointer_to(__before_begin_); } _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __before_begin() const _NOEXCEPT { - return pointer_traits<__begin_node_pointer>::pointer_to(const_cast<__begin_node&>(__before_begin_.first())); + return pointer_traits<__begin_node_pointer>::pointer_to(const_cast<__begin_node&>(__before_begin_)); } - _LIBCPP_HIDE_FROM_ABI __node_allocator& __alloc() _NOEXCEPT { return __before_begin_.second(); } - _LIBCPP_HIDE_FROM_ABI const __node_allocator& __alloc() const _NOEXCEPT { return __before_begin_.second(); } + _LIBCPP_HIDE_FROM_ABI __node_allocator& __alloc() _NOEXCEPT { return __alloc_; } + _LIBCPP_HIDE_FROM_ABI const __node_allocator& __alloc() const _NOEXCEPT { return __alloc_; } typedef __forward_list_iterator<__node_pointer> iterator; typedef __forward_list_const_iterator<__node_pointer> const_iterator; _LIBCPP_HIDE_FROM_ABI __forward_list_base() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) - : __before_begin_(__begin_node(), __default_init_tag()) {} + : __before_begin_(__begin_node()) {} _LIBCPP_HIDE_FROM_ABI explicit __forward_list_base(const allocator_type& __a) - : __before_begin_(__begin_node(), __node_allocator(__a)) {} + : __before_begin_(__begin_node()), __alloc_(__node_allocator(__a)) {} _LIBCPP_HIDE_FROM_ABI explicit __forward_list_base(const __node_allocator& __a) - : __before_begin_(__begin_node(), __a) {} + : __before_begin_(__begin_node()), __alloc_(__a) {} #ifndef _LIBCPP_CXX03_LANG public: @@ -597,13 +598,13 @@ private: template inline __forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x) _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value) - : __before_begin_(std::move(__x.__before_begin_)) { + : __before_begin_(std::move(__x.__before_begin_)), __alloc_(std::move(__x.__alloc_)) { __x.__before_begin()->__next_ = nullptr; } template inline __forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x, const allocator_type& __a) - : __before_begin_(__begin_node(), __node_allocator(__a)) { + : __before_begin_(__begin_node()), __alloc_(__node_allocator(__a)) { if (__alloc() == __x.__alloc()) { __before_begin()->__next_ = __x.__before_begin()->__next_; __x.__before_begin()->__next_ = nullptr; diff --git a/libcxx/include/future b/libcxx/include/future index 92ba188210691..f6b7d6edad6a9 100644 --- a/libcxx/include/future +++ b/libcxx/include/future @@ -1399,13 +1399,13 @@ class __packaged_task_func; template class __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)> : public __packaged_task_base<_Rp(_ArgTypes...)> { - __compressed_pair<_Fp, _Alloc> __f_; + _LIBCPP_COMPRESSED_PAIR(_Fp, __func_, _Alloc, __alloc_); public: - _LIBCPP_HIDE_FROM_ABI explicit __packaged_task_func(const _Fp& __f) : __f_(__f, __default_init_tag()) {} - _LIBCPP_HIDE_FROM_ABI explicit __packaged_task_func(_Fp&& __f) : __f_(std::move(__f), __default_init_tag()) {} - _LIBCPP_HIDE_FROM_ABI __packaged_task_func(const _Fp& __f, const _Alloc& __a) : __f_(__f, __a) {} - _LIBCPP_HIDE_FROM_ABI __packaged_task_func(_Fp&& __f, const _Alloc& __a) : __f_(std::move(__f), __a) {} + _LIBCPP_HIDE_FROM_ABI explicit __packaged_task_func(const _Fp& __f) : __func_(__f) {} + _LIBCPP_HIDE_FROM_ABI explicit __packaged_task_func(_Fp&& __f) : __func_(std::move(__f)) {} + _LIBCPP_HIDE_FROM_ABI __packaged_task_func(const _Fp& __f, const _Alloc& __a) : __func_(__f), __alloc_(__a) {} + _LIBCPP_HIDE_FROM_ABI __packaged_task_func(_Fp&& __f, const _Alloc& __a) : __func_(std::move(__f)), __alloc_(__a) {} _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __move_to(__packaged_task_base<_Rp(_ArgTypes...)>*) _NOEXCEPT; _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy(); _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy_deallocate(); @@ -1415,12 +1415,13 @@ public: template void __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__move_to( __packaged_task_base<_Rp(_ArgTypes...)>* __p) _NOEXCEPT { - ::new ((void*)__p) __packaged_task_func(std::move(__f_.first()), std::move(__f_.second())); + ::new ((void*)__p) __packaged_task_func(std::move(__func_), std::move(__alloc_)); } template void __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() { - __f_.~__compressed_pair<_Fp, _Alloc>(); + __func_.~_Fp(); + __alloc_.~_Alloc(); } template @@ -1428,14 +1429,15 @@ void __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() typedef typename __allocator_traits_rebind<_Alloc, __packaged_task_func>::type _Ap; typedef allocator_traits<_Ap> _ATraits; typedef pointer_traits _PTraits; - _Ap __a(__f_.second()); - __f_.~__compressed_pair<_Fp, _Alloc>(); + _Ap __a(__alloc_); + __func_.~_Fp(); + __alloc_.~_Alloc(); __a.deallocate(_PTraits::pointer_to(*this), 1); } template _Rp __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&&... __arg) { - return std::__invoke(__f_.first(), std::forward<_ArgTypes>(__arg)...); + return std::__invoke(__func_, std::forward<_ArgTypes>(__arg)...); } template diff --git a/libcxx/include/list b/libcxx/include/list index 7fea487445693..483d0d04ae3af 100644 --- a/libcxx/include/list +++ b/libcxx/include/list @@ -500,16 +500,16 @@ protected: "type; otherwise overload resolution breaks"); __node_base __end_; - __compressed_pair __size_alloc_; + _LIBCPP_COMPRESSED_PAIR(size_type, __size_, __node_allocator, __node_alloc_); _LIBCPP_HIDE_FROM_ABI __link_pointer __end_as_link() const _NOEXCEPT { return __node_pointer_traits::__unsafe_link_pointer_cast(const_cast<__node_base&>(__end_).__self()); } - _LIBCPP_HIDE_FROM_ABI size_type& __sz() _NOEXCEPT { return __size_alloc_.first(); } - _LIBCPP_HIDE_FROM_ABI const size_type& __sz() const _NOEXCEPT { return __size_alloc_.first(); } - _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __size_alloc_.second(); } - _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __size_alloc_.second(); } + _LIBCPP_HIDE_FROM_ABI size_type& __sz() _NOEXCEPT { return __size_; } + _LIBCPP_HIDE_FROM_ABI const size_type& __sz() const _NOEXCEPT { return __size_; } + _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __node_alloc_; } + _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __node_alloc_; } _LIBCPP_HIDE_FROM_ABI size_type __node_alloc_max_size() const _NOEXCEPT { return __node_alloc_traits::max_size(__node_alloc()); @@ -604,17 +604,20 @@ inline void __list_imp<_Tp, _Alloc>::__unlink_nodes(__link_pointer __f, __link_p template inline __list_imp<_Tp, _Alloc>::__list_imp() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) - : __size_alloc_(0, __default_init_tag()) {} + : __size_(0) {} template -inline __list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a) : __size_alloc_(0, __node_allocator(__a)) {} +inline __list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a) + : __size_(0), __node_alloc_(__node_allocator(__a)) {} template -inline __list_imp<_Tp, _Alloc>::__list_imp(const __node_allocator& __a) : __size_alloc_(0, __a) {} +inline __list_imp<_Tp, _Alloc>::__list_imp(const __node_allocator& __a) : __size_(0), __node_alloc_(__a) {} #ifndef _LIBCPP_CXX03_LANG template -inline __list_imp<_Tp, _Alloc>::__list_imp(__node_allocator&& __a) _NOEXCEPT : __size_alloc_(0, std::move(__a)) {} +inline __list_imp<_Tp, _Alloc>::__list_imp(__node_allocator&& __a) _NOEXCEPT + : __size_(0), + __node_alloc_(std::move(__a)) {} #endif template diff --git a/libcxx/include/string b/libcxx/include/string index c676182fba8ba..4fbe76ed48132 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -837,18 +837,18 @@ private: }; }; - __compressed_pair<__rep, allocator_type> __r_; + _LIBCPP_COMPRESSED_PAIR(__rep, __rep_, allocator_type, __alloc_); // Construct a string with the given allocator and enough storage to hold `__size` characters, but // don't initialize the characters. The contents of the string, including the null terminator, must be // initialized separately. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string( __uninitialized_size_tag, size_type __size, const allocator_type& __a) - : __r_(__default_init_tag(), __a) { + : __alloc_(__a) { if (__size > max_size()) __throw_length_error(); if (__fits_in_sso(__size)) { - __r_.first() = __rep(); + __rep_ = __rep(); __set_short_size(__size); } else { auto __capacity = __recommend(__size) + 1; @@ -864,7 +864,7 @@ private: template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(__init_with_sentinel_tag, _Iter __first, _Sent __last, const allocator_type& __a) - : __r_(__default_init_tag(), __a) { + : __alloc_(__a) { __init_with_sentinel(std::move(__first), std::move(__last)); } @@ -879,7 +879,7 @@ public: _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string() _NOEXCEPT_(is_nothrow_default_constructible::value) - : __r_(__value_init_tag(), __default_init_tag()) { + : __rep_() { __annotate_new(0); } @@ -889,14 +889,14 @@ public: #else _NOEXCEPT #endif - : __r_(__value_init_tag(), __a) { + : __rep_(), __alloc_(__a) { __annotate_new(0); } _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS basic_string(const basic_string& __str) - : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc())) { + : __alloc_(__alloc_traits::select_on_container_copy_construction(__str.__alloc())) { if (!__str.__is_long()) { - __r_.first() = __str.__r_.first(); + __rep_ = __str.__rep_; __annotate_new(__get_short_size()); } else __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); @@ -904,9 +904,9 @@ public: _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS basic_string(const basic_string& __str, const allocator_type& __a) - : __r_(__default_init_tag(), __a) { + : __alloc_(__a) { if (!__str.__is_long()) { - __r_.first() = __str.__r_.first(); + __rep_ = __str.__rep_; __annotate_new(__get_short_size()); } else __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); @@ -922,24 +922,25 @@ public: // Turning off ASan instrumentation for variable initialization with _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS // does not work consistently during initialization of __r_, so we instead unpoison __str's memory manually first. // __str's memory needs to be unpoisoned only in the case where it's a short string. - : __r_(((__str.__is_long() ? 0 : (__str.__annotate_delete(), 0)), std::move(__str.__r_))) { - __str.__r_.first() = __rep(); + : __rep_(((__str.__is_long() ? 0 : (__str.__annotate_delete(), 0)), std::move(__str.__rep_))), + __alloc_(std::move(__str.__alloc_)) { + __str.__rep_ = __rep(); __str.__annotate_new(0); if (!__is_long()) __annotate_new(size()); } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(basic_string&& __str, const allocator_type& __a) - : __r_(__default_init_tag(), __a) { + : __alloc_(__a) { if (__str.__is_long() && __a != __str.__alloc()) // copy, not move __init(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); else { if (__libcpp_is_constant_evaluated()) - __r_.first() = __rep(); + __rep_ = __rep(); if (!__str.__is_long()) __str.__annotate_delete(); - __r_.first() = __str.__r_.first(); - __str.__r_.first() = __rep(); + __rep_ = __str.__rep_; + __str.__rep_ = __rep(); __str.__annotate_new(0); if (!__is_long() && this != &__str) __annotate_new(size()); @@ -948,15 +949,14 @@ public: #endif // _LIBCPP_CXX03_LANG template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s) - : __r_(__default_init_tag(), __default_init_tag()) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s) { _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "basic_string(const char*) detected nullptr"); __init(__s, traits_type::length(__s)); } template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, const _Allocator& __a) - : __r_(__default_init_tag(), __a) { + : __alloc_(__a) { _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); __init(__s, traits_type::length(__s)); } @@ -965,23 +965,19 @@ public: basic_string(nullptr_t) = delete; #endif - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, size_type __n) - : __r_(__default_init_tag(), __default_init_tag()) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, size_type __n) { _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); __init(__s, __n); } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a) - : __r_(__default_init_tag(), __a) { + : __alloc_(__a) { _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); __init(__s, __n); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c) - : __r_(__default_init_tag(), __default_init_tag()) { - __init(__n, __c); - } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c) { __init(__n, __c); } #if _LIBCPP_STD_VER >= 23 _LIBCPP_HIDE_FROM_ABI constexpr basic_string( @@ -990,7 +986,7 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr basic_string( basic_string&& __str, size_type __pos, size_type __n, const _Allocator& __alloc = _Allocator()) - : __r_(__default_init_tag(), __alloc) { + : __alloc_(__alloc) { if (__pos > __str.size()) __throw_out_of_range(); @@ -1006,13 +1002,13 @@ public: template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c, const _Allocator& __a) - : __r_(__default_init_tag(), __a) { + : __alloc_(__a) { __init(__n, __c); } _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const basic_string& __str, size_type __pos, size_type __n, const _Allocator& __a = _Allocator()) - : __r_(__default_init_tag(), __a) { + : __alloc_(__a) { size_type __str_sz = __str.size(); if (__pos > __str_sz) __throw_out_of_range(); @@ -1021,7 +1017,7 @@ public: _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const basic_string& __str, size_type __pos, const _Allocator& __a = _Allocator()) - : __r_(__default_init_tag(), __a) { + : __alloc_(__a) { size_type __str_sz = __str.size(); if (__pos > __str_sz) __throw_out_of_range(); @@ -1034,7 +1030,7 @@ public: int> = 0> _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a = allocator_type()) - : __r_(__default_init_tag(), __a) { + : __alloc_(__a) { __self_view __sv0 = __t; __self_view __sv = __sv0.substr(__pos, __n); __init(__sv.data(), __sv.size()); @@ -1044,8 +1040,8 @@ public: __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value, int> = 0> - _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const _Tp& __t) - : __r_(__default_init_tag(), __default_init_tag()) { + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string( + const _Tp& __t) { __self_view __sv = __t; __init(__sv.data(), __sv.size()); } @@ -1056,21 +1052,20 @@ public: int> = 0> _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string( const _Tp& __t, const allocator_type& __a) - : __r_(__default_init_tag(), __a) { + : __alloc_(__a) { __self_view __sv = __t; __init(__sv.data(), __sv.size()); } template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(_InputIterator __first, _InputIterator __last) - : __r_(__default_init_tag(), __default_init_tag()) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(_InputIterator __first, _InputIterator __last) { __init(__first, __last); } template ::value, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a) - : __r_(__default_init_tag(), __a) { + : __alloc_(__a) { __init(__first, __last); } @@ -1078,7 +1073,7 @@ public: template <_ContainerCompatibleRange<_CharT> _Range> _LIBCPP_HIDE_FROM_ABI constexpr basic_string( from_range_t, _Range&& __range, const allocator_type& __a = allocator_type()) - : __r_(__default_init_tag(), __a) { + : __alloc_(__a) { if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { __init_with_size(ranges::begin(__range), ranges::end(__range), ranges::distance(__range)); } else { @@ -1088,13 +1083,12 @@ public: #endif #ifndef _LIBCPP_CXX03_LANG - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il) - : __r_(__default_init_tag(), __default_init_tag()) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il) { __init(__il.begin(), __il.end()); } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il, const _Allocator& __a) - : __r_(__default_init_tag(), __a) { + : __alloc_(__a) { __init(__il.begin(), __il.end()); } #endif // _LIBCPP_CXX03_LANG @@ -1359,8 +1353,8 @@ public: size_type __old_sz = __str.size(); if (!__str.__is_long()) __str.__annotate_delete(); - __r_.first() = __str.__r_.first(); - __str.__r_.first() = __rep(); + __rep_ = __str.__rep_; + __str.__rep_ = __rep(); __str.__annotate_new(0); _Traits::move(data(), data() + __pos, __len); @@ -1767,10 +1761,10 @@ private: _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS bool __is_long() const _NOEXCEPT { - if (__libcpp_is_constant_evaluated() && __builtin_constant_p(__r_.first().__l.__is_long_)) { - return __r_.first().__l.__is_long_; + if (__libcpp_is_constant_evaluated() && __builtin_constant_p(__rep_.__l.__is_long_)) { + return __rep_.__l.__is_long_; } - return __r_.first().__s.__is_long_; + return __rep_.__s.__is_long_; } static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __begin_lifetime(pointer __begin, size_type __n) { @@ -1823,27 +1817,27 @@ private: _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator __insert_with_size(const_iterator __pos, _Iterator __first, _Sentinel __last, size_type __n); - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 allocator_type& __alloc() _NOEXCEPT { return __r_.second(); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const allocator_type& __alloc() const _NOEXCEPT { return __r_.second(); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 allocator_type& __alloc() _NOEXCEPT { return __alloc_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const allocator_type& __alloc() const _NOEXCEPT { return __alloc_; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS void __set_short_size(size_type __s) _NOEXCEPT { _LIBCPP_ASSERT_INTERNAL(__s < __min_cap, "__s should never be greater than or equal to the short string capacity"); - __r_.first().__s.__size_ = __s; - __r_.first().__s.__is_long_ = false; + __rep_.__s.__size_ = __s; + __rep_.__s.__is_long_ = false; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS size_type __get_short_size() const _NOEXCEPT { - _LIBCPP_ASSERT_INTERNAL(!__r_.first().__s.__is_long_, "String has to be short when trying to get the short size"); - return __r_.first().__s.__size_; + _LIBCPP_ASSERT_INTERNAL(!__rep_.__s.__is_long_, "String has to be short when trying to get the short size"); + return __rep_.__s.__size_; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __set_long_size(size_type __s) _NOEXCEPT { - __r_.first().__l.__size_ = __s; + __rep_.__l.__size_ = __s; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __get_long_size() const _NOEXCEPT { - return __r_.first().__l.__size_; + return __rep_.__l.__size_; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __set_size(size_type __s) _NOEXCEPT { if (__is_long()) @@ -1853,28 +1847,28 @@ private: } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __set_long_cap(size_type __s) _NOEXCEPT { - __r_.first().__l.__cap_ = __s / __endian_factor; - __r_.first().__l.__is_long_ = true; + __rep_.__l.__cap_ = __s / __endian_factor; + __rep_.__l.__is_long_ = true; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __get_long_cap() const _NOEXCEPT { - return __r_.first().__l.__cap_ * __endian_factor; + return __rep_.__l.__cap_ * __endian_factor; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __set_long_pointer(pointer __p) _NOEXCEPT { - __r_.first().__l.__data_ = __p; + __rep_.__l.__data_ = __p; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pointer __get_long_pointer() _NOEXCEPT { - return __r_.first().__l.__data_; + return __rep_.__l.__data_; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_pointer __get_long_pointer() const _NOEXCEPT { - return __r_.first().__l.__data_; + return __rep_.__l.__data_; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pointer __get_short_pointer() _NOEXCEPT { - return pointer_traits::pointer_to(__r_.first().__s.__data_[0]); + return pointer_traits::pointer_to(__rep_.__s.__data_[0]); } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_pointer __get_short_pointer() const _NOEXCEPT { - return pointer_traits::pointer_to(__r_.first().__s.__data_[0]); + return pointer_traits::pointer_to(__rep_.__s.__data_[0]); } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pointer __get_pointer() _NOEXCEPT { return __is_long() ? __get_long_pointer() : __get_short_pointer(); @@ -1903,7 +1897,7 @@ private: } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_new(size_type __current_size) const _NOEXCEPT { - (void) __current_size; + (void)__current_size; #if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN) if (!__libcpp_is_constant_evaluated() && (__asan_short_string_is_annotated() || __is_long())) __annotate_contiguous_container(data() + capacity() + 1, data() + __current_size + 1); @@ -1918,7 +1912,7 @@ private: } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_increase(size_type __n) const _NOEXCEPT { - (void) __n; + (void)__n; #if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN) if (!__libcpp_is_constant_evaluated() && (__asan_short_string_is_annotated() || __is_long())) __annotate_contiguous_container(data() + size() + 1, data() + size() + 1 + __n); @@ -1926,7 +1920,7 @@ private: } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_shrink(size_type __old_size) const _NOEXCEPT { - (void) __old_size; + (void)__old_size; #if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN) if (!__libcpp_is_constant_evaluated() && (__asan_short_string_is_annotated() || __is_long())) __annotate_contiguous_container(data() + __old_size + 1, data() + size() + 1); @@ -2183,7 +2177,7 @@ template _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve) { if (__libcpp_is_constant_evaluated()) - __r_.first() = __rep(); + __rep_ = __rep(); if (__reserve > max_size()) __throw_length_error(); pointer __p; @@ -2207,7 +2201,7 @@ template _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz) { if (__libcpp_is_constant_evaluated()) - __r_.first() = __rep(); + __rep_ = __rep(); if (__sz > max_size()) __throw_length_error(); pointer __p; @@ -2231,7 +2225,7 @@ template _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NOINLINE void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(const value_type* __s, size_type __sz) { if (__libcpp_is_constant_evaluated()) - __r_.first() = __rep(); + __rep_ = __rep(); pointer __p; if (__fits_in_sso(__sz)) { @@ -2254,7 +2248,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(const value template _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c) { if (__libcpp_is_constant_evaluated()) - __r_.first() = __rep(); + __rep_ = __rep(); if (__n > max_size()) __throw_length_error(); @@ -2286,7 +2280,7 @@ template template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__init_with_sentinel(_InputIterator __first, _Sentinel __last) { - __r_.first() = __rep(); + __rep_ = __rep(); __annotate_new(0); #ifndef _LIBCPP_HAS_NO_EXCEPTIONS @@ -2317,7 +2311,7 @@ template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__init_with_size(_InputIterator __first, _Sentinel __last, size_type __sz) { if (__libcpp_is_constant_evaluated()) - __r_.first() = __rep(); + __rep_ = __rep(); if (__sz > max_size()) __throw_length_error(); @@ -2538,7 +2532,7 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) size_type __old_size = __get_short_size(); if (__get_short_size() < __str.__get_short_size()) __annotate_increase(__str.__get_short_size() - __get_short_size()); - __r_.first() = __str.__r_.first(); + __rep_ = __str.__rep_; if (__old_size > __get_short_size()) __annotate_shrink(__old_size); } else { @@ -2587,7 +2581,7 @@ basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, tr bool __str_was_short = !__str.__is_long(); __move_assign_alloc(__str); - __r_.first() = __str.__r_.first(); + __rep_ = __str.__rep_; __str.__set_short_size(0); traits_type::assign(__str.__get_short_pointer()[0], value_type()); @@ -3323,7 +3317,7 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocat __annotate_delete(); if (this != &__str && !__str.__is_long()) __str.__annotate_delete(); - std::swap(__r_.first(), __str.__r_.first()); + std::swap(__rep_, __str.__rep_); std::__swap_allocator(__alloc(), __str.__alloc()); if (!__is_long()) __annotate_new(__get_short_size()); @@ -3686,7 +3680,7 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocat if (__is_long()) { __annotate_delete(); __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1); - __r_.first() = __rep(); + __rep_ = __rep(); } } diff --git a/libcxx/include/vector b/libcxx/include/vector index 0098273a195ff..7a1eea3826262 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -413,14 +413,15 @@ public: "original allocator"); _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector() - _NOEXCEPT_(is_nothrow_default_constructible::value) {} + _NOEXCEPT_(is_nothrow_default_constructible::value) + : __cap_(nullptr) {} _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(const allocator_type& __a) #if _LIBCPP_STD_VER <= 14 _NOEXCEPT_(is_nothrow_copy_constructible::value) #else _NOEXCEPT #endif - : __end_cap_(nullptr, __a) { + : __cap_(nullptr), __alloc_(__a) { } _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n); #if _LIBCPP_STD_VER >= 14 @@ -431,7 +432,7 @@ public: template ::value> > _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __x, const allocator_type& __a) - : __end_cap_(nullptr, __a) { + : __cap_(nullptr), __alloc_(__a) { if (__n > 0) { __vallocate(__n); __construct_at_end(__n, __x); @@ -469,7 +470,7 @@ public: template <_ContainerCompatibleRange<_Tp> _Range> _LIBCPP_HIDE_FROM_ABI constexpr vector( from_range_t, _Range&& __range, const allocator_type& __alloc = allocator_type()) - : __end_cap_(nullptr, __alloc) { + : __cap_(nullptr), __alloc_(__alloc) { if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { auto __n = static_cast(ranges::distance(__range)); __init_with_size(ranges::begin(__range), ranges::end(__range), __n); @@ -725,8 +726,7 @@ public: private: pointer __begin_ = nullptr; pointer __end_ = nullptr; - __compressed_pair __end_cap_ = - __compressed_pair(nullptr, __default_init_tag()); + _LIBCPP_COMPRESSED_PAIR(pointer, __cap_, allocator_type, __alloc_); // Allocate space for __n objects // throws length_error if __n > max_size() @@ -903,17 +903,13 @@ private: ++__tx.__pos_; } - _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { - return this->__end_cap_.second(); - } + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return this->__alloc_; } _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { - return this->__end_cap_.second(); - } - _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer& __end_cap() _NOEXCEPT { - return this->__end_cap_.first(); + return this->__alloc_; } + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer& __end_cap() _NOEXCEPT { return this->__cap_; } _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const pointer& __end_cap() const _NOEXCEPT { - return this->__end_cap_.first(); + return this->__cap_; } _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __clear() _NOEXCEPT { @@ -1115,7 +1111,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__append(size_type _ } template -_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n) { +_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n) : __cap_(nullptr) { auto __guard = std::__make_exception_guard(__destroy_vector(*this)); if (__n > 0) { __vallocate(__n); @@ -1127,7 +1123,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n) { #if _LIBCPP_STD_VER >= 14 template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) - : __end_cap_(nullptr, __a) { + : __cap_(nullptr), __alloc_(__a) { auto __guard = std::__make_exception_guard(__destroy_vector(*this)); if (__n > 0) { __vallocate(__n); @@ -1138,7 +1134,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, con #endif template -_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) { +_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) : __cap_(nullptr) { auto __guard = std::__make_exception_guard(__destroy_vector(*this)); if (__n > 0) { __vallocate(__n); @@ -1152,7 +1148,8 @@ template ::value && is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value, int> > -_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last) { +_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last) + : __cap_(nullptr) { __init_with_sentinel(__first, __last); } @@ -1163,7 +1160,7 @@ template > _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a) - : __end_cap_(nullptr, __a) { + : __cap_(nullptr), __alloc_(__a) { __init_with_sentinel(__first, __last); } @@ -1172,7 +1169,8 @@ template ::value && is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value, int> > -_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last) { +_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last) + : __cap_(nullptr) { size_type __n = static_cast(std::distance(__first, __last)); __init_with_size(__first, __last, __n); } @@ -1184,21 +1182,21 @@ template > _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a) - : __end_cap_(nullptr, __a) { + : __cap_(nullptr), __alloc_(__a) { size_type __n = static_cast(std::distance(__first, __last)); __init_with_size(__first, __last, __n); } template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(const vector& __x) - : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc())) { + : __cap_(nullptr), __alloc_(__alloc_traits::select_on_container_copy_construction(__x.__alloc())) { __init_with_size(__x.__begin_, __x.__end_, __x.size()); } template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t& __a) - : __end_cap_(nullptr, __a) { + : __cap_(nullptr), __alloc_(__a) { __init_with_size(__x.__begin_, __x.__end_, __x.size()); } @@ -1209,7 +1207,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocato #else _NOEXCEPT_(is_nothrow_move_constructible::value) #endif - : __end_cap_(nullptr, std::move(__x.__alloc())) { + : __cap_(nullptr), __alloc_(std::move(__x.__alloc())) { this->__begin_ = __x.__begin_; this->__end_ = __x.__end_; this->__end_cap() = __x.__end_cap(); @@ -1219,7 +1217,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocato template _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t& __a) - : __end_cap_(nullptr, __a) { + : __cap_(nullptr), __alloc_(__a) { if (__a == __x.__alloc()) { this->__begin_ = __x.__begin_; this->__end_ = __x.__end_; @@ -1237,7 +1235,8 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI -vector<_Tp, _Allocator>::vector(initializer_list __il) { +vector<_Tp, _Allocator>::vector(initializer_list __il) + : __cap_(nullptr) { auto __guard = std::__make_exception_guard(__destroy_vector(*this)); if (__il.size() > 0) { __vallocate(__il.size()); @@ -1249,7 +1248,7 @@ vector<_Tp, _Allocator>::vector(initializer_list __il) { template _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(initializer_list __il, const allocator_type& __a) - : __end_cap_(nullptr, __a) { + : __cap_(nullptr), __alloc_(__a) { auto __guard = std::__make_exception_guard(__destroy_vector(*this)); if (__il.size() > 0) { __vallocate(__il.size()); @@ -1834,7 +1833,7 @@ private: __storage_pointer __begin_; size_type __size_; - __compressed_pair __cap_alloc_; + _LIBCPP_COMPRESSED_PAIR(size_type, __cap_, __storage_allocator, __alloc_); public: typedef __bit_reference reference; @@ -1845,15 +1844,11 @@ public: #endif private: - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type& __cap() _NOEXCEPT { return __cap_alloc_.first(); } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const size_type& __cap() const _NOEXCEPT { - return __cap_alloc_.first(); - } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __storage_allocator& __alloc() _NOEXCEPT { - return __cap_alloc_.second(); - } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type& __cap() _NOEXCEPT { return __cap_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const size_type& __cap() const _NOEXCEPT { return __cap_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __storage_allocator& __alloc() _NOEXCEPT { return __alloc_; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const __storage_allocator& __alloc() const _NOEXCEPT { - return __cap_alloc_.second(); + return __alloc_; } static const unsigned __bits_per_word = static_cast(sizeof(__storage_type) * CHAR_BIT); @@ -1916,7 +1911,7 @@ public: #if _LIBCPP_STD_VER >= 23 template <_ContainerCompatibleRange _Range> _LIBCPP_HIDE_FROM_ABI constexpr vector(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type()) - : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { + : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) { if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { auto __n = static_cast(ranges::distance(__range)); __init_with_size(ranges::begin(__range), ranges::end(__range), __n); @@ -2321,7 +2316,7 @@ vector::__construct_at_end(_InputIterator __first, _Sentinel _ template inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector() _NOEXCEPT_(is_nothrow_default_constructible::value) - : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {} + : __begin_(nullptr), __size_(0), __cap_(0) {} template inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(const allocator_type& __a) @@ -2330,12 +2325,12 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(__a)) { + : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) { } template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(size_type __n) - : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) { + : __begin_(nullptr), __size_(0), __cap_(0) { if (__n > 0) { __vallocate(__n); __construct_at_end(__n, false); @@ -2345,7 +2340,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(size_type __n) #if _LIBCPP_STD_VER >= 14 template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(size_type __n, const allocator_type& __a) - : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { + : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) { if (__n > 0) { __vallocate(__n); __construct_at_end(__n, false); @@ -2355,7 +2350,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(size_type __n, co template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(size_type __n, const value_type& __x) - : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) { + : __begin_(nullptr), __size_(0), __cap_(0) { if (__n > 0) { __vallocate(__n); __construct_at_end(__n, __x); @@ -2365,7 +2360,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(size_type __n, co template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(size_type __n, const value_type& __x, const allocator_type& __a) - : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { + : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) { if (__n > 0) { __vallocate(__n); __construct_at_end(__n, __x); @@ -2375,7 +2370,7 @@ vector::vector(size_type __n, const value_type& __x, const all template template ::value, int> > _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(_InputIterator __first, _InputIterator __last) - : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) { + : __begin_(nullptr), __size_(0), __cap_(0) { __init_with_sentinel(__first, __last); } @@ -2383,14 +2378,14 @@ template template ::value, int> > _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a) - : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { + : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) { __init_with_sentinel(__first, __last); } template template ::value, int> > _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(_ForwardIterator __first, _ForwardIterator __last) - : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) { + : __begin_(nullptr), __size_(0), __cap_(0) { auto __n = static_cast(std::distance(__first, __last)); __init_with_size(__first, __last, __n); } @@ -2399,7 +2394,7 @@ template template ::value, int> > _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a) - : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { + : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) { auto __n = static_cast(std::distance(__first, __last)); __init_with_size(__first, __last, __n); } @@ -2408,7 +2403,7 @@ vector::vector(_ForwardIterator __first, _ForwardIterator __la template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(initializer_list __il) - : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) { + : __begin_(nullptr), __size_(0), __cap_(0) { size_type __n = static_cast(__il.size()); if (__n > 0) { __vallocate(__n); @@ -2419,7 +2414,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(initializer_list< template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(initializer_list __il, const allocator_type& __a) - : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { + : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) { size_type __n = static_cast(__il.size()); if (__n > 0) { __vallocate(__n); @@ -2433,7 +2428,8 @@ template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(const vector& __v) : __begin_(nullptr), __size_(0), - __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) { + __cap_(0), + __alloc_(__storage_traits::select_on_container_copy_construction(__v.__alloc())) { if (__v.size() > 0) { __vallocate(__v.size()); __construct_at_end(__v.begin(), __v.end(), __v.size()); @@ -2442,7 +2438,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(const vector& __v template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(const vector& __v, const allocator_type& __a) - : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) { + : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(__a) { if (__v.size() > 0) { __vallocate(__v.size()); __construct_at_end(__v.begin(), __v.end(), __v.size()); @@ -2474,7 +2470,8 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(vector&& __v, const __type_identity_t& __a) - : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) { + : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(__a) { if (__a == allocator_type(__v.__alloc())) { this->__begin_ = __v.__begin_; this->__size_ = __v.__size_; diff --git a/libcxx/test/libcxx/containers/sequences/deque/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/abi.compile.pass.cpp index 37e87d59503ee..58c579af927d8 100644 --- a/libcxx/test/libcxx/containers/sequences/deque/abi.compile.pass.cpp +++ b/libcxx/test/libcxx/containers/sequences/deque/abi.compile.pass.cpp @@ -37,27 +37,51 @@ class small_iter_allocator { friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; } }; +template +class final_small_iter_allocator final { +public: + using value_type = T; + using pointer = small_pointer; + using size_type = std::int16_t; + using difference_type = std::int16_t; + + final_small_iter_allocator() TEST_NOEXCEPT {} + + template + final_small_iter_allocator(final_small_iter_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(final_small_iter_allocator, final_small_iter_allocator) { return true; } + friend bool operator!=(final_small_iter_allocator, final_small_iter_allocator) { return false; } +}; + #if __SIZE_WIDTH__ == 64 static_assert(sizeof(std::deque) == 48, ""); static_assert(sizeof(std::deque >) == 48, ""); static_assert(sizeof(std::deque >) == 80, ""); static_assert(sizeof(std::deque >) == 12, ""); +static_assert(sizeof(std::deque >) == 16, ""); static_assert(sizeof(std::deque) == 48, ""); static_assert(sizeof(std::deque >) == 48, ""); static_assert(sizeof(std::deque >) == 80, ""); static_assert(sizeof(std::deque >) == 12, ""); +static_assert(sizeof(std::deque >) == 16, ""); static_assert(TEST_ALIGNOF(std::deque) == 8, ""); static_assert(TEST_ALIGNOF(std::deque >) == 8, ""); static_assert(TEST_ALIGNOF(std::deque >) == 8, ""); static_assert(TEST_ALIGNOF(std::deque >) == 2, ""); +static_assert(TEST_ALIGNOF(std::deque >) == 2, ""); static_assert(TEST_ALIGNOF(std::deque) == 8, ""); static_assert(TEST_ALIGNOF(std::deque >) == 8, ""); static_assert(TEST_ALIGNOF(std::deque >) == 8, ""); static_assert(TEST_ALIGNOF(std::deque >) == 2, ""); +static_assert(TEST_ALIGNOF(std::deque >) == 2, ""); #elif __SIZE_WIDTH__ == 32 @@ -65,21 +89,25 @@ static_assert(sizeof(std::deque) == 24, ""); static_assert(sizeof(std::deque >) == 24, ""); static_assert(sizeof(std::deque >) == 48, ""); static_assert(sizeof(std::deque >) == 12, ""); +static_assert(sizeof(std::deque >) == 12, ""); static_assert(sizeof(std::deque) == 24, ""); static_assert(sizeof(std::deque >) == 24, ""); static_assert(sizeof(std::deque >) == 48, ""); static_assert(sizeof(std::deque >) == 12, ""); +static_assert(sizeof(std::deque >) == 12, ""); static_assert(TEST_ALIGNOF(std::deque) == 4, ""); static_assert(TEST_ALIGNOF(std::deque >) == 4, ""); static_assert(TEST_ALIGNOF(std::deque >) == 4, ""); static_assert(TEST_ALIGNOF(std::deque >) == 2, ""); +static_assert(TEST_ALIGNOF(std::deque >) == 2, ""); static_assert(TEST_ALIGNOF(std::deque) == 4, ""); static_assert(TEST_ALIGNOF(std::deque >) == 4, ""); static_assert(TEST_ALIGNOF(std::deque >) == 4, ""); static_assert(TEST_ALIGNOF(std::deque >) == 2, ""); +static_assert(TEST_ALIGNOF(std::deque >) == 2, ""); #else # error std::size_t has an unexpected size diff --git a/libcxx/test/libcxx/containers/sequences/list/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/list/abi.compile.pass.cpp new file mode 100644 index 0000000000000..39ae10d047f25 --- /dev/null +++ b/libcxx/test/libcxx/containers/sequences/list/abi.compile.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include + +#include "min_allocator.h" +#include "test_allocator.h" +#include "test_macros.h" + +template +class small_pointer { + std::uint16_t offset; +}; + +template +class small_iter_allocator { +public: + using value_type = T; + using pointer = small_pointer; + using size_type = std::int16_t; + using difference_type = std::int16_t; + + small_iter_allocator() TEST_NOEXCEPT {} + + template + small_iter_allocator(small_iter_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(small_iter_allocator, small_iter_allocator) { return true; } + friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; } +}; + +#if __SIZE_WIDTH__ == 64 + +static_assert(sizeof(std::list) == 24, ""); +static_assert(sizeof(std::list >) == 24, ""); +static_assert(sizeof(std::list >) == 40, ""); +static_assert(sizeof(std::list >) == 6, ""); + +static_assert(sizeof(std::list) == 24, ""); +static_assert(sizeof(std::list >) == 24, ""); +static_assert(sizeof(std::list >) == 40, ""); +static_assert(sizeof(std::list >) == 6, ""); + +static_assert(TEST_ALIGNOF(std::list) == 8, ""); +static_assert(TEST_ALIGNOF(std::list >) == 8, ""); +static_assert(TEST_ALIGNOF(std::list >) == 8, ""); +static_assert(TEST_ALIGNOF(std::list >) == 2, ""); + +static_assert(TEST_ALIGNOF(std::list) == 8, ""); +static_assert(TEST_ALIGNOF(std::list >) == 8, ""); +static_assert(TEST_ALIGNOF(std::list >) == 8, ""); +static_assert(TEST_ALIGNOF(std::list >) == 2, ""); + +#elif __SIZE_WIDTH__ == 32 + +static_assert(sizeof(std::list) == 24, ""); +static_assert(sizeof(std::list >) == 24, ""); +static_assert(sizeof(std::list >) == 24, ""); +static_assert(sizeof(std::list >) == 6, ""); + +static_assert(sizeof(std::list) == 24, ""); +static_assert(sizeof(std::list >) == 24, ""); +static_assert(sizeof(std::list >) == 24, ""); +static_assert(sizeof(std::list >) == 6, ""); + +static_assert(TEST_ALIGNOF(std::list) == 4, ""); +static_assert(TEST_ALIGNOF(std::list >) == 4, ""); +static_assert(TEST_ALIGNOF(std::list >) == 4, ""); +static_assert(TEST_ALIGNOF(std::list >) == 2, ""); + +static_assert(TEST_ALIGNOF(std::list) == 4, ""); +static_assert(TEST_ALIGNOF(std::list >) == 4, ""); +static_assert(TEST_ALIGNOF(std::list >) == 4, ""); +static_assert(TEST_ALIGNOF(std::list >) == 2, ""); + +#else +# error std::size_t has an unexpected size +#endif diff --git a/libcxx/test/libcxx/containers/sequences/vector.bool/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/vector.bool/abi.compile.pass.cpp new file mode 100644 index 0000000000000..1086d38c33f8c --- /dev/null +++ b/libcxx/test/libcxx/containers/sequences/vector.bool/abi.compile.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include + +#include "min_allocator.h" +#include "test_allocator.h" +#include "test_macros.h" + +template +class small_pointer { + std::uint16_t offset; +}; + +template +class small_iter_allocator { +public: + using value_type = T; + using pointer = small_pointer; + using size_type = std::int16_t; + using difference_type = std::int16_t; + + small_iter_allocator() TEST_NOEXCEPT {} + + template + small_iter_allocator(small_iter_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(small_iter_allocator, small_iter_allocator) { return true; } + friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; } +}; + +#if __SIZE_WIDTH__ == 64 + +static_assert(sizeof(std::vector) == 24, ""); +static_assert(sizeof(std::vector >) == 24, ""); +static_assert(sizeof(std::vector >) == 40, ""); +static_assert(sizeof(std::vector >) == 6, ""); + +static_assert(TEST_ALIGNOF(std::vector) == 8, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 8, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 8, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 2, ""); + +#elif __SIZE_WIDTH__ == 32 + +static_assert(sizeof(std::vector) == 24, ""); +static_assert(sizeof(std::vector >) == 24, ""); +static_assert(sizeof(std::vector >) == 24, ""); +static_assert(sizeof(std::vector >) == 6, ""); + +static_assert(TEST_ALIGNOF(std::vector) == 4, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 4, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 4, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 2, ""); + +#else +# error std::size_t has an unexpected size +#endif diff --git a/libcxx/test/libcxx/containers/sequences/vector/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/vector/abi.compile.pass.cpp new file mode 100644 index 0000000000000..26a465a7dd8b9 --- /dev/null +++ b/libcxx/test/libcxx/containers/sequences/vector/abi.compile.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include + +#include "min_allocator.h" +#include "test_allocator.h" +#include "test_macros.h" + +template +class small_pointer { + std::uint16_t offset; +}; + +template +class small_iter_allocator { +public: + using value_type = T; + using pointer = small_pointer; + using size_type = std::int16_t; + using difference_type = std::int16_t; + + small_iter_allocator() TEST_NOEXCEPT {} + + template + small_iter_allocator(small_iter_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(small_iter_allocator, small_iter_allocator) { return true; } + friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; } +}; + +#if __SIZE_WIDTH__ == 64 + +static_assert(sizeof(std::vector) == 24, ""); +static_assert(sizeof(std::vector >) == 24, ""); +static_assert(sizeof(std::vector >) == 40, ""); +static_assert(sizeof(std::vector >) == 6, ""); + +static_assert(sizeof(std::vector) == 24, ""); +static_assert(sizeof(std::vector >) == 24, ""); +static_assert(sizeof(std::vector >) == 40, ""); +static_assert(sizeof(std::vector >) == 6, ""); + +static_assert(TEST_ALIGNOF(std::vector) == 8, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 8, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 8, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 2, ""); + +static_assert(TEST_ALIGNOF(std::vector) == 8, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 8, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 8, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 2, ""); + +#elif __SIZE_WIDTH__ == 32 + +static_assert(sizeof(std::vector) == 24, ""); +static_assert(sizeof(std::vector >) == 24, ""); +static_assert(sizeof(std::vector >) == 24, ""); +static_assert(sizeof(std::vector >) == 6, ""); + +static_assert(sizeof(std::vector) == 24, ""); +static_assert(sizeof(std::vector >) == 24, ""); +static_assert(sizeof(std::vector >) == 24, ""); +static_assert(sizeof(std::vector >) == 6, ""); + +static_assert(TEST_ALIGNOF(std::vector) == 4, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 4, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 4, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 2, ""); + +static_assert(TEST_ALIGNOF(std::vector) == 4, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 4, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 4, ""); +static_assert(TEST_ALIGNOF(std::vector >) == 2, ""); + +#else +# error std::size_t has an unexpected size +#endif diff --git a/libcxx/test/libcxx/containers/unord/unord.set/missing_hash_specialization.verify.cpp b/libcxx/test/libcxx/containers/unord/unord.set/missing_hash_specialization.verify.cpp index f492b760edf26..15740f8098216 100644 --- a/libcxx/test/libcxx/containers/unord/unord.set/missing_hash_specialization.verify.cpp +++ b/libcxx/test/libcxx/containers/unord/unord.set/missing_hash_specialization.verify.cpp @@ -52,7 +52,7 @@ int main(int, char**) { // FIXME: It would be great to suppress the below diagnostic all together. // but for now it's sufficient that it appears last. However there is // currently no way to test the order diagnostics are issued. - // expected-error@*:* {{call to implicitly-deleted default constructor of 'std::}} + // expected-error@*:* {{call to implicitly-deleted default constructor}} } { using Set = std::unordered_set; diff --git a/libcxx/test/libcxx/memory/compressed_pair/compressed_pair.pass.cpp b/libcxx/test/libcxx/memory/compressed_pair/compressed_pair.pass.cpp deleted file mode 100644 index 8bc890a208d0c..0000000000000 --- a/libcxx/test/libcxx/memory/compressed_pair/compressed_pair.pass.cpp +++ /dev/null @@ -1,52 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include -#include -#include - -#include "test_macros.h" - -typedef std::__compressed_pair IntPair; - -void test_constructor() { - IntPair value; - assert(value.first() == 0); - assert(value.second() == 0); - - value.first() = 1; - value.second() = 2; - new (&value) IntPair; - assert(value.first() == 0); - assert(value.second() == 0); -} - -void test_constructor_default_init() { - IntPair value; - value.first() = 1; - value.second() = 2; - - new (&value) IntPair(std::__default_init_tag(), 3); - assert(value.first() == 1); - assert(value.second() == 3); - - new (&value) IntPair(4, std::__default_init_tag()); - assert(value.first() == 4); - assert(value.second() == 3); - - new (&value) IntPair(std::__default_init_tag(), std::__default_init_tag()); - assert(value.first() == 4); - assert(value.second() == 3); -} - -int main(int, char**) -{ - test_constructor(); - test_constructor_default_init(); - return 0; -} diff --git a/libcxx/test/libcxx/utilities/memory/util.smartptr/util.smartptr.shared/libcxx.control_block_layout.pass.cpp b/libcxx/test/libcxx/utilities/memory/util.smartptr/util.smartptr.shared/libcxx.control_block_layout.pass.cpp index 0af79eef4687a..2344a82ace48b 100644 --- a/libcxx/test/libcxx/utilities/memory/util.smartptr/util.smartptr.shared/libcxx.control_block_layout.pass.cpp +++ b/libcxx/test/libcxx/utilities/memory/util.smartptr/util.smartptr.shared/libcxx.control_block_layout.pass.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -26,6 +27,128 @@ #include "test_macros.h" +namespace std { +struct __default_init_tag {}; +struct __value_init_tag {}; + +template ::value && !__libcpp_is_final<_Tp>::value> +struct __compressed_pair_elem { + using _ParamT = _Tp; + using reference = _Tp&; + using const_reference = const _Tp&; + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_() {} + + template >::value> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(_Up&& __u) + : __value_(std::forward<_Up>(__u)) {} + +#ifndef _LIBCPP_CXX03_LANG + template + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 explicit __compressed_pair_elem( + piecewise_construct_t, tuple<_Args...> __args, __tuple_indices<_Indices...>) + : __value_(std::forward<_Args>(std::get<_Indices>(__args))...) {} +#endif + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference __get() _NOEXCEPT { return __value_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return __value_; } + +private: + _Tp __value_; +}; + +template +struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp { + using _ParamT = _Tp; + using reference = _Tp&; + using const_reference = const _Tp&; + using __value_type = _Tp; + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem() = default; + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_type() {} + + template >::value> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(_Up&& __u) + : __value_type(std::forward<_Up>(__u)) {} + +#ifndef _LIBCPP_CXX03_LANG + template + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 + __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, __tuple_indices<_Indices...>) + : __value_type(std::forward<_Args>(std::get<_Indices>(__args))...) {} +#endif + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference __get() _NOEXCEPT { return *this; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return *this; } +}; + +template +class __compressed_pair : private __compressed_pair_elem<_T1, 0>, private __compressed_pair_elem<_T2, 1> { +public: + // NOTE: This static assert should never fire because __compressed_pair + // is *almost never* used in a scenario where it's possible for T1 == T2. + // (The exception is std::function where it is possible that the function + // object and the allocator have the same type). + static_assert( + (!is_same<_T1, _T2>::value), + "__compressed_pair cannot be instantiated when T1 and T2 are the same type; " + "The current implementation is NOT ABI-compatible with the previous implementation for this configuration"); + + using _Base1 _LIBCPP_NODEBUG = __compressed_pair_elem<_T1, 0>; + using _Base2 _LIBCPP_NODEBUG = __compressed_pair_elem<_T2, 1>; + + template , _Dummy>::value && + __dependent_type, _Dummy>::value > > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair() + : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {} + + template + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair(_U1&& __t1, _U2&& __t2) + : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {} + +#ifndef _LIBCPP_CXX03_LANG + template + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 explicit __compressed_pair( + piecewise_construct_t __pc, tuple<_Args1...> __first_args, tuple<_Args2...> __second_args) + : _Base1(__pc, std::move(__first_args), typename __make_tuple_indices::type()), + _Base2(__pc, std::move(__second_args), typename __make_tuple_indices::type()) {} +#endif + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename _Base1::reference first() _NOEXCEPT { + return static_cast<_Base1&>(*this).__get(); + } + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename _Base1::const_reference first() const _NOEXCEPT { + return static_cast<_Base1 const&>(*this).__get(); + } + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename _Base2::reference second() _NOEXCEPT { + return static_cast<_Base2&>(*this).__get(); + } + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename _Base2::const_reference second() const _NOEXCEPT { + return static_cast<_Base2 const&>(*this).__get(); + } + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static _Base1* __get_first_base(__compressed_pair* __pair) _NOEXCEPT { + return static_cast<_Base1*>(__pair); + } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static _Base2* __get_second_base(__compressed_pair* __pair) _NOEXCEPT { + return static_cast<_Base2*>(__pair); + } + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void swap(__compressed_pair& __x) + _NOEXCEPT_(__is_nothrow_swappable<_T1>::value&& __is_nothrow_swappable<_T2>::value) { + using std::swap; + swap(first(), __x.first()); + swap(second(), __x.second()); + } +}; +} // namespace std + // This is the pre-C++20 implementation of the control block used by non-array // std::allocate_shared and std::make_shared. We keep it here so that we can // make sure our implementation is backwards compatible with it forever.