Skip to content

Commit

Permalink
Revert "Revert "[libc++] LWG3870: Remove voidify (llvm#110355)" (ll…
Browse files Browse the repository at this point in the history
…vm#110587)"

This reverts commit f3d58f4.
  • Loading branch information
frederick-vs-ja committed Oct 3, 2024
1 parent 6ae14c0 commit a3942b3
Show file tree
Hide file tree
Showing 21 changed files with 24 additions and 297 deletions.
2 changes: 1 addition & 1 deletion libcxx/docs/Status/Cxx23Issues.csv
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
"`LWG3862 <https://wg21.link/LWG3862>`__","``basic_const_iterator``'s ``common_type`` specialization is underconstrained","2023-02 (Issaquah)","","",""
"`LWG3865 <https://wg21.link/LWG3865>`__","Sorting a range of ``pairs``","2023-02 (Issaquah)","|Complete|","17.0",""
"`LWG3869 <https://wg21.link/LWG3869>`__","Deprecate ``std::errc`` constants related to UNIX STREAMS","2023-02 (Issaquah)","|Complete|","19.0",""
"`LWG3870 <https://wg21.link/LWG3870>`__","Remove ``voidify``","2023-02 (Issaquah)","","",""
"`LWG3870 <https://wg21.link/LWG3870>`__","Remove ``voidify``","2023-02 (Issaquah)","|Complete|","20.0",""
"`LWG3871 <https://wg21.link/LWG3871>`__","Adjust note about ``terminate``","2023-02 (Issaquah)","","",""
"`LWG3872 <https://wg21.link/LWG3872>`__","``basic_const_iterator`` should have custom ``iter_move``","2023-02 (Issaquah)","","",""
"`LWG3875 <https://wg21.link/LWG3875>`__","``std::ranges::repeat_view<T, IntegerClass>::iterator`` may be ill-formed","2023-02 (Issaquah)","|Complete|","17.0",""
Expand Down
1 change: 0 additions & 1 deletion libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,6 @@ set(files
__memory/unique_temporary_buffer.h
__memory/uses_allocator.h
__memory/uses_allocator_construction.h
__memory/voidify.h
__memory_resource/memory_resource.h
__memory_resource/monotonic_buffer_resource.h
__memory_resource/polymorphic_allocator.h
Expand Down
5 changes: 2 additions & 3 deletions libcxx/include/__memory/construct_at.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <__config>
#include <__iterator/access.h>
#include <__memory/addressof.h>
#include <__memory/voidify.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/is_array.h>
#include <__utility/declval.h>
Expand All @@ -38,7 +37,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class... _Args, class = decltype(::new(std::declval<void*>()) _Tp(std::declval<_Args>()...))>
_LIBCPP_HIDE_FROM_ABI constexpr _Tp* construct_at(_Tp* __location, _Args&&... __args) {
_LIBCPP_ASSERT_NON_NULL(__location != nullptr, "null pointer given to construct_at");
return ::new (std::__voidify(*__location)) _Tp(std::forward<_Args>(__args)...);
return ::new (static_cast<void*>(__location)) _Tp(std::forward<_Args>(__args)...);
}

#endif
Expand All @@ -49,7 +48,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* __construct_at(_Tp* __l
return std::construct_at(__location, std::forward<_Args>(__args)...);
#else
return _LIBCPP_ASSERT_NON_NULL(__location != nullptr, "null pointer given to construct_at"),
::new (std::__voidify(*__location)) _Tp(std::forward<_Args>(__args)...);
::new (static_cast<void*>(__location)) _Tp(std::forward<_Args>(__args)...);
#endif
}

Expand Down
14 changes: 8 additions & 6 deletions libcxx/include/__memory/shared_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,33 +248,35 @@ struct __for_overwrite_tag {};

template <class _Tp, class _Alloc>
struct __shared_ptr_emplace : __shared_weak_count {
using __value_type = __remove_cv_t<_Tp>;

template <class... _Args,
class _Allocator = _Alloc,
__enable_if_t<is_same<typename _Allocator::value_type, __for_overwrite_tag>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI explicit __shared_ptr_emplace(_Alloc __a, _Args&&...) : __storage_(std::move(__a)) {
static_assert(
sizeof...(_Args) == 0, "No argument should be provided to the control block when using _for_overwrite");
::new ((void*)__get_elem()) _Tp;
::new (static_cast<void*>(__get_elem())) __value_type;
}

template <class... _Args,
class _Allocator = _Alloc,
__enable_if_t<!is_same<typename _Allocator::value_type, __for_overwrite_tag>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI explicit __shared_ptr_emplace(_Alloc __a, _Args&&... __args) : __storage_(std::move(__a)) {
using _TpAlloc = typename __allocator_traits_rebind<_Alloc, __remove_cv_t<_Tp> >::type;
using _TpAlloc = typename __allocator_traits_rebind<_Alloc, __value_type>::type;
_TpAlloc __tmp(*__get_alloc());
allocator_traits<_TpAlloc>::construct(__tmp, __get_elem(), std::forward<_Args>(__args)...);
}

_LIBCPP_HIDE_FROM_ABI _Alloc* __get_alloc() _NOEXCEPT { return __storage_.__get_alloc(); }

_LIBCPP_HIDE_FROM_ABI _Tp* __get_elem() _NOEXCEPT { return __storage_.__get_elem(); }
_LIBCPP_HIDE_FROM_ABI __value_type* __get_elem() _NOEXCEPT { return __storage_.__get_elem(); }

private:
template <class _Allocator = _Alloc,
__enable_if_t<is_same<typename _Allocator::value_type, __for_overwrite_tag>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI void __on_zero_shared_impl() _NOEXCEPT {
__get_elem()->~_Tp();
__get_elem()->~__value_type();
}

template <class _Allocator = _Alloc,
Expand All @@ -300,7 +302,7 @@ struct __shared_ptr_emplace : __shared_weak_count {
// through `std::allocate_shared` and `std::make_shared`.
struct _Storage {
struct _Data {
_LIBCPP_COMPRESSED_PAIR(_Alloc, __alloc_, _Tp, __elem_);
_LIBCPP_COMPRESSED_PAIR(_Alloc, __alloc_, __value_type, __elem_);
};

_ALIGNAS_TYPE(_Data) char __buffer_[sizeof(_Data)];
Expand All @@ -312,7 +314,7 @@ struct __shared_ptr_emplace : __shared_weak_count {
return std::addressof(reinterpret_cast<_Data*>(__buffer_)->__alloc_);
}

_LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _Tp* __get_elem() _NOEXCEPT {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI __value_type* __get_elem() _NOEXCEPT {
return std::addressof(reinterpret_cast<_Data*>(__buffer_)->__elem_);
}
};
Expand Down
21 changes: 10 additions & 11 deletions libcxx/include/__memory/uninitialized_algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <__memory/allocator_traits.h>
#include <__memory/construct_at.h>
#include <__memory/pointer_traits.h>
#include <__memory/voidify.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/extent.h>
#include <__type_traits/is_array.h>
Expand Down Expand Up @@ -64,7 +63,7 @@ inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitiali
try {
#endif
for (; __ifirst != __ilast && !__stop_copying(__idx); ++__ifirst, (void)++__idx)
::new (std::__voidify(*__idx)) _ValueType(*__ifirst);
::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(*__ifirst);
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
} catch (...) {
std::__destroy(__ofirst, __idx);
Expand Down Expand Up @@ -94,7 +93,7 @@ __uninitialized_copy_n(_InputIterator __ifirst, _Size __n, _ForwardIterator __of
try {
#endif
for (; __n > 0 && !__stop_copying(__idx); ++__ifirst, (void)++__idx, (void)--__n)
::new (std::__voidify(*__idx)) _ValueType(*__ifirst);
::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(*__ifirst);
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
} catch (...) {
std::__destroy(__ofirst, __idx);
Expand Down Expand Up @@ -124,7 +123,7 @@ __uninitialized_fill(_ForwardIterator __first, _Sentinel __last, const _Tp& __x)
try {
#endif
for (; __idx != __last; ++__idx)
::new (std::__voidify(*__idx)) _ValueType(__x);
::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__x);
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
} catch (...) {
std::__destroy(__first, __idx);
Expand Down Expand Up @@ -152,7 +151,7 @@ __uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) {
try {
#endif
for (; __n > 0; ++__idx, (void)--__n)
::new (std::__voidify(*__idx)) _ValueType(__x);
::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__x);
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
} catch (...) {
std::__destroy(__first, __idx);
Expand Down Expand Up @@ -182,7 +181,7 @@ __uninitialized_default_construct(_ForwardIterator __first, _Sentinel __last) {
try {
# endif
for (; __idx != __last; ++__idx)
::new (std::__voidify(*__idx)) _ValueType;
::new (static_cast<void*>(std::addressof(*__idx))) _ValueType;
# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
} catch (...) {
std::__destroy(__first, __idx);
Expand All @@ -208,7 +207,7 @@ inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_default_construct_
try {
# endif
for (; __n > 0; ++__idx, (void)--__n)
::new (std::__voidify(*__idx)) _ValueType;
::new (static_cast<void*>(std::addressof(*__idx))) _ValueType;
# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
} catch (...) {
std::__destroy(__first, __idx);
Expand All @@ -235,7 +234,7 @@ __uninitialized_value_construct(_ForwardIterator __first, _Sentinel __last) {
try {
# endif
for (; __idx != __last; ++__idx)
::new (std::__voidify(*__idx)) _ValueType();
::new (static_cast<void*>(std::addressof(*__idx))) _ValueType();
# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
} catch (...) {
std::__destroy(__first, __idx);
Expand All @@ -261,7 +260,7 @@ inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_value_construct_n(
try {
# endif
for (; __n > 0; ++__idx, (void)--__n)
::new (std::__voidify(*__idx)) _ValueType();
::new (static_cast<void*>(std::addressof(*__idx))) _ValueType();
# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
} catch (...) {
std::__destroy(__first, __idx);
Expand Down Expand Up @@ -297,7 +296,7 @@ inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitiali
try {
# endif
for (; __ifirst != __ilast && !__stop_moving(__idx); ++__idx, (void)++__ifirst) {
::new (std::__voidify(*__idx)) _ValueType(__iter_move(__ifirst));
::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__iter_move(__ifirst));
}
# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
} catch (...) {
Expand Down Expand Up @@ -335,7 +334,7 @@ inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitiali
try {
# endif
for (; __n > 0 && !__stop_moving(__idx); ++__idx, (void)++__ifirst, --__n)
::new (std::__voidify(*__idx)) _ValueType(__iter_move(__ifirst));
::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__iter_move(__ifirst));
# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
} catch (...) {
std::__destroy(__ofirst, __idx);
Expand Down
30 changes: 0 additions & 30 deletions libcxx/include/__memory/voidify.h

This file was deleted.

1 change: 0 additions & 1 deletion libcxx/include/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,6 @@ module std [system] {
}
module uses_allocator { header "__memory/uses_allocator.h" }
module uses_allocator_construction { header "__memory/uses_allocator_construction.h" }
module voidify { header "__memory/voidify.h" }

header "memory"
export *
Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/optional
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ struct __optional_destruct_base<_Tp, false> {
static_assert(is_object_v<value_type>, "instantiation of optional with a non-object type is undefined behavior");
union {
char __null_state_;
value_type __val_;
remove_cv_t<value_type> __val_;
};
bool __engaged_;

Expand Down Expand Up @@ -323,7 +323,7 @@ struct __optional_destruct_base<_Tp, true> {
static_assert(is_object_v<value_type>, "instantiation of optional with a non-object type is undefined behavior");
union {
char __null_state_;
value_type __val_;
remove_cv_t<value_type> __val_;
};
bool __engaged_;

Expand Down Expand Up @@ -377,7 +377,7 @@ struct __optional_storage_base : __optional_destruct_base<_Tp> {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __assign_from(_That&& __opt) {
if (this->__engaged_ == __opt.has_value()) {
if (this->__engaged_)
this->__val_ = std::forward<_That>(__opt).__get();
static_cast<_Tp&>(this->__val_) = std::forward<_That>(__opt).__get();
} else {
if (this->__engaged_)
this->reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,6 @@ constexpr bool test()
a.deallocate(p, 2);
}

{
std::allocator<Counted> a;
Counted const* p = a.allocate(2);
int count = 0;
std::construct_at(p, count);
assert(count == 1);
std::construct_at(p+1, count);
assert(count == 2);
(p+1)->~Counted();
assert(count == 1);
p->~Counted();
assert(count == 0);
a.deallocate(const_cast<Counted*>(p), 2);
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,6 @@ constexpr bool test() {
alloc.deallocate(out, 2);
}

// Works with const pointers.
{
int x = 1;
const int* ptr = &x;

const int* result = std::ranges::construct_at(ptr, 42);
assert(result == ptr);
assert(x == 42);
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,30 +163,5 @@ int main(int, char**) {
}
#endif // TEST_HAS_NO_EXCEPTIONS

// Works with const iterators, (iter, sentinel) overload.
{
constexpr int N = 5;
Buffer<Counted, N> buf;

std::ranges::uninitialized_default_construct(buf.cbegin(), buf.cend());
assert(Counted::current_objects == N);
assert(Counted::total_objects == N);
std::destroy(buf.begin(), buf.end());
Counted::reset();
}

// Works with const iterators, (range) overload.
{
constexpr int N = 5;
Buffer<Counted, N> buf;
auto range = std::ranges::subrange(buf.cbegin(), buf.cend());

std::ranges::uninitialized_default_construct(range);
assert(Counted::current_objects == N);
assert(Counted::total_objects == N);
std::destroy(buf.begin(), buf.end());
Counted::reset();
}

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,5 @@ int main(int, char**) {
}
#endif // TEST_HAS_NO_EXCEPTIONS

// Works with const iterators.
{
constexpr int N = 5;
Buffer<Counted, N> buf;

std::ranges::uninitialized_default_construct_n(buf.cbegin(), N);
assert(Counted::current_objects == N);
assert(Counted::total_objects == N);
std::destroy(buf.begin(), buf.end());
Counted::reset();
}

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,30 +183,5 @@ int main(int, char**) {
}
#endif // TEST_HAS_NO_EXCEPTIONS

// Works with const iterators, (iter, sentinel) overload.
{
constexpr int N = 5;
Buffer<Counted, N> buf;

std::ranges::uninitialized_value_construct(buf.cbegin(), buf.cend());
assert(Counted::current_objects == N);
assert(Counted::total_objects == N);
std::destroy(buf.begin(), buf.end());
Counted::reset();
}

// Works with const iterators, (range) overload.
{
constexpr int N = 5;
Buffer<Counted, N> buf;

auto range = std::ranges::subrange(buf.cbegin(), buf.cend());
std::ranges::uninitialized_value_construct(range);
assert(Counted::current_objects == N);
assert(Counted::total_objects == N);
std::destroy(buf.begin(), buf.end());
Counted::reset();
}

return 0;
}
Loading

0 comments on commit a3942b3

Please sign in to comment.