summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2015-07-29 16:25:45 +0000
committerMarshall Clow <mclow.lists@gmail.com>2015-07-29 16:25:45 +0000
commita37957634cd9c4e22d8dfa5a8a39565905b46f79 (patch)
tree75a88969cfd043c615395eac7c5ee6652842bbe1 /test
parent91eeba8d26c90fb8a7e9d3e4a868b325fad4eb50 (diff)
downloadexternal_libcxx-a37957634cd9c4e22d8dfa5a8a39565905b46f79.tar.gz
external_libcxx-a37957634cd9c4e22d8dfa5a8a39565905b46f79.tar.bz2
external_libcxx-a37957634cd9c4e22d8dfa5a8a39565905b46f79.zip
Fix a self-move bug in inplace_merge. Thanks to Ted and Dexon for the report and the suggested fix.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@243530 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp31
-rw-r--r--test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp48
2 files changed, 69 insertions, 10 deletions
diff --git a/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp b/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp
index 01db088aa..9065b991d 100644
--- a/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp
+++ b/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp
@@ -20,12 +20,35 @@
#include "test_iterators.h"
+#ifndef TEST_STD_VER >= 11
+struct S {
+ S() : i_(0) {}
+ S(int i) : i_(i) {}
+
+ S(const S& rhs) : i_(rhs.i_) {}
+ S( S&& rhs) : i_(rhs.i_) { rhs.i_ = -1; }
+
+ S& operator =(const S& rhs) { i_ = rhs.i_; return *this; }
+ S& operator =( S&& rhs) { i_ = rhs.i_; rhs.i_ = -2; assert(this != &rhs); return *this; }
+ S& operator =(int i) { i_ = i; return *this; }
+
+ bool operator <(const S& rhs) const { return i_ < rhs.i_; }
+ bool operator ==(const S& rhs) const { return i_ == rhs.i_; }
+ bool operator ==(int i) const { return i_ == i; }
+
+ void set(int i) { i_ = i; }
+
+ int i_;
+ };
+#endif
+
template <class Iter>
void
test_one(unsigned N, unsigned M)
{
+ typedef typename std::iterator_traits<Iter>::value_type value_type;
assert(M <= N);
- int* ia = new int[N];
+ value_type* ia = new value_type[N];
for (unsigned i = 0; i < N; ++i)
ia[i] = i;
std::random_shuffle(ia, ia+N);
@@ -76,4 +99,10 @@ int main()
test<bidirectional_iterator<int*> >();
test<random_access_iterator<int*> >();
test<int*>();
+
+#ifndef TEST_STD_VER >= 11
+ test<bidirectional_iterator<S*> >();
+ test<random_access_iterator<S*> >();
+ test<S*>();
+#endif // TEST_STD_VER >= 11
}
diff --git a/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp b/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp
index b54efb688..a9b14fca2 100644
--- a/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp
+++ b/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp
@@ -18,7 +18,10 @@
#include <algorithm>
#include <functional>
#include <cassert>
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#include "test_macros.h"
+
+#ifndef TEST_STD_VER >= 11
#include <memory>
struct indirect_less
@@ -28,7 +31,29 @@ struct indirect_less
{return *x < *y;}
};
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+struct S {
+ S() : i_(0) {}
+ S(int i) : i_(i) {}
+
+ S(const S& rhs) : i_(rhs.i_) {}
+ S( S&& rhs) : i_(rhs.i_) { rhs.i_ = -1; }
+
+ S& operator =(const S& rhs) { i_ = rhs.i_; return *this; }
+ S& operator =( S&& rhs) { i_ = rhs.i_; rhs.i_ = -2; assert(this != &rhs); return *this; }
+ S& operator =(int i) { i_ = i; return *this; }
+
+ bool operator <(const S& rhs) const { return i_ < rhs.i_; }
+ bool operator >(const S& rhs) const { return i_ > rhs.i_; }
+ bool operator ==(const S& rhs) const { return i_ == rhs.i_; }
+ bool operator ==(int i) const { return i_ == i; }
+
+ void set(int i) { i_ = i; }
+
+ int i_;
+ };
+
+
+#endif // TEST_STD_VER >= 11
#include "test_iterators.h"
#include "counting_predicates.hpp"
@@ -38,19 +63,20 @@ void
test_one(unsigned N, unsigned M)
{
assert(M <= N);
- int* ia = new int[N];
+ typedef typename std::iterator_traits<Iter>::value_type value_type;
+ value_type* ia = new value_type[N];
for (unsigned i = 0; i < N; ++i)
ia[i] = i;
std::random_shuffle(ia, ia+N);
- std::sort(ia, ia+M, std::greater<int>());
- std::sort(ia+M, ia+N, std::greater<int>());
- binary_counting_predicate<std::greater<int>, int, int> pred((std::greater<int>()));
+ std::sort(ia, ia+M, std::greater<value_type>());
+ std::sort(ia+M, ia+N, std::greater<value_type>());
+ binary_counting_predicate<std::greater<value_type>, value_type, value_type> pred((std::greater<value_type>()));
std::inplace_merge(Iter(ia), Iter(ia+M), Iter(ia+N), std::ref(pred));
if(N > 0)
{
assert(ia[0] == N-1);
assert(ia[N-1] == 0);
- assert(std::is_sorted(ia, ia+N, std::greater<int>()));
+ assert(std::is_sorted(ia, ia+N, std::greater<value_type>()));
assert(pred.count() <= (N-1));
}
delete [] ia;
@@ -93,7 +119,11 @@ int main()
test<random_access_iterator<int*> >();
test<int*>();
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifndef TEST_STD_VER >= 11
+ test<bidirectional_iterator<S*> >();
+ test<random_access_iterator<S*> >();
+ test<S*>();
+
{
unsigned N = 100;
unsigned M = 50;
@@ -112,5 +142,5 @@ int main()
}
delete [] ia;
}
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#endif // TEST_STD_VER >= 11
}