jloser created this revision. jloser added reviewers: EricWF, matthew. Herald added subscribers: cfe-commits, christof.
[libc++] Fix Container::insert(value_type const&) tests Several unit tests meaning to test the behavior of lvalue insertion incorrectly pass rvalues. Fixes bug 27394. Repository: rCXX libc++ https://reviews.llvm.org/D44411 Files: libcxx/test/std/containers/associative/multiset/insert_cv.pass.cpp libcxx/test/std/containers/associative/set/insert_cv.pass.cpp libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_const_lvalue.pass.cpp libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_const_lvalue.pass.cpp libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_const_lvalue.pass.cpp libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp libcxx/test/std/containers/unord/unord.multiset/insert_const_lvalue.pass.cpp libcxx/test/std/containers/unord/unord.multiset/insert_hint_const_lvalue.pass.cpp libcxx/test/std/containers/unord/unord.set/insert_const_lvalue.pass.cpp libcxx/test/std/containers/unord/unord.set/insert_hint_const_lvalue.pass.cpp
Index: libcxx/test/std/containers/unord/unord.set/insert_hint_const_lvalue.pass.cpp =================================================================== --- libcxx/test/std/containers/unord/unord.set/insert_hint_const_lvalue.pass.cpp +++ libcxx/test/std/containers/unord/unord.set/insert_hint_const_lvalue.pass.cpp @@ -24,53 +24,42 @@ #include "min_allocator.h" +template<class Container> +void do_insert_hint_const_lvalue_test() +{ + typedef Container C; + typedef typename C::iterator R; + typedef typename C::value_type VT; + C c; + typename C::const_iterator e = c.end(); + const VT v1(3.5); + R r = c.insert(e, v1); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(e, v1); + assert(c.size() == 1); + assert(*r == 3.5); + + const VT v2(4.5); + r = c.insert(e, v2); + assert(c.size() == 2); + assert(*r == 4.5); + + const VT v3(5.5); + r = c.insert(e, v3); + assert(c.size() == 3); + assert(*r == 5.5); +} + int main() { - { - typedef std::unordered_set<double> C; - typedef C::iterator R; - typedef C::value_type P; - C c; - C::const_iterator e = c.end(); - R r = c.insert(e, P(3.5)); - assert(c.size() == 1); - assert(*r == 3.5); - - r = c.insert(e, P(3.5)); - assert(c.size() == 1); - assert(*r == 3.5); - - r = c.insert(e, P(4.5)); - assert(c.size() == 2); - assert(*r == 4.5); - - r = c.insert(e, P(5.5)); - assert(c.size() == 3); - assert(*r == 5.5); - } + do_insert_hint_const_lvalue_test<std::unordered_set<double> >(); #if TEST_STD_VER >= 11 { typedef std::unordered_set<double, std::hash<double>, std::equal_to<double>, min_allocator<double>> C; - typedef C::iterator R; - typedef C::value_type P; - C c; - C::const_iterator e = c.end(); - R r = c.insert(e, P(3.5)); - assert(c.size() == 1); - assert(*r == 3.5); - - r = c.insert(e, P(3.5)); - assert(c.size() == 1); - assert(*r == 3.5); - - r = c.insert(e, P(4.5)); - assert(c.size() == 2); - assert(*r == 4.5); - - r = c.insert(e, P(5.5)); - assert(c.size() == 3); - assert(*r == 5.5); + do_insert_hint_const_lvalue_test<C>(); } #endif #if _LIBCPP_DEBUG >= 1 Index: libcxx/test/std/containers/unord/unord.set/insert_const_lvalue.pass.cpp =================================================================== --- libcxx/test/std/containers/unord/unord.set/insert_const_lvalue.pass.cpp +++ libcxx/test/std/containers/unord/unord.set/insert_const_lvalue.pass.cpp @@ -20,59 +20,45 @@ #include "min_allocator.h" +template<class Container> +void do_insert_const_lvalue_test() +{ + typedef Container C; + typedef std::pair<typename C::iterator, bool> R; + typedef typename C::value_type VT; + C c; + const VT v1(3.5); + R r = c.insert(v1); + assert(c.size() == 1); + assert(*r.first == 3.5); + assert(r.second); + + r = c.insert(v1); + assert(c.size() == 1); + assert(*r.first == 3.5); + assert(!r.second); + + const VT v2(4.5); + r = c.insert(v2); + assert(c.size() == 2); + assert(*r.first == 4.5); + assert(r.second); + + const VT v3(5.5); + r = c.insert(v3); + assert(c.size() == 3); + assert(*r.first == 5.5); + assert(r.second); +} + int main() { - { - typedef std::unordered_set<double> C; - typedef std::pair<C::iterator, bool> R; - typedef C::value_type P; - C c; - R r = c.insert(P(3.5)); - assert(c.size() == 1); - assert(*r.first == 3.5); - assert(r.second); - - r = c.insert(P(3.5)); - assert(c.size() == 1); - assert(*r.first == 3.5); - assert(!r.second); - - r = c.insert(P(4.5)); - assert(c.size() == 2); - assert(*r.first == 4.5); - assert(r.second); - - r = c.insert(P(5.5)); - assert(c.size() == 3); - assert(*r.first == 5.5); - assert(r.second); - } + do_insert_const_lvalue_test<std::unordered_set<double> >(); #if TEST_STD_VER >= 11 { typedef std::unordered_set<double, std::hash<double>, std::equal_to<double>, min_allocator<double>> C; - typedef std::pair<C::iterator, bool> R; - typedef C::value_type P; - C c; - R r = c.insert(P(3.5)); - assert(c.size() == 1); - assert(*r.first == 3.5); - assert(r.second); - - r = c.insert(P(3.5)); - assert(c.size() == 1); - assert(*r.first == 3.5); - assert(!r.second); - - r = c.insert(P(4.5)); - assert(c.size() == 2); - assert(*r.first == 4.5); - assert(r.second); - - r = c.insert(P(5.5)); - assert(c.size() == 3); - assert(*r.first == 5.5); - assert(r.second); + do_insert_const_lvalue_test<C>(); } #endif } Index: libcxx/test/std/containers/unord/unord.multiset/insert_hint_const_lvalue.pass.cpp =================================================================== --- libcxx/test/std/containers/unord/unord.multiset/insert_hint_const_lvalue.pass.cpp +++ libcxx/test/std/containers/unord/unord.multiset/insert_hint_const_lvalue.pass.cpp @@ -24,53 +24,42 @@ #include "min_allocator.h" +template<class Container> +void do_insert_hint_const_lvalue_test() +{ + typedef Container C; + typedef typename C::iterator R; + typedef typename C::value_type VT; + C c; + typename C::const_iterator e = c.end(); + const VT v1(3.5); + R r = c.insert(e, v1); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(c.end(), v1); + assert(c.size() == 2); + assert(*r == 3.5); + + const VT v2(4.5); + r = c.insert(c.end(), v2); + assert(c.size() == 3); + assert(*r == 4.5); + + const VT v3(5.5); + r = c.insert(c.end(), v3); + assert(c.size() == 4); + assert(*r == 5.5); +} + int main() { - { - typedef std::unordered_multiset<double> C; - typedef C::iterator R; - typedef C::value_type P; - C c; - C::const_iterator e = c.end(); - R r = c.insert(e, P(3.5)); - assert(c.size() == 1); - assert(*r == 3.5); - - r = c.insert(c.end(), P(3.5)); - assert(c.size() == 2); - assert(*r == 3.5); - - r = c.insert(c.end(), P(4.5)); - assert(c.size() == 3); - assert(*r == 4.5); - - r = c.insert(c.end(), P(5.5)); - assert(c.size() == 4); - assert(*r == 5.5); - } + do_insert_hint_const_lvalue_test<std::unordered_multiset<double> >(); #if TEST_STD_VER >= 11 { typedef std::unordered_multiset<double, std::hash<double>, - std::equal_to<double>, min_allocator<double>> C; - typedef C::iterator R; - typedef C::value_type P; - C c; - C::const_iterator e = c.end(); - R r = c.insert(e, P(3.5)); - assert(c.size() == 1); - assert(*r == 3.5); - - r = c.insert(c.end(), P(3.5)); - assert(c.size() == 2); - assert(*r == 3.5); - - r = c.insert(c.end(), P(4.5)); - assert(c.size() == 3); - assert(*r == 4.5); - - r = c.insert(c.end(), P(5.5)); - assert(c.size() == 4); - assert(*r == 5.5); + std::equal_to<double>, min_allocator<double>> C; + do_insert_hint_const_lvalue_test<C>(); } #endif #if _LIBCPP_DEBUG >= 1 Index: libcxx/test/std/containers/unord/unord.multiset/insert_const_lvalue.pass.cpp =================================================================== --- libcxx/test/std/containers/unord/unord.multiset/insert_const_lvalue.pass.cpp +++ libcxx/test/std/containers/unord/unord.multiset/insert_const_lvalue.pass.cpp @@ -20,51 +20,41 @@ #include "min_allocator.h" +template<class Container> +void do_insert_const_lvalue_test() +{ + typedef Container C; + typedef typename C::iterator R; + typedef typename C::value_type VT; + C c; + const VT v1(3.5); + R r = c.insert(v1); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(v1); + assert(c.size() == 2); + assert(*r == 3.5); + + const VT v2(4.5); + r = c.insert(v2); + assert(c.size() == 3); + assert(*r == 4.5); + + const VT v3(5.5); + r = c.insert(v3); + assert(c.size() == 4); + assert(*r == 5.5); +} + int main() { - { - typedef std::unordered_multiset<double> C; - typedef C::iterator R; - typedef C::value_type P; - C c; - R r = c.insert(P(3.5)); - assert(c.size() == 1); - assert(*r == 3.5); - - r = c.insert(P(3.5)); - assert(c.size() == 2); - assert(*r == 3.5); - - r = c.insert(P(4.5)); - assert(c.size() == 3); - assert(*r == 4.5); - - r = c.insert(P(5.5)); - assert(c.size() == 4); - assert(*r == 5.5); - } + do_insert_const_lvalue_test<std::unordered_multiset<double> >(); #if TEST_STD_VER >= 11 { typedef std::unordered_multiset<double, std::hash<double>, - std::equal_to<double>, min_allocator<double>> C; - typedef C::iterator R; - typedef C::value_type P; - C c; - R r = c.insert(P(3.5)); - assert(c.size() == 1); - assert(*r == 3.5); - - r = c.insert(P(3.5)); - assert(c.size() == 2); - assert(*r == 3.5); - - r = c.insert(P(4.5)); - assert(c.size() == 3); - assert(*r == 4.5); - - r = c.insert(P(5.5)); - assert(c.size() == 4); - assert(*r == 5.5); + std::equal_to<double>, min_allocator<double>> C; + do_insert_const_lvalue_test<C>(); } #endif } Index: libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp =================================================================== --- libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp +++ libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp @@ -24,61 +24,47 @@ #include "min_allocator.h" +template<class Container> +void do_insert_const_lvalue_test() +{ + typedef Container C; + typedef typename C::iterator R; + typedef typename C::value_type VT; + C c; + typename C::const_iterator e = c.end(); + const VT v1(3.5, 3); + R r = c.insert(e, v1); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + const VT v2(3.5, 4); + r = c.insert(c.end(), v2); + assert(c.size() == 2); + assert(r->first == 3.5); + assert(r->second == 4); + + const VT v3(4.5, 4); + r = c.insert(c.end(), v3); + assert(c.size() == 3); + assert(r->first == 4.5); + assert(r->second == 4); + + const VT v4(5.5, 4); + r = c.insert(c.end(), v4); + assert(c.size() == 4); + assert(r->first == 5.5); + assert(r->second == 4); +} + int main() { - { - typedef std::unordered_multimap<double, int> C; - typedef C::iterator R; - typedef C::value_type P; - C c; - C::const_iterator e = c.end(); - R r = c.insert(e, P(3.5, 3)); - assert(c.size() == 1); - assert(r->first == 3.5); - assert(r->second == 3); - - r = c.insert(c.end(), P(3.5, 4)); - assert(c.size() == 2); - assert(r->first == 3.5); - assert(r->second == 4); - - r = c.insert(c.end(), P(4.5, 4)); - assert(c.size() == 3); - assert(r->first == 4.5); - assert(r->second == 4); - - r = c.insert(c.end(), P(5.5, 4)); - assert(c.size() == 4); - assert(r->first == 5.5); - assert(r->second == 4); - } + do_insert_const_lvalue_test<std::unordered_multimap<double, int> >(); #if TEST_STD_VER >= 11 { typedef std::unordered_multimap<double, int, std::hash<double>, std::equal_to<double>, min_allocator<std::pair<const double, int>>> C; - typedef C::iterator R; - typedef C::value_type P; - C c; - C::const_iterator e = c.end(); - R r = c.insert(e, P(3.5, 3)); - assert(c.size() == 1); - assert(r->first == 3.5); - assert(r->second == 3); - - r = c.insert(c.end(), P(3.5, 4)); - assert(c.size() == 2); - assert(r->first == 3.5); - assert(r->second == 4); - - r = c.insert(c.end(), P(4.5, 4)); - assert(c.size() == 3); - assert(r->first == 4.5); - assert(r->second == 4); - - r = c.insert(c.end(), P(5.5, 4)); - assert(c.size() == 4); - assert(r->first == 5.5); - assert(r->second == 4); + do_insert_const_lvalue_test<C>(); } #endif #if _LIBCPP_DEBUG >= 1 Index: libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_const_lvalue.pass.cpp =================================================================== --- libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_const_lvalue.pass.cpp +++ libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_const_lvalue.pass.cpp @@ -20,59 +20,46 @@ #include "min_allocator.h" +template<class Container> +void do_insert_const_lvalue_test() +{ + typedef Container C; + typedef typename C::iterator R; + typedef typename C::value_type VT; + C c; + const VT v1(3.5, 3); + R r = c.insert(v1); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + const VT v2(3.5, 4); + r = c.insert(v2); + assert(c.size() == 2); + assert(r->first == 3.5); + assert(r->second == 4); + + const VT v3(4.5, 4); + r = c.insert(v3); + assert(c.size() == 3); + assert(r->first == 4.5); + assert(r->second == 4); + + const VT v4(5.5, 4); + r = c.insert(v4); + assert(c.size() == 4); + assert(r->first == 5.5); + assert(r->second == 4); +} + int main() { - { - typedef std::unordered_multimap<double, int> C; - typedef C::iterator R; - typedef C::value_type P; - C c; - R r = c.insert(P(3.5, 3)); - assert(c.size() == 1); - assert(r->first == 3.5); - assert(r->second == 3); - - r = c.insert(P(3.5, 4)); - assert(c.size() == 2); - assert(r->first == 3.5); - assert(r->second == 4); - - r = c.insert(P(4.5, 4)); - assert(c.size() == 3); - assert(r->first == 4.5); - assert(r->second == 4); - - r = c.insert(P(5.5, 4)); - assert(c.size() == 4); - assert(r->first == 5.5); - assert(r->second == 4); - } + do_insert_const_lvalue_test<std::unordered_multimap<double, int> >(); #if TEST_STD_VER >= 11 { typedef std::unordered_multimap<double, int, std::hash<double>, std::equal_to<double>, min_allocator<std::pair<const double, int>>> C; - typedef C::iterator R; - typedef C::value_type P; - C c; - R r = c.insert(P(3.5, 3)); - assert(c.size() == 1); - assert(r->first == 3.5); - assert(r->second == 3); - - r = c.insert(P(3.5, 4)); - assert(c.size() == 2); - assert(r->first == 3.5); - assert(r->second == 4); - - r = c.insert(P(4.5, 4)); - assert(c.size() == 3); - assert(r->first == 4.5); - assert(r->second == 4); - - r = c.insert(P(5.5, 4)); - assert(c.size() == 4); - assert(r->first == 5.5); - assert(r->second == 4); + do_insert_const_lvalue_test<C>(); } #endif } Index: libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_const_lvalue.pass.cpp =================================================================== --- libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_const_lvalue.pass.cpp +++ libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_const_lvalue.pass.cpp @@ -24,61 +24,48 @@ #include "min_allocator.h" +template<class Container> +void do_insert_hint_const_lvalue_test() +{ + typedef Container C; + typedef typename C::iterator R; + typedef typename C::value_type VT; + C c; + typename C::const_iterator e = c.end(); + const VT v1(3.5, 3); + R r = c.insert(e, v1); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + const VT v2(3.5, 4); + r = c.insert(c.end(), v2); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + const VT v3(4.5, 4); + r = c.insert(c.end(), v3); + assert(c.size() == 2); + assert(r->first == 4.5); + assert(r->second == 4); + + const VT v4(5.5, 4); + r = c.insert(c.end(), v4); + assert(c.size() == 3); + assert(r->first == 5.5); + assert(r->second == 4); +} + int main() { - { - typedef std::unordered_map<double, int> C; - typedef C::iterator R; - typedef C::value_type P; - C c; - C::const_iterator e = c.end(); - R r = c.insert(e, P(3.5, 3)); - assert(c.size() == 1); - assert(r->first == 3.5); - assert(r->second == 3); - - r = c.insert(c.end(), P(3.5, 4)); - assert(c.size() == 1); - assert(r->first == 3.5); - assert(r->second == 3); - - r = c.insert(c.end(), P(4.5, 4)); - assert(c.size() == 2); - assert(r->first == 4.5); - assert(r->second == 4); - - r = c.insert(c.end(), P(5.5, 4)); - assert(c.size() == 3); - assert(r->first == 5.5); - assert(r->second == 4); - } + do_insert_hint_const_lvalue_test<std::unordered_map<double, int> >(); #if TEST_STD_VER >= 11 { typedef std::unordered_map<double, int, std::hash<double>, std::equal_to<double>, min_allocator<std::pair<const double, int>>> C; - typedef C::iterator R; - typedef C::value_type P; - C c; - C::const_iterator e = c.end(); - R r = c.insert(e, P(3.5, 3)); - assert(c.size() == 1); - assert(r->first == 3.5); - assert(r->second == 3); - r = c.insert(c.end(), P(3.5, 4)); - assert(c.size() == 1); - assert(r->first == 3.5); - assert(r->second == 3); - - r = c.insert(c.end(), P(4.5, 4)); - assert(c.size() == 2); - assert(r->first == 4.5); - assert(r->second == 4); - - r = c.insert(c.end(), P(5.5, 4)); - assert(c.size() == 3); - assert(r->first == 5.5); - assert(r->second == 4); + do_insert_hint_const_lvalue_test<C>(); } #endif #if _LIBCPP_DEBUG >= 1 Index: libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_const_lvalue.pass.cpp =================================================================== --- libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_const_lvalue.pass.cpp +++ libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_const_lvalue.pass.cpp @@ -37,28 +37,29 @@ assert(r.first->first == 2.5); assert(r.first->second == 2); - r = m.insert(VT(2.5, 3)); // test rvalue insertion works in C++03 - assert(!r.second); - assert(m.size() == 1); - assert(r.first->first == 2.5); - assert(r.first->second == 2); - - const VT v2(1.5, 1); + const VT v2(2.5, 3); r = m.insert(v2); + assert(!r.second); + assert(m.size() == 1); + assert(r.first->first == 2.5); + assert(r.first->second == 2); + + const VT v3(1.5, 1); + r = m.insert(v3); assert(r.second); assert(m.size() == 2); assert(r.first->first == 1.5); assert(r.first->second == 1); - const VT v3(3.5, 3); - r = m.insert(v3); - assert(r.second); - assert(m.size() == 3); - assert(r.first->first == 3.5); - assert(r.first->second == 3); - - const VT v4(3.5, 4); + const VT v4(3.5, 3); r = m.insert(v4); + assert(r.second); + assert(m.size() == 3); + assert(r.first->first == 3.5); + assert(r.first->second == 3); + + const VT v5(3.5, 4); + r = m.insert(v5); assert(!r.second); assert(m.size() == 3); assert(r.first->first == 3.5); Index: libcxx/test/std/containers/associative/set/insert_cv.pass.cpp =================================================================== --- libcxx/test/std/containers/associative/set/insert_cv.pass.cpp +++ libcxx/test/std/containers/associative/set/insert_cv.pass.cpp @@ -18,64 +18,49 @@ #include "min_allocator.h" +template<class Container> +void do_insert_cv_test() +{ + typedef Container M; + typedef std::pair<typename M::iterator, bool> R; + typedef typename M::value_type VT; + M m; + + 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); + + const VT v2(1); + r = m.insert(v2); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(*r.first == 1); + + 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() { - { - 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); - - 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<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 } Index: libcxx/test/std/containers/associative/multiset/insert_cv.pass.cpp =================================================================== --- libcxx/test/std/containers/associative/multiset/insert_cv.pass.cpp +++ libcxx/test/std/containers/associative/multiset/insert_cv.pass.cpp @@ -18,56 +18,44 @@ #include "min_allocator.h" +template<class Container> +void do_insert_cv_test() +{ + 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(3); + 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); +} + int main() { - { - 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); - - r = m.insert(M::value_type(3)); - assert(r == prev(m.end())); - assert(m.size() == 4); - assert(*r == 3); - } + 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 }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits