Skip to content

Commit

Permalink
[libc++] Revert "Make vector unconditionally move elements when exc…
Browse files Browse the repository at this point in the history
…eptions are disabled."

This reverts r370502, which broke the use case of a copy-only T (with a
deleted move constructor) when exceptions are disabled. Until we figure
out the right behavior, I'm reverting the commit.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@371068 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
ldionne committed Sep 5, 2019
1 parent 7de36b7 commit ffced82
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 82 deletions.
26 changes: 7 additions & 19 deletions include/memory
Original file line number Diff line number Diff line change
Expand Up @@ -1609,16 +1609,10 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
_LIBCPP_INLINE_VISIBILITY
static
void
__construct_forward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
__construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
{
for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
construct(__a, _VSTD::__to_raw_pointer(__begin2),
#ifdef _LIBCPP_NO_EXCEPTIONS
_VSTD::move(*__begin1)
#else
_VSTD::move_if_noexcept(*__begin1)
#endif
);
construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
}

template <class _Tp>
Expand All @@ -1631,7 +1625,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
is_trivially_move_constructible<_Tp>::value,
void
>::type
__construct_forward_with_exception_guarantees(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
__construct_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
{
ptrdiff_t _Np = __end1 - __begin1;
if (_Np > 0)
Expand Down Expand Up @@ -1678,18 +1672,12 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
_LIBCPP_INLINE_VISIBILITY
static
void
__construct_backward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
__construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
{
while (__end1 != __begin1)
{
construct(__a, _VSTD::__to_raw_pointer(__end2 - 1),
#ifdef _LIBCPP_NO_EXCEPTIONS
_VSTD::move(*--__end1)
#else
_VSTD::move_if_noexcept(*--__end1)
#endif
);
--__end2;
construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
--__end2;
}
}

Expand All @@ -1703,7 +1691,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
is_trivially_move_constructible<_Tp>::value,
void
>::type
__construct_backward_with_exception_guarantees(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
__construct_backward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
{
ptrdiff_t _Np = __end1 - __begin1;
__end2 -= _Np;
Expand Down
9 changes: 3 additions & 6 deletions include/vector
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,7 @@ void
vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
{
__annotate_delete();
__alloc_traits::__construct_backward_with_exception_guarantees(
this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
__alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
_VSTD::swap(this->__begin_, __v.__begin_);
_VSTD::swap(this->__end_, __v.__end_);
_VSTD::swap(this->__end_cap(), __v.__end_cap());
Expand All @@ -964,10 +963,8 @@ vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, a
{
__annotate_delete();
pointer __r = __v.__begin_;
__alloc_traits::__construct_backward_with_exception_guarantees(
this->__alloc(), this->__begin_, __p, __v.__begin_);
__alloc_traits::__construct_forward_with_exception_guarantees(
this->__alloc(), __p, this->__end_, __v.__end_);
__alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_);
__alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_);
_VSTD::swap(this->__begin_, __v.__begin_);
_VSTD::swap(this->__end_, __v.__end_);
_VSTD::swap(this->__end_cap(), __v.__end_cap());
Expand Down

This file was deleted.

0 comments on commit ffced82

Please sign in to comment.