summaryrefslogtreecommitdiffstats
path: root/libcxx/test
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2014-08-08 15:35:52 +0000
committerMarshall Clow <mclow.lists@gmail.com>2014-08-08 15:35:52 +0000
commitced70066c24b9f62ad0e4d4c303a6122d7d335f2 (patch)
tree6188e7e691ebde93948c521f7b101fa38b330a70 /libcxx/test
parentac0d28dfe6d678a6facc0ecab79d918280a1a9bc (diff)
downloadbcm5719-llvm-ced70066c24b9f62ad0e4d4c303a6122d7d335f2.tar.gz
bcm5719-llvm-ced70066c24b9f62ad0e4d4c303a6122d7d335f2.zip
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.
llvm-svn: 215210
Diffstat (limited to 'libcxx/test')
-rw-r--r--libcxx/test/containers/sequences/list/list.ops/remove.pass.cpp32
1 files changed, 32 insertions, 0 deletions
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<int>(a2, a2+3));
}
+ { // LWG issue #526
+ int a1[] = {1, 2, 1, 3, 5, 8, 11};
+ int a2[] = { 2, 3, 5, 8, 11};
+ std::list<int> c(a1, a1+7);
+ c.remove(c.front());
+ assert(c == std::list<int>(a2, a2+5));
+ }
+ {
+ int a1[] = {1, 2, 1, 3, 5, 8, 11, 1};
+ int a2[] = { 2, 3, 5, 8, 11 };
+ std::list<S> c;
+ for(int *ip = a1; ip < a1+8; ++ip)
+ c.push_back(S(*ip));
+ c.remove(c.front());
+ std::list<S>::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};
OpenPOWER on IntegriCloud