[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
GitOrigin-RevId: be4c657b010c3fd850ca5cfcee0f96b464740523
diff --git a/include/memory b/include/memory
index b519339..883a01d 100644
--- a/include/memory
+++ b/include/memory
@@ -892,18 +892,13 @@
#if _LIBCPP_STD_VER > 17
-template<class _Tp>
-_LIBCPP_CONSTEXPR_AFTER_CXX17 void* __voidify(_Tp& __ptr) noexcept {
- return const_cast<void*>(static_cast<const volatile void*>(_VSTD::addressof(__ptr)));
-}
-
template<class _Tp, class ..._Args, class = decltype(
- ::new (_VSTD::declval<void*>()) _Tp(_VSTD::declval<_Args>()...)
+ ::new (declval<void*>()) _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 @@
template <class _Up, class... _Args>
_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 @@
template <class _Up, class... _Args>
_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 @@
_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 @@
{
#endif
for (; __f != __l; ++__f, (void) ++__r)
- ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
+ ::new ((void*)_VSTD::addressof(*__r)) value_type(*__f);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
@@ -2919,7 +2914,7 @@
{
#endif
for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
- ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
+ ::new ((void*)_VSTD::addressof(*__r)) value_type(*__f);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
@@ -2943,7 +2938,7 @@
{
#endif
for (; __f != __l; ++__f)
- ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
+ ::new ((void*)_VSTD::addressof(*__f)) value_type(__x);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
@@ -2966,7 +2961,7 @@
{
#endif
for (; __n > 0; ++__f, (void) --__n)
- ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
+ ::new ((void*)_VSTD::addressof(*__f)) value_type(__x);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
@@ -3005,7 +3000,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
typedef __allocator_destructor<_A2> _D2;
_A2 __a2(__a);
unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
- ::new(static_cast<void*>(_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 @@
typedef __allocator_destructor<_A2> _D2;
_A2 __a2(__a);
unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
- ::new(static_cast<void*>(_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 @@
_A2 __a2(__a);
unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
- ::new(static_cast<void*>(_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()));