From be4c657b010c3fd850ca5cfcee0f96b464740523 Mon Sep 17 00:00:00 2001 From: Arthur O'Dwyer Date: Fri, 11 Dec 2020 20:30:28 -0500 Subject: [PATCH] [libc++] Consistently replace `::new(__p) T` with `::new ((void*)__p) T`. NFCI. Everywhere, normalize the whitespace to `::new (EXPR) T`. Everywhere, normalize the spelling of the cast to `(void*)EXPR`. Without the cast to `(void*)`, the expression triggers ADL on GCC. (I think this is a GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98249) Even if it doesn't trigger ADL, it still seems incorrect to use any argument that's not exactly `(void*)` because that opens the possibility of overload resolution picking a user-defined overload of `operator new`, which would be wrong. Differential Revision: https://reviews.llvm.org/D93153 --- libcxx/include/__debug | 2 +- libcxx/include/__functional_03 | 48 +++++++++++----------- libcxx/include/algorithm | 36 ++++++++-------- libcxx/include/functional | 8 ++-- libcxx/include/future | 20 ++++----- libcxx/include/memory | 46 +++++++++------------ libcxx/include/optional | 2 +- libcxx/include/valarray | 42 +++++++++---------- .../algorithms/robust_against_adl_on_new.pass.cpp | 35 ++++++++++++++++ 9 files changed, 133 insertions(+), 106 deletions(-) create mode 100644 libcxx/test/std/algorithms/robust_against_adl_on_new.pass.cpp diff --git a/libcxx/include/__debug b/libcxx/include/__debug index be80275..7b5bfb3 100644 --- a/libcxx/include/__debug +++ b/libcxx/include/__debug @@ -221,7 +221,7 @@ public: template _LIBCPP_INLINE_VISIBILITY static __c_node* __create_C_node(void *__mem, void *__c, __c_node *__next) { - return ::new(__mem) _C_node<_Cont>(__c, __next); + return ::new (__mem) _C_node<_Cont>(__c, __next); } template diff --git a/libcxx/include/__functional_03 b/libcxx/include/__functional_03 index bf86428..9616480 100644 --- a/libcxx/include/__functional_03 +++ b/libcxx/include/__functional_03 @@ -126,7 +126,7 @@ __func<_Fp, _Alloc, _Rp()>::__clone() const _Ap __a(__f_.second()); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); + ::new ((void*)__hold.get()) __func(__f_.first(), _Alloc(__a)); return __hold.release(); } @@ -134,7 +134,7 @@ template void __func<_Fp, _Alloc, _Rp()>::__clone(__base<_Rp()>* __p) const { - ::new (__p) __func(__f_.first(), __f_.second()); + ::new ((void*)__p) __func(__f_.first(), __f_.second()); } template @@ -212,7 +212,7 @@ __func<_Fp, _Alloc, _Rp(_A0)>::__clone() const _Ap __a(__f_.second()); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); + ::new ((void*)__hold.get()) __func(__f_.first(), _Alloc(__a)); return __hold.release(); } @@ -220,7 +220,7 @@ template void __func<_Fp, _Alloc, _Rp(_A0)>::__clone(__base<_Rp(_A0)>* __p) const { - ::new (__p) __func(__f_.first(), __f_.second()); + ::new ((void*)__p) __func(__f_.first(), __f_.second()); } template @@ -298,7 +298,7 @@ __func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone() const _Ap __a(__f_.second()); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); + ::new ((void*)__hold.get()) __func(__f_.first(), _Alloc(__a)); return __hold.release(); } @@ -306,7 +306,7 @@ template void __func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone(__base<_Rp(_A0, _A1)>* __p) const { - ::new (__p) __func(__f_.first(), __f_.second()); + ::new ((void*)__p) __func(__f_.first(), __f_.second()); } template @@ -384,7 +384,7 @@ __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone() const _Ap __a(__f_.second()); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); + ::new ((void*)__hold.get()) __func(__f_.first(), _Alloc(__a)); return __hold.release(); } @@ -392,7 +392,7 @@ template void __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone(__base<_Rp(_A0, _A1, _A2)>* __p) const { - ::new (__p) __func(__f_.first(), __f_.second()); + ::new ((void*)__p) __func(__f_.first(), __f_.second()); } template @@ -554,7 +554,7 @@ function<_Rp()>::function(_Fp __f, if (sizeof(_FF) <= sizeof(__buf_)) { __f_ = (__base*)&__buf_; - ::new (__f_) _FF(__f); + ::new ((void*)__f_) _FF(__f); } else { @@ -562,7 +562,7 @@ function<_Rp()>::function(_Fp __f, _Ap __a; typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); + ::new ((void*)__hold.get()) _FF(__f, allocator<_Fp>(__a)); __f_ = __hold.release(); } } @@ -581,7 +581,7 @@ function<_Rp()>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, if (sizeof(_FF) <= sizeof(__buf_)) { __f_ = (__base*)&__buf_; - ::new (__f_) _FF(__f, __a0); + ::new ((void*)__f_) _FF(__f, __a0); } else { @@ -589,7 +589,7 @@ function<_Rp()>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, _Ap __a(__a0); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new (__hold.get()) _FF(__f, _Alloc(__a)); + ::new ((void*)__hold.get()) _FF(__f, _Alloc(__a)); __f_ = __hold.release(); } } @@ -834,7 +834,7 @@ function<_Rp(_A0)>::function(_Fp __f, if (sizeof(_FF) <= sizeof(__buf_)) { __f_ = (__base*)&__buf_; - ::new (__f_) _FF(__f); + ::new ((void*)__f_) _FF(__f); } else { @@ -842,7 +842,7 @@ function<_Rp(_A0)>::function(_Fp __f, _Ap __a; typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); + ::new ((void*)__hold.get()) _FF(__f, allocator<_Fp>(__a)); __f_ = __hold.release(); } } @@ -861,7 +861,7 @@ function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, if (sizeof(_FF) <= sizeof(__buf_)) { __f_ = (__base*)&__buf_; - ::new (__f_) _FF(__f, __a0); + ::new ((void*)__f_) _FF(__f, __a0); } else { @@ -869,7 +869,7 @@ function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, _Ap __a(__a0); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new (__hold.get()) _FF(__f, _Alloc(__a)); + ::new ((void*)__hold.get()) _FF(__f, _Alloc(__a)); __f_ = __hold.release(); } } @@ -1114,7 +1114,7 @@ function<_Rp(_A0, _A1)>::function(_Fp __f, if (sizeof(_FF) <= sizeof(__buf_)) { __f_ = (__base*)&__buf_; - ::new (__f_) _FF(__f); + ::new ((void*)__f_) _FF(__f); } else { @@ -1122,7 +1122,7 @@ function<_Rp(_A0, _A1)>::function(_Fp __f, _Ap __a; typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); + ::new ((void*)__hold.get()) _FF(__f, allocator<_Fp>(__a)); __f_ = __hold.release(); } } @@ -1141,7 +1141,7 @@ function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, if (sizeof(_FF) <= sizeof(__buf_)) { __f_ = (__base*)&__buf_; - ::new (__f_) _FF(__f, __a0); + ::new ((void*)__f_) _FF(__f, __a0); } else { @@ -1149,7 +1149,7 @@ function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, _Ap __a(__a0); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new (__hold.get()) _FF(__f, _Alloc(__a)); + ::new ((void*)__hold.get()) _FF(__f, _Alloc(__a)); __f_ = __hold.release(); } } @@ -1394,7 +1394,7 @@ function<_Rp(_A0, _A1, _A2)>::function(_Fp __f, if (sizeof(_FF) <= sizeof(__buf_)) { __f_ = (__base*)&__buf_; - ::new (__f_) _FF(__f); + ::new ((void*)__f_) _FF(__f); } else { @@ -1402,7 +1402,7 @@ function<_Rp(_A0, _A1, _A2)>::function(_Fp __f, _Ap __a; typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); + ::new ((void*)__hold.get()) _FF(__f, allocator<_Fp>(__a)); __f_ = __hold.release(); } } @@ -1421,7 +1421,7 @@ function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _Fp if (sizeof(_FF) <= sizeof(__buf_)) { __f_ = (__base*)&__buf_; - ::new (__f_) _FF(__f, __a0); + ::new ((void*)__f_) _FF(__f, __a0); } else { @@ -1429,7 +1429,7 @@ function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _Fp _Ap __a(__a0); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new (__hold.get()) _FF(__f, _Alloc(__a)); + ::new ((void*)__hold.get()) _FF(__f, _Alloc(__a)); __f_ = __hold.release(); } } diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm index b1771a1..7a4cc39 100644 --- a/libcxx/include/algorithm +++ b/libcxx/include/algorithm @@ -3404,7 +3404,7 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate // Move the falses into the temporary buffer, and the trues to the front of the line // Update __first to always point to the end of the trues value_type* __t = __p.first; - ::new(__t) value_type(_VSTD::move(*__first)); + ::new ((void*)__t) value_type(_VSTD::move(*__first)); __d.template __incr(); ++__t; _ForwardIterator __i = __first; @@ -3417,7 +3417,7 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate } else { - ::new(__t) value_type(_VSTD::move(*__i)); + ::new ((void*)__t) value_type(_VSTD::move(*__i)); __d.template __incr(); ++__t; } @@ -3534,7 +3534,7 @@ __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last // Move the falses into the temporary buffer, and the trues to the front of the line // Update __first to always point to the end of the trues value_type* __t = __p.first; - ::new(__t) value_type(_VSTD::move(*__first)); + ::new ((void*)__t) value_type(_VSTD::move(*__first)); __d.template __incr(); ++__t; _BidirectionalIterator __i = __first; @@ -3547,7 +3547,7 @@ __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last } else { - ::new(__t) value_type(_VSTD::move(*__i)); + ::new ((void*)__t) value_type(_VSTD::move(*__i)); __d.template __incr(); ++__t; } @@ -3922,7 +3922,7 @@ __insertion_sort_move(_BidirectionalIterator __first1, _BidirectionalIterator __ __destruct_n __d(0); unique_ptr __h(__first2, __d); value_type* __last2 = __first2; - ::new(__last2) value_type(_VSTD::move(*__first1)); + ::new ((void*)__last2) value_type(_VSTD::move(*__first1)); __d.template __incr(); for (++__last2; ++__first1 != __last1; ++__last2) { @@ -3930,7 +3930,7 @@ __insertion_sort_move(_BidirectionalIterator __first1, _BidirectionalIterator __ value_type* __i2 = __j2; if (__comp(*__first1, *--__i2)) { - ::new(__j2) value_type(_VSTD::move(*__i2)); + ::new ((void*)__j2) value_type(_VSTD::move(*__i2)); __d.template __incr(); for (--__j2; __i2 != __first2 && __comp(*__first1, *--__i2); --__j2) *__j2 = _VSTD::move(*__i2); @@ -3938,7 +3938,7 @@ __insertion_sort_move(_BidirectionalIterator __first1, _BidirectionalIterator __ } else { - ::new(__j2) value_type(_VSTD::move(*__first1)); + ::new ((void*)__j2) value_type(_VSTD::move(*__first1)); __d.template __incr(); } } @@ -4482,14 +4482,14 @@ __buffered_inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator { value_type* __p = __buff; for (_BidirectionalIterator __i = __first; __i != __middle; __d.template __incr(), (void) ++__i, (void) ++__p) - ::new(__p) value_type(_VSTD::move(*__i)); + ::new ((void*)__p) value_type(_VSTD::move(*__i)); _VSTD::__half_inplace_merge(__buff, __p, __middle, __last, __first, __comp); } else { value_type* __p = __buff; for (_BidirectionalIterator __i = __middle; __i != __last; __d.template __incr(), (void) ++__i, (void) ++__p) - ::new(__p) value_type(_VSTD::move(*__i)); + ::new ((void*)__p) value_type(_VSTD::move(*__i)); typedef reverse_iterator<_BidirectionalIterator> _RBi; typedef reverse_iterator _Rv; _VSTD::__half_inplace_merge(_Rv(__p), _Rv(__buff), @@ -4629,26 +4629,26 @@ __merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1, if (__first1 == __last1) { for (; __first2 != __last2; ++__first2, ++__result, (void)__d.template __incr()) - ::new (__result) value_type(_VSTD::move(*__first2)); + ::new ((void*)__result) value_type(_VSTD::move(*__first2)); __h.release(); return; } if (__first2 == __last2) { for (; __first1 != __last1; ++__first1, ++__result, (void)__d.template __incr()) - ::new (__result) value_type(_VSTD::move(*__first1)); + ::new ((void*)__result) value_type(_VSTD::move(*__first1)); __h.release(); return; } if (__comp(*__first2, *__first1)) { - ::new (__result) value_type(_VSTD::move(*__first2)); + ::new ((void*)__result) value_type(_VSTD::move(*__first2)); __d.template __incr(); ++__first2; } else { - ::new (__result) value_type(_VSTD::move(*__first1)); + ::new ((void*)__result) value_type(_VSTD::move(*__first1)); __d.template __incr(); ++__first1; } @@ -4702,24 +4702,24 @@ __stable_sort_move(_RandomAccessIterator __first1, _RandomAccessIterator __last1 case 0: return; case 1: - ::new(__first2) value_type(_VSTD::move(*__first1)); + ::new ((void*)__first2) value_type(_VSTD::move(*__first1)); return; case 2: __destruct_n __d(0); unique_ptr __h2(__first2, __d); if (__comp(*--__last1, *__first1)) { - ::new(__first2) value_type(_VSTD::move(*__last1)); + ::new ((void*)__first2) value_type(_VSTD::move(*__last1)); __d.template __incr(); ++__first2; - ::new(__first2) value_type(_VSTD::move(*__first1)); + ::new ((void*)__first2) value_type(_VSTD::move(*__first1)); } else { - ::new(__first2) value_type(_VSTD::move(*__first1)); + ::new ((void*)__first2) value_type(_VSTD::move(*__first1)); __d.template __incr(); ++__first2; - ::new(__first2) value_type(_VSTD::move(*__last1)); + ::new ((void*)__first2) value_type(_VSTD::move(*__last1)); } __h2.release(); return; diff --git a/libcxx/include/functional b/libcxx/include/functional index ffcff35..6d3d905 100644 --- a/libcxx/include/functional +++ b/libcxx/include/functional @@ -1609,7 +1609,7 @@ public: __builtin_new_allocator::__holder_t __hold = __builtin_new_allocator::__allocate_type<__default_alloc_func>(1); __default_alloc_func* __res = - ::new (__hold.get()) __default_alloc_func(__f_); + ::new ((void*)__hold.get()) __default_alloc_func(__f_); (void)__hold.release(); return __res; } @@ -1700,7 +1700,7 @@ template void __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const { - ::new (__p) __func(__f_.__target(), __f_.__get_allocator()); + ::new ((void*)__p) __func(__f_.__target(), __f_.__get_allocator()); } template @@ -2154,7 +2154,7 @@ template class __policy_func<_Rp(_ArgTypes...)> } else { __builtin_new_allocator::__holder_t __hold = __builtin_new_allocator::__allocate_type<_Fun>(1); - __buf_.__large = ::new (__hold.get()) _Fun(_VSTD::move(__f)); + __buf_.__large = ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f)); (void)__hold.release(); } } @@ -2286,7 +2286,7 @@ public: } virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const { - ::new (__p) __func(__f_); + ::new ((void*)__p) __func(__f_); } virtual void destroy() _NOEXCEPT { diff --git a/libcxx/include/future b/libcxx/include/future index 6e755c8..b414cb6 100644 --- a/libcxx/include/future +++ b/libcxx/include/future @@ -652,7 +652,7 @@ __assoc_state<_Rp>::set_value(_Arg&& __arg) unique_lock __lk(this->__mut_); if (this->__has_value()) __throw_future_error(future_errc::promise_already_satisfied); - ::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg)); + ::new ((void*)&__value_) _Rp(_VSTD::forward<_Arg>(__arg)); this->__state_ |= base::__constructed | base::ready; __cv_.notify_all(); } @@ -665,7 +665,7 @@ __assoc_state<_Rp>::set_value_at_thread_exit(_Arg&& __arg) unique_lock __lk(this->__mut_); if (this->__has_value()) __throw_future_error(future_errc::promise_already_satisfied); - ::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg)); + ::new ((void*)&__value_) _Rp(_VSTD::forward<_Arg>(__arg)); this->__state_ |= base::__constructed; __thread_local_data()->__make_ready_at_thread_exit(this); } @@ -1328,7 +1328,7 @@ promise<_Rp>::promise(allocator_arg_t, const _Alloc& __a0) typedef __allocator_destructor<_A2> _D2; _A2 __a(__a0); unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); - ::new(static_cast(_VSTD::addressof(*__hold.get()))) _State(__a0); + ::new ((void*)_VSTD::addressof(*__hold.get())) _State(__a0); __state_ = _VSTD::addressof(*__hold.release()); } @@ -1471,7 +1471,7 @@ promise<_Rp&>::promise(allocator_arg_t, const _Alloc& __a0) typedef __allocator_destructor<_A2> _D2; _A2 __a(__a0); unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); - ::new(static_cast(_VSTD::addressof(*__hold.get()))) _State(__a0); + ::new ((void*)_VSTD::addressof(*__hold.get())) _State(__a0); __state_ = _VSTD::addressof(*__hold.release()); } @@ -1590,7 +1590,7 @@ promise::promise(allocator_arg_t, const _Alloc& __a0) typedef __allocator_destructor<_A2> _D2; _A2 __a(__a0); unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); - ::new(static_cast(_VSTD::addressof(*__hold.get()))) _State(__a0); + ::new ((void*)_VSTD::addressof(*__hold.get())) _State(__a0); __state_ = _VSTD::addressof(*__hold.release()); } @@ -1655,7 +1655,7 @@ void __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__move_to( __packaged_task_base<_Rp(_ArgTypes...)>* __p) _NOEXCEPT { - ::new (__p) __packaged_task_func(_VSTD::move(__f_.first()), _VSTD::move(__f_.second())); + ::new ((void*)__p) __packaged_task_func(_VSTD::move(__f_.first()), _VSTD::move(__f_.second())); } template @@ -1748,7 +1748,7 @@ __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(_Fp&& __f) typedef __packaged_task_func<_FR, allocator<_FR>, _Rp(_ArgTypes...)> _FF; if (sizeof(_FF) <= sizeof(__buf_)) { - ::new (&__buf_) _FF(_VSTD::forward<_Fp>(__f)); + ::new ((void*)&__buf_) _FF(_VSTD::forward<_Fp>(__f)); __f_ = (__base*)&__buf_; } else @@ -1757,7 +1757,7 @@ __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(_Fp&& __f) _Ap __a; typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new (__hold.get()) _FF(_VSTD::forward<_Fp>(__f), allocator<_FR>(__a)); + ::new ((void*)__hold.get()) _FF(_VSTD::forward<_Fp>(__f), allocator<_FR>(__a)); __f_ = __hold.release(); } } @@ -1773,7 +1773,7 @@ __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function( if (sizeof(_FF) <= sizeof(__buf_)) { __f_ = (__base*)&__buf_; - ::new (__f_) _FF(_VSTD::forward<_Fp>(__f)); + ::new ((void*)__f_) _FF(_VSTD::forward<_Fp>(__f)); } else { @@ -1781,7 +1781,7 @@ __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function( _Ap __a(__a0); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new (static_cast(_VSTD::addressof(*__hold.get()))) + ::new ((void*)_VSTD::addressof(*__hold.get())) _FF(_VSTD::forward<_Fp>(__f), _Alloc(__a)); __f_ = _VSTD::addressof(*__hold.release()); } diff --git a/libcxx/include/memory b/libcxx/include/memory index b519339..883a01d 100644 --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -892,18 +892,13 @@ struct __rebind_pointer { #if _LIBCPP_STD_VER > 17 -template -_LIBCPP_CONSTEXPR_AFTER_CXX17 void* __voidify(_Tp& __ptr) noexcept { - return const_cast(static_cast(_VSTD::addressof(__ptr))); -} - template()) _Tp(_VSTD::declval<_Args>()...) + ::new (declval()) _Tp(declval<_Args>()...) )> _LIBCPP_INLINE_VISIBILITY constexpr _Tp* construct_at(_Tp* __location, _Args&& ...__args) { _LIBCPP_ASSERT(__location, "null pointer given to construct_at"); - return ::new (_VSTD::__voidify(*__location)) _Tp(_VSTD::forward<_Args>(__args)...); + return ::new ((void*)__location) _Tp(_VSTD::forward<_Args>(__args)...); } #endif @@ -1617,7 +1612,7 @@ public: template _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY void construct(_Up* __p, _Args&&... __args) { - ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); + ::new ((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); } _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY @@ -1694,7 +1689,7 @@ public: template _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY void construct(_Up* __p, _Args&&... __args) { - ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); + ::new ((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); } _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY @@ -1813,10 +1808,10 @@ public: _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {} _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;} _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element) - {::new(_VSTD::addressof(*__x_)) _Tp(__element); return *this;} + {::new ((void*)_VSTD::addressof(*__x_)) _Tp(__element); return *this;} #if _LIBCPP_STD_VER >= 14 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element) - {::new(_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;} + {::new ((void*)_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;} #endif _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;} _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int) @@ -2895,7 +2890,7 @@ uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r) { #endif for (; __f != __l; ++__f, (void) ++__r) - ::new (static_cast(_VSTD::addressof(*__r))) value_type(*__f); + ::new ((void*)_VSTD::addressof(*__r)) value_type(*__f); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -2919,7 +2914,7 @@ uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r) { #endif for (; __n > 0; ++__f, (void) ++__r, (void) --__n) - ::new (static_cast(_VSTD::addressof(*__r))) value_type(*__f); + ::new ((void*)_VSTD::addressof(*__r)) value_type(*__f); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -2943,7 +2938,7 @@ uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x) { #endif for (; __f != __l; ++__f) - ::new (static_cast(_VSTD::addressof(*__f))) value_type(__x); + ::new ((void*)_VSTD::addressof(*__f)) value_type(__x); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -2966,7 +2961,7 @@ uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x) { #endif for (; __n > 0; ++__f, (void) --__n) - ::new (static_cast(_VSTD::addressof(*__f))) value_type(__x); + ::new ((void*)_VSTD::addressof(*__f)) value_type(__x); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -3005,7 +3000,7 @@ void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator try { #endif for (; __idx != __last; ++__idx) - ::new((void*)_VSTD::addressof(*__idx)) _Vt; + ::new ((void*)_VSTD::addressof(*__idx)) _Vt; #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { _VSTD::destroy(__first, __idx); @@ -3023,7 +3018,7 @@ _ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Si try { #endif for (; __n > 0; (void)++__idx, --__n) - ::new((void*)_VSTD::addressof(*__idx)) _Vt; + ::new ((void*)_VSTD::addressof(*__idx)) _Vt; return __idx; #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { @@ -3043,7 +3038,7 @@ void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __ try { #endif for (; __idx != __last; ++__idx) - ::new((void*)_VSTD::addressof(*__idx)) _Vt(); + ::new ((void*)_VSTD::addressof(*__idx)) _Vt(); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { _VSTD::destroy(__first, __idx); @@ -3061,7 +3056,7 @@ _ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size try { #endif for (; __n > 0; (void)++__idx, --__n) - ::new((void*)_VSTD::addressof(*__idx)) _Vt(); + ::new ((void*)_VSTD::addressof(*__idx)) _Vt(); return __idx; #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { @@ -3081,7 +3076,7 @@ _ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __fi try { #endif for (; __first != __last; (void)++__idx, ++__first) - ::new((void*)_VSTD::addressof(*__idx)) _Vt(_VSTD::move(*__first)); + ::new ((void*)_VSTD::addressof(*__idx)) _Vt(_VSTD::move(*__first)); return __idx; #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { @@ -3101,7 +3096,7 @@ uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) { try { #endif for (; __n > 0; ++__idx, (void)++__first, --__n) - ::new((void*)_VSTD::addressof(*__idx)) _Vt(_VSTD::move(*__first)); + ::new ((void*)_VSTD::addressof(*__idx)) _Vt(_VSTD::move(*__first)); return {__first, __idx}; #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { @@ -3728,8 +3723,7 @@ shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, typedef __allocator_destructor<_A2> _D2; _A2 __a2(__a); unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); - ::new(static_cast(_VSTD::addressof(*__hold2.get()))) - _CntrlBlk(__p, __d, __a); + ::new ((void*)_VSTD::addressof(*__hold2.get())) _CntrlBlk(__p, __d, __a); __cntrl_ = _VSTD::addressof(*__hold2.release()); __enable_weak_this(__p, __p); #ifndef _LIBCPP_NO_EXCEPTIONS @@ -3756,8 +3750,7 @@ shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) typedef __allocator_destructor<_A2> _D2; _A2 __a2(__a); unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); - ::new(static_cast(_VSTD::addressof(*__hold2.get()))) - _CntrlBlk(__p, __d, __a); + ::new ((void*)_VSTD::addressof(*__hold2.get())) _CntrlBlk(__p, __d, __a); __cntrl_ = _VSTD::addressof(*__hold2.release()); #ifndef _LIBCPP_NO_EXCEPTIONS } @@ -4054,8 +4047,7 @@ allocate_shared(const _Alloc& __a, _Args&& ...__args) _A2 __a2(__a); unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); - ::new(static_cast(_VSTD::addressof(*__hold2.get()))) - _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...); + ::new ((void*)_VSTD::addressof(*__hold2.get())) _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...); typename shared_ptr<_Tp>::element_type *__p = __hold2->__get_elem(); return shared_ptr<_Tp>::__create_with_control_block(__p, _VSTD::addressof(*__hold2.release())); diff --git a/libcxx/include/optional b/libcxx/include/optional index 570fa11..97a0bbe 100644 --- a/libcxx/include/optional +++ b/libcxx/include/optional @@ -321,7 +321,7 @@ struct __optional_storage_base : __optional_destruct_base<_Tp> void __construct(_Args&&... __args) { _LIBCPP_ASSERT(!has_value(), "__construct called for engaged __optional_storage"); - ::new((void*)_VSTD::addressof(this->__val_)) value_type(_VSTD::forward<_Args>(__args)...); + ::new ((void*)_VSTD::addressof(this->__val_)) value_type(_VSTD::forward<_Args>(__args)...); this->__engaged_ = true; } diff --git a/libcxx/include/valarray b/libcxx/include/valarray index 9654cd5..787d8ac 100644 --- a/libcxx/include/valarray +++ b/libcxx/include/valarray @@ -2753,7 +2753,7 @@ __val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const __r.__begin_ = __r.__end_ = allocator().allocate(__n); for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i) - ::new (__r.__end_) result_type(__expr_[__i]); + ::new ((void*)__r.__end_) result_type(__expr_[__i]); } return __r; } @@ -2774,7 +2774,7 @@ valarray<_Tp>::valarray(size_t __n) { #endif // _LIBCPP_NO_EXCEPTIONS for (size_t __n_left = __n; __n_left; --__n_left, ++__end_) - ::new (__end_) value_type(); + ::new ((void*)__end_) value_type(); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -2808,7 +2808,7 @@ valarray<_Tp>::valarray(const value_type* __p, size_t __n) { #endif // _LIBCPP_NO_EXCEPTIONS for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left) - ::new (__end_) value_type(*__p); + ::new ((void*)__end_) value_type(*__p); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -2833,7 +2833,7 @@ valarray<_Tp>::valarray(const valarray& __v) { #endif // _LIBCPP_NO_EXCEPTIONS for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p) - ::new (__end_) value_type(*__p); + ::new ((void*)__end_) value_type(*__p); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -2871,7 +2871,7 @@ valarray<_Tp>::valarray(initializer_list __il) #endif // _LIBCPP_NO_EXCEPTIONS size_t __n_left = __n; for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left) - ::new (__end_) value_type(*__p); + ::new ((void*)__end_) value_type(*__p); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -2900,7 +2900,7 @@ valarray<_Tp>::valarray(const slice_array& __sa) #endif // _LIBCPP_NO_EXCEPTIONS size_t __n_left = __n; for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left) - ::new (__end_) value_type(*__p); + ::new ((void*)__end_) value_type(*__p); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -2929,7 +2929,7 @@ valarray<_Tp>::valarray(const gslice_array& __ga) const value_type* __s = __ga.__vp_; for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; __i != __e; ++__i, ++__end_) - ::new (__end_) value_type(__s[*__i]); + ::new ((void*)__end_) value_type(__s[*__i]); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -2958,7 +2958,7 @@ valarray<_Tp>::valarray(const mask_array& __ma) const value_type* __s = __ma.__vp_; for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; __i != __e; ++__i, ++__end_) - ::new (__end_) value_type(__s[*__i]); + ::new ((void*)__end_) value_type(__s[*__i]); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -2987,7 +2987,7 @@ valarray<_Tp>::valarray(const indirect_array& __ia) const value_type* __s = __ia.__vp_; for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; __i != __e; ++__i, ++__end_) - ::new (__end_) value_type(__s[*__i]); + ::new ((void*)__end_) value_type(__s[*__i]); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -3269,7 +3269,7 @@ valarray<_Tp>::operator+() const { __r.__begin_ = __r.__end_ = allocator().allocate(__n); for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) - ::new (__r.__end_) value_type(+*__p); + ::new ((void*)__r.__end_) value_type(+*__p); } return __r; } @@ -3284,7 +3284,7 @@ valarray<_Tp>::operator-() const { __r.__begin_ = __r.__end_ = allocator().allocate(__n); for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) - ::new (__r.__end_) value_type(-*__p); + ::new ((void*)__r.__end_) value_type(-*__p); } return __r; } @@ -3299,7 +3299,7 @@ valarray<_Tp>::operator~() const { __r.__begin_ = __r.__end_ = allocator().allocate(__n); for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) - ::new (__r.__end_) value_type(~*__p); + ::new ((void*)__r.__end_) value_type(~*__p); } return __r; } @@ -3314,7 +3314,7 @@ valarray<_Tp>::operator!() const { __r.__begin_ = __r.__end_ = allocator().allocate(__n); for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) - ::new (__r.__end_) bool(!*__p); + ::new ((void*)__r.__end_) bool(!*__p); } return __r; } @@ -3649,11 +3649,11 @@ valarray<_Tp>::shift(int __i) const __te = __r.__begin_ + __n; } for (; __r.__end_ != __tb; ++__r.__end_) - ::new (__r.__end_) value_type(); + ::new ((void*)__r.__end_) value_type(); for (; __r.__end_ != __te; ++__r.__end_, ++__sb) - ::new (__r.__end_) value_type(*__sb); + ::new ((void*)__r.__end_) value_type(*__sb); for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_) - ::new (__r.__end_) value_type(); + ::new ((void*)__r.__end_) value_type(); } return __r; } @@ -3670,9 +3670,9 @@ valarray<_Tp>::cshift(int __i) const __i %= static_cast(__n); const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i; for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s) - ::new (__r.__end_) value_type(*__s); + ::new ((void*)__r.__end_) value_type(*__s); for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s) - ::new (__r.__end_) value_type(*__s); + ::new ((void*)__r.__end_) value_type(*__s); } return __r; } @@ -3687,7 +3687,7 @@ valarray<_Tp>::apply(value_type __f(value_type)) const { __r.__begin_ = __r.__end_ = allocator().allocate(__n); for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) - ::new (__r.__end_) value_type(__f(*__p)); + ::new ((void*)__r.__end_) value_type(__f(*__p)); } return __r; } @@ -3702,7 +3702,7 @@ valarray<_Tp>::apply(value_type __f(const value_type&)) const { __r.__begin_ = __r.__end_ = allocator().allocate(__n); for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) - ::new (__r.__end_) value_type(__f(*__p)); + ::new ((void*)__r.__end_) value_type(__f(*__p)); } return __r; } @@ -3733,7 +3733,7 @@ valarray<_Tp>::resize(size_t __n, value_type __x) { #endif // _LIBCPP_NO_EXCEPTIONS for (size_t __n_left = __n; __n_left; --__n_left, ++__end_) - ::new (__end_) value_type(__x); + ::new ((void*)__end_) value_type(__x); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) diff --git a/libcxx/test/std/algorithms/robust_against_adl_on_new.pass.cpp b/libcxx/test/std/algorithms/robust_against_adl_on_new.pass.cpp new file mode 100644 index 0000000..333f11d --- /dev/null +++ b/libcxx/test/std/algorithms/robust_against_adl_on_new.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03 + +// + +#include + +#include "test_macros.h" + +struct A { + int i; + A(int v) : i(v) {} + bool operator<(const A& rhs) const { return i < rhs.i; } + static bool isEven(const A& a) { return a.i % 2 == 0; } +}; + +void *operator new(size_t, A*) = delete; + +int main(int, char**) +{ + A a[4] = { 1,2,3,4 }; + std::sort(a, a+4); + std::partition(a, a+4, A::isEven); + std::stable_sort(a, a+4); + std::stable_partition(a, a+4, A::isEven); + + return 0; +} -- 2.7.4