diff --git a/libcxx/include/list b/libcxx/include/list --- a/libcxx/include/list +++ b/libcxx/include/list @@ -270,11 +270,21 @@ struct __list_node : public __list_node_base<_Tp, _VoidPtr> { - _Tp __value_; + +#ifndef _LIBCPP_CXX03_LANG + union { + _Tp __value_; + }; +#else + typename aligned_storage::type __value_; +#endif typedef __list_node_base<_Tp, _VoidPtr> __base; typedef typename __base::__link_pointer __link_pointer; + _LIBCPP_INLINE_VISIBILITY + __list_node() {} + _LIBCPP_INLINE_VISIBILITY __link_pointer __as_link() { return static_cast<__link_pointer>(__base::__self()); @@ -360,7 +370,11 @@ _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable list::iterator"); #endif +#ifndef _LIBCPP_CXX03_LANG return __ptr_->__as_node()->__value_; +#else + return *reinterpret_cast(&__ptr_->__as_node()->__value_); +#endif } _LIBCPP_INLINE_VISIBILITY pointer operator->() const @@ -487,7 +501,12 @@ _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable list::const_iterator"); #endif + +#ifndef _LIBCPP_CXX03_LANG return __ptr_->__as_node()->__value_; +#else + return *reinterpret_cast(&__ptr_->__as_node()->__value_); +#endif } _LIBCPP_INLINE_VISIBILITY pointer operator->() const @@ -496,7 +515,13 @@ _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable list::const_iterator"); #endif + +#ifndef _LIBCPP_CXX03_LANG return pointer_traits::pointer_to(__ptr_->__as_node()->__value_); +#else + return pointer_traits::pointer_to( + *reinterpret_cast(&__ptr_->__as_node()->__value_)); +#endif } _LIBCPP_INLINE_VISIBILITY @@ -761,7 +786,12 @@ { __node_pointer __np = __f->__as_node(); __f = __f->__next_; +#ifndef _LIBCPP_CXX03_LANG __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); +#else + __node_alloc_traits::destroy(__na, _VSTD::addressof( + *reinterpret_cast(&__np->__value_))); +#endif __node_alloc_traits::deallocate(__na, __np, 1); } __invalidate_all_iterators(); @@ -978,25 +1008,41 @@ reference front() { _LIBCPP_ASSERT(!empty(), "list::front called on empty list"); +#ifndef _LIBCPP_CXX03_LANG return base::__end_.__next_->__as_node()->__value_; +#else + return *reinterpret_cast(&base::__end_.__next_->__as_node()->__value_); +#endif } _LIBCPP_INLINE_VISIBILITY const_reference front() const { _LIBCPP_ASSERT(!empty(), "list::front called on empty list"); +#ifndef _LIBCPP_CXX03_LANG return base::__end_.__next_->__as_node()->__value_; +#else + return *reinterpret_cast(&base::__end_.__next_->__as_node()->__value_); +#endif } _LIBCPP_INLINE_VISIBILITY reference back() { _LIBCPP_ASSERT(!empty(), "list::back called on empty list"); +#ifndef _LIBCPP_CXX03_LANG return base::__end_.__prev_->__as_node()->__value_; +#else + return *reinterpret_cast(&base::__end_.__prev_->__as_node()->__value_); +#endif } _LIBCPP_INLINE_VISIBILITY const_reference back() const { _LIBCPP_ASSERT(!empty(), "list::back called on empty list"); +#ifndef _LIBCPP_CXX03_LANG return base::__end_.__prev_->__as_node()->__value_; +#else + return *reinterpret_cast(&base::__end_.__prev_->__as_node()->__value_); +#endif } #ifndef _LIBCPP_CXX03_LANG @@ -1113,6 +1159,7 @@ _LIBCPP_INLINE_VISIBILITY __hold_pointer __allocate_node(__node_allocator& __na) { __node_pointer __p = __node_alloc_traits::allocate(__na, 1); + ::new ((void*)_VSTD::addressof(*__p)) __node(); __p->__prev_ = nullptr; return __hold_pointer(__p, __node_destructor(__na, 1)); } @@ -1456,7 +1503,12 @@ #endif __node_allocator& __na = base::__node_alloc(); __hold_pointer __hold = __allocate_node(__na); +#ifndef _LIBCPP_CXX03_LANG __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); +#else + __node_alloc_traits::construct(__na, _VSTD::addressof( + *reinterpret_cast(&__hold->__value_)), __x); +#endif __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link()); ++base::__sz(); #if _LIBCPP_DEBUG_LEVEL == 2 @@ -1483,7 +1535,13 @@ size_type __ds = 0; __node_allocator& __na = base::__node_alloc(); __hold_pointer __hold = __allocate_node(__na); +#ifndef _LIBCPP_CXX03_LANG __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); +#else + __node_alloc_traits::construct(__na, _VSTD::addressof( + *reinterpret_cast(&__hold->__value_)), __x); +#endif + ++__ds; #if _LIBCPP_DEBUG_LEVEL == 2 __r = iterator(__hold->__as_link(), this); @@ -1499,7 +1557,12 @@ for (--__n; __n != 0; --__n, ++__e, ++__ds) { __hold.reset(__node_alloc_traits::allocate(__na, 1)); +#ifndef _LIBCPP_CXX03_LANG __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); +#else + __node_alloc_traits::construct(__na, _VSTD::addressof( + *reinterpret_cast(&__hold->__value_)), __x); +#endif __e.__ptr_->__next_ = __hold->__as_link(); __hold->__prev_ = __e.__ptr_; __hold.release(); @@ -1549,7 +1612,12 @@ size_type __ds = 0; __node_allocator& __na = base::__node_alloc(); __hold_pointer __hold = __allocate_node(__na); +#ifndef _LIBCPP_CXX03_LANG __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f); +#else + __node_alloc_traits::construct(__na, _VSTD::addressof( + *reinterpret_cast(&__hold->__value_)), *__f); +#endif ++__ds; #if _LIBCPP_DEBUG_LEVEL == 2 __r = iterator(__hold.get()->__as_link(), this); @@ -1565,7 +1633,12 @@ for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds) { __hold.reset(__node_alloc_traits::allocate(__na, 1)); +#ifndef _LIBCPP_CXX03_LANG __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f); +#else + __node_alloc_traits::construct(__na, _VSTD::addressof( + *reinterpret_cast(&__hold->__value_)), *__f); +#endif __e.__ptr_->__next_ = __hold.get()->__as_link(); __hold->__prev_ = __e.__ptr_; __hold.release(); @@ -1602,7 +1675,13 @@ { __node_allocator& __na = base::__node_alloc(); __hold_pointer __hold = __allocate_node(__na); +#ifndef _LIBCPP_CXX03_LANG __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); +#else + __node_alloc_traits::construct(__na, _VSTD::addressof( + *reinterpret_cast(&__hold->__value_)), __x); +#endif + __link_pointer __nl = __hold->__as_link(); __link_nodes_at_front(__nl, __nl); ++base::__sz(); @@ -1615,7 +1694,12 @@ { __node_allocator& __na = base::__node_alloc(); __hold_pointer __hold = __allocate_node(__na); +#ifndef _LIBCPP_CXX03_LANG __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); +#else + __node_alloc_traits::construct(__na, _VSTD::addressof( + *reinterpret_cast(&__hold->__value_)), __x); +#endif __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link()); ++base::__sz(); __hold.release(); @@ -1629,7 +1713,12 @@ { __node_allocator& __na = base::__node_alloc(); __hold_pointer __hold = __allocate_node(__na); +#ifndef _LIBCPP_CXX03_LANG __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); +#else + __node_alloc_traits::construct(__na, _VSTD::addressof( + *reinterpret_cast(&__hold->__value_), _VSTD::move(__x)); +#endif __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link()); ++base::__sz(); __hold.release(); @@ -1641,7 +1730,12 @@ { __node_allocator& __na = base::__node_alloc(); __hold_pointer __hold = __allocate_node(__na); +#ifndef _LIBCPP_CXX03_LANG __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); +#else + __node_alloc_traits::construct(__na, _VSTD::addressof( + *reinterpret_cast(&__hold->__value_), __x); +#endif __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link()); ++base::__sz(); __hold.release(); @@ -1658,11 +1752,21 @@ { __node_allocator& __na = base::__node_alloc(); __hold_pointer __hold = __allocate_node(__na); +#ifndef _LIBCPP_CXX03_LANG __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); +#else + __node_alloc_traits::construct(__na, _VSTD::addressof( + *reinterpret_cast(&__hold->__value_), _VSTD::forward<_Args>(__args)...); +#endif __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link()); ++base::__sz(); #if _LIBCPP_STD_VER > 14 +#ifndef _LIBCPP_CXX03_LANG return __hold.release()->__value_; +#else + return *reinterpret_cast(&__hold.release()->__value_); +#endif + #else __hold.release(); #endif @@ -1679,12 +1783,21 @@ { __node_allocator& __na = base::__node_alloc(); __hold_pointer __hold = __allocate_node(__na); +#ifndef _LIBCPP_CXX03_LANG __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); +#else + __node_alloc_traits::construct(__na, _VSTD::addressof( + *reinterpret_cast(&__hold->__value_), _VSTD::forward<_Args>(__args)...); +#endif __link_pointer __nl = __hold->__as_link(); __link_nodes_at_back(__nl, __nl); ++base::__sz(); #if _LIBCPP_STD_VER > 14 +#ifndef _LIBCPP_CXX03_LANG return __hold.release()->__value_; +#else + return *reinterpret_cast(&__hold.release()->__value_); +#endif #else __hold.release(); #endif @@ -1955,7 +2068,12 @@ size_type __ds = 0; __node_allocator& __na = base::__node_alloc(); __hold_pointer __hold = __allocate_node(__na); +#ifndef _LIBCPP_CXX03_LANG __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); +#else + __node_alloc_traits::construct(__na, _VSTD::addressof( + *reinterpret_cast(&__hold->__value_)), __x); +#endif ++__ds; __link_pointer __nl = __hold.release()->__as_link(); #if _LIBCPP_DEBUG_LEVEL == 2 @@ -1971,7 +2089,12 @@ for (--__n; __n != 0; --__n, ++__e, ++__ds) { __hold.reset(__node_alloc_traits::allocate(__na, 1)); +#ifndef _LIBCPP_CXX03_LANG __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); +#else + __node_alloc_traits::construct(__na, _VSTD::addressof( + *reinterpret_cast(&__hold->__value_)), __x); +#endif __e.__ptr_->__next_ = __hold.get()->__as_link(); __hold->__prev_ = __e.__ptr_; __hold.release(); diff --git a/libcxx/include/optional b/libcxx/include/optional --- a/libcxx/include/optional +++ b/libcxx/include/optional @@ -215,7 +215,7 @@ "instantiation of optional with a non-object type is undefined behavior"); union { - char __null_state_; + // char __null_state_; value_type __val_; }; bool __engaged_; @@ -229,7 +229,7 @@ _LIBCPP_INLINE_VISIBILITY constexpr __optional_destruct_base() noexcept - : __null_state_(), + : /* __null_state_(), */ __engaged_(false) {} template @@ -257,14 +257,14 @@ "instantiation of optional with a non-object type is undefined behavior"); union { - char __null_state_; + // char __null_state_; value_type __val_; }; bool __engaged_; _LIBCPP_INLINE_VISIBILITY constexpr __optional_destruct_base() noexcept - : __null_state_(), + : /* __null_state_(), */ __engaged_(false) {} template