From 6dcaf3ee1a1d97ce320d87df842848c5846c2564 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Fri, 5 Apr 2013 17:58:52 +0000 Subject: [PATCH] Fix bug in __libcpp_db::__iterator_copy. Add debug test for swaping lists. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@178892 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/list | 2 +- src/debug.cpp | 5 +-- .../list/list.special/db_swap_1.pass.cpp | 42 +++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 test/containers/sequences/list/list.special/db_swap_1.pass.cpp diff --git a/include/list b/include/list index 6040e7a4..c6000c97 100644 --- a/include/list +++ b/include/list @@ -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 diff --git a/src/debug.cpp b/src/debug.cpp index 2d4b094b..06040af9 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -110,8 +110,7 @@ __libcpp_db::__find_c_from_i(void* __i) const { 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, const void* __i0) __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) diff --git a/test/containers/sequences/list/list.special/db_swap_1.pass.cpp b/test/containers/sequences/list/list.special/db_swap_1.pass.cpp new file mode 100644 index 00000000..12730c28 --- /dev/null +++ b/test/containers/sequences/list/list.special/db_swap_1.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// template +// void swap(list& x, list& y); + +#if _LIBCPP_DEBUG2 >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#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 c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + std::list::iterator i1 = c1.begin(); + std::list::iterator i2 = c2.begin(); + swap(c1, c2); + c1.erase(i2); + c2.erase(i1); + std::list::iterator j = i1; + c1.erase(i1); + assert(false); + } +#endif +}