[libcxx] r178892 - Fix bug in __libcpp_db::__iterator_copy. Add debug test for swaping lists.
Howard Hinnant
hhinnant at apple.com
Fri Apr 5 10:58:52 PDT 2013
Author: hhinnant
Date: Fri Apr 5 12:58:52 2013
New Revision: 178892
URL: http://llvm.org/viewvc/llvm-project?rev=178892&view=rev
Log:
Fix bug in __libcpp_db::__iterator_copy. Add debug test for swaping lists.
Added:
libcxx/trunk/test/containers/sequences/list/list.special/db_swap_1.pass.cpp
Modified:
libcxx/trunk/include/list
libcxx/trunk/src/debug.cpp
Modified: libcxx/trunk/include/list
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/list?rev=178892&r1=178891&r2=178892&view=diff
==============================================================================
--- libcxx/trunk/include/list (original)
+++ libcxx/trunk/include/list Fri Apr 5 12:58:52 2013
@@ -394,7 +394,7 @@ public:
#endif
}
_LIBCPP_INLINE_VISIBILITY
- __list_const_iterator(__list_iterator<_Tp, _VoidPtr> __p) _NOEXCEPT
+ __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
: __ptr_(__p.__ptr_)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
Modified: libcxx/trunk/src/debug.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/debug.cpp?rev=178892&r1=178891&r2=178892&view=diff
==============================================================================
--- libcxx/trunk/src/debug.cpp (original)
+++ libcxx/trunk/src/debug.cpp Fri Apr 5 12:58:52 2013
@@ -110,8 +110,7 @@ __libcpp_db::__find_c_from_i(void* __i)
{
RLock _(mut());
__i_node* i = __find_iterator(__i);
- _LIBCPP_ASSERT(i != nullptr, "iterator constructed in translation unit with debug mode not enabled."
- " #define _LIBCPP_DEBUG2 1 for that translation unit.");
+ _LIBCPP_ASSERT(i != nullptr, "iterator not found in debug database.");
return i->__c_ != nullptr ? i->__c_->__c_ : nullptr;
}
@@ -302,7 +301,7 @@ __libcpp_db::__iterator_copy(void* __i,
__i_node* i = __find_iterator(__i);
__i_node* i0 = __find_iterator(__i0);
__c_node* c0 = i0 != nullptr ? i0->__c_ : nullptr;
- if (i == nullptr && c0 != nullptr)
+ if (i == nullptr && i0 != nullptr)
i = __insert_iterator(__i);
__c_node* c = i != nullptr ? i->__c_ : nullptr;
if (c != c0)
Added: libcxx/trunk/test/containers/sequences/list/list.special/db_swap_1.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/list/list.special/db_swap_1.pass.cpp?rev=178892&view=auto
==============================================================================
--- libcxx/trunk/test/containers/sequences/list/list.special/db_swap_1.pass.cpp (added)
+++ libcxx/trunk/test/containers/sequences/list/list.special/db_swap_1.pass.cpp Fri Apr 5 12:58:52 2013
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <list>
+
+// template <class T, class Alloc>
+// void swap(list<T,Alloc>& x, list<T,Alloc>& y);
+
+#if _LIBCPP_DEBUG2 >= 1
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+#endif
+
+#include <list>
+#include <cassert>
+
+#include <__debug>
+
+int main()
+{
+#if _LIBCPP_DEBUG2 >= 1
+ {
+ int a1[] = {1, 3, 7, 9, 10};
+ int a2[] = {0, 2, 4, 5, 6, 8, 11};
+ std::list<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
+ std::list<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
+ std::list<int>::iterator i1 = c1.begin();
+ std::list<int>::iterator i2 = c2.begin();
+ swap(c1, c2);
+ c1.erase(i2);
+ c2.erase(i1);
+ std::list<int>::iterator j = i1;
+ c1.erase(i1);
+ assert(false);
+ }
+#endif
+}
More information about the cfe-commits
mailing list