From ced70066c24b9f62ad0e4d4c303a6122d7d335f2 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Fri, 8 Aug 2014 15:35:52 +0000 Subject: While reading LWG#526, Ion GaztaƱaga noticed that libc++ didn't correctly handle list::remove(const value_type &x), if x was an element of the list. Added a test for this, and a fix. Thanks to Ion for the report. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit llvm-svn: 215210 --- .../sequences/list/list.ops/remove.pass.cpp | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'libcxx/test') diff --git a/libcxx/test/containers/sequences/list/list.ops/remove.pass.cpp b/libcxx/test/containers/sequences/list/list.ops/remove.pass.cpp index 76d878d02c3..106c0527f5f 100644 --- a/libcxx/test/containers/sequences/list/list.ops/remove.pass.cpp +++ b/libcxx/test/containers/sequences/list/list.ops/remove.pass.cpp @@ -16,6 +16,17 @@ #include "min_allocator.h" +struct S { + S(int i) : i_(new int(i)) {} + S(const S &rhs) : i_(new int(*rhs.i_)) {} + S& operator = (const S &rhs) { *i_ = *rhs.i_; return *this; } + ~S () { delete i_; i_ = NULL; } + bool operator == (const S &rhs) const { return *i_ == *rhs.i_; } + int get () const { return *i_; } + int *i_; + }; + + int main() { { @@ -25,6 +36,27 @@ int main() c.remove(3); assert(c == std::list(a2, a2+3)); } + { // LWG issue #526 + int a1[] = {1, 2, 1, 3, 5, 8, 11}; + int a2[] = { 2, 3, 5, 8, 11}; + std::list c(a1, a1+7); + c.remove(c.front()); + assert(c == std::list(a2, a2+5)); + } + { + int a1[] = {1, 2, 1, 3, 5, 8, 11, 1}; + int a2[] = { 2, 3, 5, 8, 11 }; + std::list c; + for(int *ip = a1; ip < a1+8; ++ip) + c.push_back(S(*ip)); + c.remove(c.front()); + std::list::const_iterator it = c.begin(); + for(int *ip = a2; ip < a2+5; ++ip, ++it) { + assert ( it != c.end()); + assert ( *ip == it->get()); + } + assert ( it == c.end ()); + } #if __cplusplus >= 201103L { int a1[] = {1, 2, 3, 4}; -- cgit v1.2.3