summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/containers/associative
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2018-04-08 21:57:35 +0000
committerEric Fiselier <eric@efcs.ca>2018-04-08 21:57:35 +0000
commitba0543b32bf0c9a32b0f0d2dfbb7d31de7962570 (patch)
treebd983f361b32fe411f2a9bd9200d30773002f60a /libcxx/test/std/containers/associative
parent0d7df36c668d54e95143f5a330997f32aaa0dd97 (diff)
downloadbcm5719-llvm-ba0543b32bf0c9a32b0f0d2dfbb7d31de7962570.tar.gz
bcm5719-llvm-ba0543b32bf0c9a32b0f0d2dfbb7d31de7962570.zip
[test] Fix Container::insert(value_type const&) tests
Patch from Joe Loser. Several unit tests meaning to test the behavior of lvalue insertion incorrectly pass rvalues. Fixes bug PR # 27394 Reviewed as https://reviews.llvm.org/D44411 llvm-svn: 329541
Diffstat (limited to 'libcxx/test/std/containers/associative')
-rw-r--r--libcxx/test/std/containers/associative/multiset/insert_cv.pass.cpp78
-rw-r--r--libcxx/test/std/containers/associative/set/insert_cv.pass.cpp87
2 files changed, 69 insertions, 96 deletions
diff --git a/libcxx/test/std/containers/associative/multiset/insert_cv.pass.cpp b/libcxx/test/std/containers/associative/multiset/insert_cv.pass.cpp
index 2aa920d7097..fe756428223 100644
--- a/libcxx/test/std/containers/associative/multiset/insert_cv.pass.cpp
+++ b/libcxx/test/std/containers/associative/multiset/insert_cv.pass.cpp
@@ -18,56 +18,44 @@
#include "min_allocator.h"
-int main()
+template<class Container>
+void do_insert_cv_test()
{
- {
- typedef std::multiset<int> M;
- typedef M::iterator R;
- M m;
- R r = m.insert(M::value_type(2));
- assert(r == m.begin());
- assert(m.size() == 1);
- assert(*r == 2);
-
- r = m.insert(M::value_type(1));
- assert(r == m.begin());
- assert(m.size() == 2);
- assert(*r == 1);
-
- r = m.insert(M::value_type(3));
- assert(r == prev(m.end()));
- assert(m.size() == 3);
- assert(*r == 3);
+ typedef Container M;
+ typedef typename M::iterator R;
+ typedef typename M::value_type VT;
+ M m;
+ const VT v1(2);
+ R r = m.insert(v1);
+ assert(r == m.begin());
+ assert(m.size() == 1);
+ assert(*r == 2);
+
+ const VT v2(1);
+ r = m.insert(v2);
+ assert(r == m.begin());
+ assert(m.size() == 2);
+ assert(*r == 1);
+
+ const VT v3(3);
+ r = m.insert(v3);
+ assert(r == prev(m.end()));
+ assert(m.size() == 3);
+ assert(*r == 3);
+
+ r = m.insert(v3);
+ assert(r == prev(m.end()));
+ assert(m.size() == 4);
+ assert(*r == 3);
+}
- r = m.insert(M::value_type(3));
- assert(r == prev(m.end()));
- assert(m.size() == 4);
- assert(*r == 3);
- }
+int main()
+{
+ do_insert_cv_test<std::multiset<int> >();
#if TEST_STD_VER >= 11
{
typedef std::multiset<int, std::less<int>, min_allocator<int>> M;
- typedef M::iterator R;
- M m;
- R r = m.insert(M::value_type(2));
- assert(r == m.begin());
- assert(m.size() == 1);
- assert(*r == 2);
-
- r = m.insert(M::value_type(1));
- assert(r == m.begin());
- assert(m.size() == 2);
- assert(*r == 1);
-
- r = m.insert(M::value_type(3));
- assert(r == prev(m.end()));
- assert(m.size() == 3);
- assert(*r == 3);
-
- r = m.insert(M::value_type(3));
- assert(r == prev(m.end()));
- assert(m.size() == 4);
- assert(*r == 3);
+ do_insert_cv_test<M>();
}
#endif
}
diff --git a/libcxx/test/std/containers/associative/set/insert_cv.pass.cpp b/libcxx/test/std/containers/associative/set/insert_cv.pass.cpp
index 8d5290a97af..17d3c26237c 100644
--- a/libcxx/test/std/containers/associative/set/insert_cv.pass.cpp
+++ b/libcxx/test/std/containers/associative/set/insert_cv.pass.cpp
@@ -18,64 +18,49 @@
#include "min_allocator.h"
-int main()
+template<class Container>
+void do_insert_cv_test()
{
- {
- typedef std::set<int> M;
- typedef std::pair<M::iterator, bool> R;
- M m;
- R r = m.insert(M::value_type(2));
- assert(r.second);
- assert(r.first == m.begin());
- assert(m.size() == 1);
- assert(*r.first == 2);
+ typedef Container M;
+ typedef std::pair<typename M::iterator, bool> R;
+ typedef typename M::value_type VT;
+ M m;
- r = m.insert(M::value_type(1));
- assert(r.second);
- assert(r.first == m.begin());
- assert(m.size() == 2);
- assert(*r.first == 1);
+ const VT v1(2);
+ R r = m.insert(v1);
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 1);
+ assert(*r.first == 2);
- r = m.insert(M::value_type(3));
- assert(r.second);
- assert(r.first == prev(m.end()));
- assert(m.size() == 3);
- assert(*r.first == 3);
+ const VT v2(1);
+ r = m.insert(v2);
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 2);
+ assert(*r.first == 1);
- r = m.insert(M::value_type(3));
- assert(!r.second);
- assert(r.first == prev(m.end()));
- assert(m.size() == 3);
- assert(*r.first == 3);
- }
+ const VT v3(3);
+ r = m.insert(v3);
+ assert(r.second);
+ assert(r.first == prev(m.end()));
+ assert(m.size() == 3);
+ assert(*r.first == 3);
+
+ r = m.insert(v3);
+ assert(!r.second);
+ assert(r.first == prev(m.end()));
+ assert(m.size() == 3);
+ assert(*r.first == 3);
+}
+
+int main()
+{
+ do_insert_cv_test<std::set<int> >();
#if TEST_STD_VER >= 11
{
typedef std::set<int, std::less<int>, min_allocator<int>> M;
- typedef std::pair<M::iterator, bool> R;
- M m;
- R r = m.insert(M::value_type(2));
- assert(r.second);
- assert(r.first == m.begin());
- assert(m.size() == 1);
- assert(*r.first == 2);
-
- r = m.insert(M::value_type(1));
- assert(r.second);
- assert(r.first == m.begin());
- assert(m.size() == 2);
- assert(*r.first == 1);
-
- r = m.insert(M::value_type(3));
- assert(r.second);
- assert(r.first == prev(m.end()));
- assert(m.size() == 3);
- assert(*r.first == 3);
-
- r = m.insert(M::value_type(3));
- assert(!r.second);
- assert(r.first == prev(m.end()));
- assert(m.size() == 3);
- assert(*r.first == 3);
+ do_insert_cv_test<M>();
}
#endif
}
OpenPOWER on IntegriCloud