The vector test suite now passes for no-debug, debug-lite and debug-regular

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@139930 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant 2011-09-16 18:41:29 +00:00
parent abe2628b43
commit 0442b12591
2 changed files with 43 additions and 40 deletions

View File

@ -970,41 +970,41 @@ vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
template <class _Tp, class _Allocator>
vector<_Tp, _Allocator>::vector(size_type __n)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
if (__n > 0)
{
allocate(__n);
__construct_at_end(__n);
}
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _Tp, class _Allocator>
vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
if (__n > 0)
{
allocate(__n);
__construct_at_end(__n, __x);
}
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _Tp, class _Allocator>
vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
: __base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
if (__n > 0)
{
allocate(__n);
__construct_at_end(__n, __x);
}
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _Tp, class _Allocator>
@ -1013,11 +1013,11 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
typename enable_if<__is_input_iterator <_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value>::type*)
{
for (; __first != __last; ++__first)
push_back(*__first);
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
for (; __first != __last; ++__first)
push_back(*__first);
}
template <class _Tp, class _Allocator>
@ -1027,11 +1027,11 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, c
!__is_forward_iterator<_InputIterator>::value>::type*)
: __base(__a)
{
for (; __first != __last; ++__first)
push_back(*__first);
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
for (; __first != __last; ++__first)
push_back(*__first);
}
template <class _Tp, class _Allocator>
@ -1039,15 +1039,15 @@ template <class _ForwardIterator>
vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__n > 0)
{
allocate(__n);
__construct_at_end(__first, __last);
}
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _Tp, class _Allocator>
@ -1056,45 +1056,45 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las
typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
: __base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__n > 0)
{
allocate(__n);
__construct_at_end(__first, __last);
}
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _Tp, class _Allocator>
vector<_Tp, _Allocator>::vector(const vector& __x)
: __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
size_type __n = __x.size();
if (__n > 0)
{
allocate(__n);
__construct_at_end(__x.__begin_, __x.__end_);
}
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _Tp, class _Allocator>
vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
: __base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
size_type __n = __x.size();
if (__n > 0)
{
allocate(__n);
__construct_at_end(__x.__begin_, __x.__end_);
}
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
@ -1105,14 +1105,14 @@ vector<_Tp, _Allocator>::vector(vector&& __x)
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
: __base(_VSTD::move(__x.__alloc()))
{
this->__begin_ = __x.__begin_;
this->__end_ = __x.__end_;
this->__end_cap() = __x.__end_cap();
__x.__begin_ = __x.__end_ = __x.__end_cap() = 0;
#if _LIBCPP_DEBUG_LEVEL >= 2
__x.__invalidate_all_iterators();
__get_db()->__insert_c(this);
#endif
this->__begin_ = __x.__begin_;
this->__end_ = __x.__end_;
this->__end_cap() = __x.__end_cap();
__x.__begin_ = __x.__end_ = __x.__end_cap() = 0;
}
template <class _Tp, class _Allocator>
@ -1120,6 +1120,9 @@ _LIBCPP_INLINE_VISIBILITY inline
vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
: __base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
if (__a == __x.__alloc())
{
this->__begin_ = __x.__begin_;
@ -1133,9 +1136,6 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
typedef move_iterator<iterator> _I;
assign(_I(__x.begin()), _I(__x.end()));
}
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
@ -1144,14 +1144,14 @@ template <class _Tp, class _Allocator>
_LIBCPP_INLINE_VISIBILITY inline
vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
if (__il.size() > 0)
{
allocate(__il.size());
__construct_at_end(__il.begin(), __il.end());
}
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _Tp, class _Allocator>
@ -1159,14 +1159,14 @@ _LIBCPP_INLINE_VISIBILITY inline
vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
: __base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
if (__il.size() > 0)
{
allocate(__il.size());
__construct_at_end(__il.begin(), __il.end());
}
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
@ -1747,8 +1747,8 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __firs
#endif // _LIBCPP_NO_EXCEPTIONS
}
__p = _VSTD::rotate(__p, __old_last, this->__end_);
insert(__make_iter(__p), move_iterator<iterator>(__v.begin()),
move_iterator<iterator>(__v.end()));
insert(__make_iter(__p), make_move_iterator(__v.begin()),
make_move_iterator(__v.end()));
return begin() + __off;
}

View File

@ -58,6 +58,8 @@ int main()
assert(c2.empty());
assert(distance(c2.begin(), c2.end()) == 0);
}
#ifndef _LIBCPP_DEBUG_LEVEL
// This test known to result in undefined behavior detected by _LIBCPP_DEBUG_LEVEL >= 1
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
@ -70,6 +72,7 @@ int main()
assert((c2 == std::vector<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0]))));
assert(c2.get_allocator() == A(2));
}
#endif
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};