[libcxx] r178819 - More work on debug mode for list.
Howard Hinnant
hhinnant at apple.com
Thu Apr 4 17:18:49 PDT 2013
Author: hhinnant
Date: Thu Apr 4 19:18:49 2013
New Revision: 178819
URL: http://llvm.org/viewvc/llvm-project?rev=178819&view=rev
Log:
More work on debug mode for list.
Modified:
libcxx/trunk/include/list
libcxx/trunk/test/containers/sequences/list/list.modifiers/emplace.pass.cpp
libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp
libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_rvalue.pass.cpp
libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp
libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp
libcxx/trunk/test/containers/sequences/list/list.modifiers/pop_back.pass.cpp
Modified: libcxx/trunk/include/list
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/list?rev=178819&r1=178818&r2=178819&view=diff
==============================================================================
--- libcxx/trunk/include/list (original)
+++ libcxx/trunk/include/list Thu Apr 4 19:18:49 2013
@@ -1292,7 +1292,11 @@ list<_Tp, _Alloc>::insert(const_iterator
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
__link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold);
++base::__sz();
+#if _LIBCPP_DEBUG_LEVEL >= 2
+ return iterator(__hold.release(), this);
+#else
return iterator(__hold.release());
+#endif
}
template <class _Tp, class _Alloc>
@@ -1518,6 +1522,11 @@ template <class... _Args>
typename list<_Tp, _Alloc>::iterator
list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
{
+#if _LIBCPP_DEBUG_LEVEL >= 2
+ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+ "list::emplace(iterator, args...) called with an iterator not"
+ " referring to this list");
+#endif
__node_allocator& __na = base::__node_alloc();
typedef __allocator_destructor<__node_allocator> _Dp;
unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
@@ -1624,6 +1633,8 @@ list<_Tp, _Alloc>::erase(const_iterator
"list::erase(iterator) called with an iterator not"
" referring to this list");
#endif
+ _LIBCPP_ASSERT(__p != end(),
+ "list::erase(iterator) called with a non-dereferenceable iterator");
__node_allocator& __na = base::__node_alloc();
__node& __n = const_cast<__node&>(*__p.__ptr_);
__node_pointer __r = __n.__next_;
Modified: libcxx/trunk/test/containers/sequences/list/list.modifiers/emplace.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/list/list.modifiers/emplace.pass.cpp?rev=178819&r1=178818&r2=178819&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/list/list.modifiers/emplace.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/list/list.modifiers/emplace.pass.cpp Thu Apr 4 19:18:49 2013
@@ -11,6 +11,10 @@
// template <class... Args> void emplace(const_iterator p, Args&&... args);
+#if _LIBCPP_DEBUG2 >= 1
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+#endif
+
#include <list>
#include <cassert>
@@ -44,4 +48,12 @@ int main()
assert(c.back().geti() == 3);
assert(c.back().getd() == 4.5);
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#if _LIBCPP_DEBUG2 >= 1
+ {
+ std::list<A> c1;
+ std::list<A> c2;
+ std::list<A>::iterator i = c1.emplace(c2.cbegin(), 2, 3.5);
+ assert(false);
+ }
+#endif
}
Modified: libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp?rev=178819&r1=178818&r2=178819&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp Thu Apr 4 19:18:49 2013
@@ -12,9 +12,14 @@
// template <InputIterator Iter>
// iterator insert(const_iterator position, Iter first, Iter last);
+#if _LIBCPP_DEBUG2 >= 1
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+#endif
+
#include <list>
#include <cstdlib>
#include <cassert>
+#include "test_iterators.h"
int throw_next = 0xFFFF;
int count = 0;
@@ -36,6 +41,7 @@ void operator delete(void* p) throw()
int main()
{
+ {
int a1[] = {1, 2, 3};
std::list<int> l1;
std::list<int>::iterator i = l1.insert(l1.begin(), a1, a1+3);
@@ -90,4 +96,17 @@ int main()
assert(*i == 6);
++i;
assert(*i == 3);
+ }
+#if _LIBCPP_DEBUG2 >= 1
+ {
+ throw_next = 0xFFFF;
+ std::list<int> v(100);
+ std::list<int> v2(100);
+ int a[] = {1, 2, 3, 4, 5};
+ const int N = sizeof(a)/sizeof(a[0]);
+ std::list<int>::iterator i = v.insert(next(v2.cbegin(), 10), input_iterator<const int*>(a),
+ input_iterator<const int*>(a+N));
+ assert(false);
+ }
+#endif
}
Modified: libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_rvalue.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_rvalue.pass.cpp?rev=178819&r1=178818&r2=178819&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_rvalue.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_rvalue.pass.cpp Thu Apr 4 19:18:49 2013
@@ -11,6 +11,10 @@
// iterator insert(const_iterator position, value_type&& x);
+#if _LIBCPP_DEBUG2 >= 1
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+#endif
+
#include <list>
#include <cassert>
@@ -28,4 +32,12 @@ int main()
assert(l1.front() == MoveOnly(2));
assert(l1.back() == MoveOnly(1));
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#if _LIBCPP_DEBUG2 >= 1
+ {
+ std::list<int> v1(3);
+ std::list<int> v2(3);
+ v1.insert(v2.begin(), 4);
+ assert(false);
+ }
+#endif
}
Modified: libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp?rev=178819&r1=178818&r2=178819&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp Thu Apr 4 19:18:49 2013
@@ -11,6 +11,10 @@
// iterator insert(const_iterator position, size_type n, const value_type& x);
+#if _LIBCPP_DEBUG2 >= 1
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+#endif
+
#include <list>
#include <cstdlib>
#include <cassert>
@@ -54,4 +58,12 @@ int main()
throw_next = 0xFFFF;
assert(save_count == count);
assert(l1 == std::list<int>(a2, a2+8));
+#if _LIBCPP_DEBUG2 >= 1
+ {
+ std::list<int> c1(100);
+ std::list<int> c2;
+ std::list<int>::iterator i = c1.insert(next(c2.cbegin(), 10), 5, 1);
+ assert(false);
+ }
+#endif
}
Modified: libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp?rev=178819&r1=178818&r2=178819&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp Thu Apr 4 19:18:49 2013
@@ -11,6 +11,10 @@
// iterator insert(const_iterator position, const value_type& x);
+#if _LIBCPP_DEBUG2 >= 1
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+#endif
+
#include <list>
#include <cstdlib>
#include <cassert>
@@ -56,4 +60,13 @@ int main()
throw_next = 0xFFFF;
assert(save_count == count);
assert(l1 == std::list<int>(a2, a2+4));
+#if _LIBCPP_DEBUG2 >= 1
+ {
+ std::list<int> v1(3);
+ std::list<int> v2(3);
+ int i = 4;
+ v1.insert(v2.begin(), i);
+ assert(false);
+ }
+#endif
}
Modified: libcxx/trunk/test/containers/sequences/list/list.modifiers/pop_back.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/list/list.modifiers/pop_back.pass.cpp?rev=178819&r1=178818&r2=178819&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/list/list.modifiers/pop_back.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/list/list.modifiers/pop_back.pass.cpp Thu Apr 4 19:18:49 2013
@@ -11,6 +11,10 @@
// void pop_back();
+#if _LIBCPP_DEBUG2 >= 1
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+#endif
+
#include <list>
#include <cassert>
@@ -24,4 +28,8 @@ int main()
assert(c == std::list<int>(a, a+1));
c.pop_back();
assert(c.empty());
+#if _LIBCPP_DEBUG2 >= 1
+ c.pop_back();
+ assert(false);
+#endif
}
More information about the cfe-commits
mailing list