diff options
author | Howard Hinnant <hhinnant@apple.com> | 2013-07-30 21:04:42 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2013-07-30 21:04:42 +0000 |
commit | 4c80bfbd53cafa3690ba5c65459cf6cfc560e2e3 (patch) | |
tree | 3ce5e9c83da7ba999b7fa8546196f4060a8f1d4e | |
parent | b7d5409ad292f54def13989d868f2536713d6ece (diff) | |
download | bcm5719-llvm-4c80bfbd53cafa3690ba5c65459cf6cfc560e2e3.tar.gz bcm5719-llvm-4c80bfbd53cafa3690ba5c65459cf6cfc560e2e3.zip |
Debug mode for unordered_multimap. Some mods were done for unordered_map as well to keep all the tests passing. However unordered_map is at the very least still missing tests, if not functionality (if it isn't tested, it probably isn't working).
llvm-svn: 187446
24 files changed, 766 insertions, 22 deletions
diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map index 55db2f5f584..eebf2f5ea61 100644 --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -801,8 +801,18 @@ public: template <class... _Args> _LIBCPP_INLINE_VISIBILITY +#if _LIBCPP_DEBUG_LEVEL >= 2 + iterator emplace_hint(const_iterator __p, _Args&&... __args) + { + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not" + " referring to this unordered_map"); + return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first; + } +#else iterator emplace_hint(const_iterator, _Args&&... __args) {return emplace(_VSTD::forward<_Args>(__args)...).first;} +#endif #endif // _LIBCPP_HAS_NO_VARIADICS #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY @@ -816,14 +826,34 @@ public: {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));} #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY +#if _LIBCPP_DEBUG_LEVEL >= 2 + iterator insert(const_iterator __p, const value_type& __x) + { + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered_map::insert(const_iterator, const value_type&) called with an iterator not" + " referring to this unordered_map"); + return insert(__x).first; + } +#else iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;} +#endif #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _Pp, class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> _LIBCPP_INLINE_VISIBILITY +#if _LIBCPP_DEBUG_LEVEL >= 2 + iterator insert(const_iterator __p, _Pp&& __x) + { + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered_map::insert(const_iterator, value_type&&) called with an iterator not" + " referring to this unordered_map"); + return insert(_VSTD::forward<_Pp>(__x)).first; + } +#else iterator insert(const_iterator, _Pp&& __x) {return insert(_VSTD::forward<_Pp>(__x)).first;} +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _InputIterator> void insert(_InputIterator __first, _InputIterator __last); @@ -1047,6 +1077,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); + __get_db()->swap(this, &__u); #endif } @@ -1066,6 +1097,10 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_) ); } +#if _LIBCPP_DEBUG_LEVEL >= 2 + else + __get_db()->swap(this, &__u); +#endif } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -1754,6 +1789,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); + __get_db()->swap(this, &__u); #endif } @@ -1775,6 +1811,10 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( ); } } +#if _LIBCPP_DEBUG_LEVEL >= 2 + else + __get_db()->swap(this, &__u); +#endif } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES diff --git a/libcxx/test/containers/unord/unord.map/unorder.map.modifiers/emplace_hint.pass.cpp b/libcxx/test/containers/unord/unord.map/unorder.map.modifiers/emplace_hint.pass.cpp index 6d6f3315e1a..455f058ea5f 100644 --- a/libcxx/test/containers/unord/unord.map/unorder.map.modifiers/emplace_hint.pass.cpp +++ b/libcxx/test/containers/unord/unord.map/unorder.map.modifiers/emplace_hint.pass.cpp @@ -36,12 +36,12 @@ int main() assert(r->first == 3); assert(r->second == Emplaceable()); - r = c.emplace_hint(e, std::pair<const int, Emplaceable>(4, Emplaceable(5, 6))); + r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(4, Emplaceable(5, 6))); assert(c.size() == 2); assert(r->first == 4); assert(r->second == Emplaceable(5, 6)); - r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(5), + r = c.emplace_hint(c.end(), std::piecewise_construct, std::forward_as_tuple(5), std::forward_as_tuple(6, 7)); assert(c.size() == 3); assert(r->first == 5); @@ -60,12 +60,12 @@ int main() assert(r->first == 3); assert(r->second == Emplaceable()); - r = c.emplace_hint(e, std::pair<const int, Emplaceable>(4, Emplaceable(5, 6))); + r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(4, Emplaceable(5, 6))); assert(c.size() == 2); assert(r->first == 4); assert(r->second == Emplaceable(5, 6)); - r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(5), + r = c.emplace_hint(c.end(), std::piecewise_construct, std::forward_as_tuple(5), std::forward_as_tuple(6, 7)); assert(c.size() == 3); assert(r->first == 5); diff --git a/libcxx/test/containers/unord/unord.map/unorder.map.modifiers/insert_hint_const_lvalue.pass.cpp b/libcxx/test/containers/unord/unord.map/unorder.map.modifiers/insert_hint_const_lvalue.pass.cpp index 788105e7459..2aa87f12dc4 100644 --- a/libcxx/test/containers/unord/unord.map/unorder.map.modifiers/insert_hint_const_lvalue.pass.cpp +++ b/libcxx/test/containers/unord/unord.map/unorder.map.modifiers/insert_hint_const_lvalue.pass.cpp @@ -33,17 +33,17 @@ int main() assert(r->first == 3.5); assert(r->second == 3); - r = c.insert(e, P(3.5, 4)); + 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(e, P(4.5, 4)); + 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(e, P(5.5, 4)); + r = c.insert(c.end(), P(5.5, 4)); assert(c.size() == 3); assert(r->first == 5.5); assert(r->second == 4); @@ -61,17 +61,17 @@ int main() assert(r->first == 3.5); assert(r->second == 3); - r = c.insert(e, P(3.5, 4)); + 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(e, P(4.5, 4)); + 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(e, P(5.5, 4)); + r = c.insert(c.end(), P(5.5, 4)); assert(c.size() == 3); assert(r->first == 5.5); assert(r->second == 4); diff --git a/libcxx/test/containers/unord/unord.map/unorder.map.modifiers/insert_hint_rvalue.pass.cpp b/libcxx/test/containers/unord/unord.map/unorder.map.modifiers/insert_hint_rvalue.pass.cpp index 3fef2701b63..cc777bbb226 100644 --- a/libcxx/test/containers/unord/unord.map/unorder.map.modifiers/insert_hint_rvalue.pass.cpp +++ b/libcxx/test/containers/unord/unord.map/unorder.map.modifiers/insert_hint_rvalue.pass.cpp @@ -36,17 +36,17 @@ int main() assert(r->first == 3.5); assert(r->second == 3); - r = c.insert(e, P(3.5, 4)); + 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(e, P(4.5, 4)); + 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(e, P(5.5, 4)); + r = c.insert(c.end(), P(5.5, 4)); assert(c.size() == 3); assert(r->first == 5.5); assert(r->second == 4); @@ -63,17 +63,17 @@ int main() assert(r->first == 3); assert(r->second == 3); - r = c.insert(e, P(3, 4)); + r = c.insert(c.end(), P(3, 4)); assert(c.size() == 1); assert(r->first == 3); assert(r->second == 3); - r = c.insert(e, P(4, 4)); + r = c.insert(c.end(), P(4, 4)); assert(c.size() == 2); assert(r->first == 4); assert(r->second == 4); - r = c.insert(e, P(5, 4)); + r = c.insert(c.end(), P(5, 4)); assert(c.size() == 3); assert(r->first == 5); assert(r->second == 4); @@ -92,17 +92,17 @@ int main() assert(r->first == 3.5); assert(r->second == 3); - r = c.insert(e, P(3.5, 4)); + 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(e, P(4.5, 4)); + 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(e, P(5.5, 4)); + r = c.insert(c.end(), P(5.5, 4)); assert(c.size() == 3); assert(r->first == 5.5); assert(r->second == 4); @@ -120,17 +120,17 @@ int main() assert(r->first == 3); assert(r->second == 3); - r = c.insert(e, P(3, 4)); + r = c.insert(c.end(), P(3, 4)); assert(c.size() == 1); assert(r->first == 3); assert(r->second == 3); - r = c.insert(e, P(4, 4)); + r = c.insert(c.end(), P(4, 4)); assert(c.size() == 2); assert(r->first == 4); assert(r->second == 4); - r = c.insert(e, P(5, 4)); + r = c.insert(c.end(), P(5, 4)); assert(c.size() == 3); assert(r->first == 5); assert(r->second == 4); diff --git a/libcxx/test/containers/unord/unord.multimap/bucket.pass.cpp b/libcxx/test/containers/unord/unord.multimap/bucket.pass.cpp index e53b492bbcc..230b6aae976 100644 --- a/libcxx/test/containers/unord/unord.multimap/bucket.pass.cpp +++ b/libcxx/test/containers/unord/unord.multimap/bucket.pass.cpp @@ -15,6 +15,10 @@ // size_type bucket(const key_type& __k) const; +#ifdef _LIBCPP_DEBUG2 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + #include <unordered_map> #include <string> #include <cassert> @@ -62,4 +66,12 @@ int main() assert(c.bucket(i) == i % bc); } #endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_multimap<int, std::string> C; + C c; + C::size_type i = c.bucket(3); + assert(false); + } +#endif } diff --git a/libcxx/test/containers/unord/unord.multimap/bucket_size.pass.cpp b/libcxx/test/containers/unord/unord.multimap/bucket_size.pass.cpp index 79e53d2e92a..27ae7069ca4 100644 --- a/libcxx/test/containers/unord/unord.multimap/bucket_size.pass.cpp +++ b/libcxx/test/containers/unord/unord.multimap/bucket_size.pass.cpp @@ -15,6 +15,10 @@ // size_type bucket_size(size_type n) const +#ifdef _LIBCPP_DEBUG2 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + #include <unordered_map> #include <string> #include <cassert> @@ -70,4 +74,12 @@ int main() assert(c.bucket_size(6) == 0); } #endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_multimap<int, std::string> C; + C c; + C::size_type i = c.bucket_size(3); + assert(false); + } +#endif } diff --git a/libcxx/test/containers/unord/unord.multimap/db_iterators_1.pass.cpp b/libcxx/test/containers/unord/unord.multimap/db_iterators_1.pass.cpp new file mode 100644 index 00000000000..f527f92499c --- /dev/null +++ b/libcxx/test/containers/unord/unord.multimap/db_iterators_1.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_map> + +// Compare iterators from different containers with == or !=. + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_map> +#include <string> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "../../min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap<int, std::string> C; + C c1; + C c2; + bool b = c1.begin() != c2.begin(); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>, + min_allocator<std::pair<const int, std::string>>> C; + C c1; + C c2; + bool b = c1.begin() != c2.begin(); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/unord/unord.multimap/db_iterators_7.pass.cpp b/libcxx/test/containers/unord/unord.multimap/db_iterators_7.pass.cpp new file mode 100644 index 00000000000..92cf1f50a87 --- /dev/null +++ b/libcxx/test/containers/unord/unord.multimap/db_iterators_7.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_map> + +// Increment iterator past end. + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_map> +#include <string> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "../../min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap<int, std::string> C; + C c; + c.insert(std::make_pair(1, "one")); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>, + min_allocator<std::pair<const int, std::string>>> C; + C c; + c.insert(std::make_pair(1, "one")); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/unord/unord.multimap/db_iterators_8.pass.cpp b/libcxx/test/containers/unord/unord.multimap/db_iterators_8.pass.cpp new file mode 100644 index 00000000000..b1fb3389c84 --- /dev/null +++ b/libcxx/test/containers/unord/unord.multimap/db_iterators_8.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_map> + +// Dereference non-dereferenceable iterator. + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_map> +#include <string> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "../../min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap<int, std::string> C; + C c; + c.insert(std::make_pair(1, "one")); + C::iterator i = c.end(); + C::value_type j = *i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>, + min_allocator<std::pair<const int, std::string>>> C; + C c; + c.insert(std::make_pair(1, "one")); + C::iterator i = c.end(); + C::value_type j = *i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/unord/unord.multimap/db_local_iterators_1.pass.cpp b/libcxx/test/containers/unord/unord.multimap/db_local_iterators_1.pass.cpp new file mode 100644 index 00000000000..c3e022d2d2b --- /dev/null +++ b/libcxx/test/containers/unord/unord.multimap/db_local_iterators_1.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_map> + +// Compare local_iterators from different containers with == or !=. + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_map> +#include <string> +#include <cassert> + +int main() +{ + { + typedef std::unordered_multimap<int, std::string> C; + C c1; + c1.insert(std::make_pair(1, "one")); + C c2; + c2.insert(std::make_pair(1, "one")); + C::local_iterator i = c1.begin(c1.bucket(1)); + C::local_iterator j = c2.begin(c2.bucket(1)); + assert(i != j); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/unord/unord.multimap/db_local_iterators_7.pass.cpp b/libcxx/test/containers/unord/unord.multimap/db_local_iterators_7.pass.cpp new file mode 100644 index 00000000000..5237e17ebb5 --- /dev/null +++ b/libcxx/test/containers/unord/unord.multimap/db_local_iterators_7.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_map> + +// Increment local_iterator past end. + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_map> +#include <string> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "../../min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap<int, std::string> C; + C c(1); + C::local_iterator i = c.begin(0); + ++i; + ++i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>, + min_allocator<std::pair<const int, std::string>>> C; + C c(1); + C::local_iterator i = c.begin(0); + ++i; + ++i; + assert(false); + } +#endif + +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/unord/unord.multimap/db_local_iterators_8.pass.cpp b/libcxx/test/containers/unord/unord.multimap/db_local_iterators_8.pass.cpp new file mode 100644 index 00000000000..a6f7db47bae --- /dev/null +++ b/libcxx/test/containers/unord/unord.multimap/db_local_iterators_8.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_map> + +// Dereference non-dereferenceable iterator. + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_map> +#include <string> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "../../min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap<int, std::string> C; + C c(1); + C::local_iterator i = c.end(0); + C::value_type j = *i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>, + min_allocator<std::pair<const int, std::string>>> C; + C c(1); + C::local_iterator i = c.end(0); + C::value_type j = *i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/unord/unord.multimap/max_load_factor.pass.cpp b/libcxx/test/containers/unord/unord.multimap/max_load_factor.pass.cpp index 5fcca6b13fe..8a1daf5bd9b 100644 --- a/libcxx/test/containers/unord/unord.multimap/max_load_factor.pass.cpp +++ b/libcxx/test/containers/unord/unord.multimap/max_load_factor.pass.cpp @@ -16,6 +16,10 @@ // float max_load_factor() const; // void max_load_factor(float mlf); +#ifdef _LIBCPP_DEBUG2 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + #include <unordered_map> #include <string> #include <cassert> @@ -56,4 +60,12 @@ int main() assert(c.max_load_factor() == 2.5); } #endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_multimap<int, std::string> C; + C c; + c.max_load_factor(0); + assert(false); + } +#endif } diff --git a/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/assign_move.pass.cpp b/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/assign_move.pass.cpp index 721743aeef2..99d99e6334e 100644 --- a/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/assign_move.pass.cpp +++ b/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/assign_move.pass.cpp @@ -290,5 +290,17 @@ int main() assert(c.max_load_factor() == 1); } #endif +#if _LIBCPP_DEBUG2 >= 1 + { + std::unordered_multimap<int, int> s1 = {{1, 1}, {2, 2}, {3, 3}}; + std::unordered_multimap<int, int>::iterator i = s1.begin(); + std::pair<const int, int> k = *i; + std::unordered_multimap<int, int> s2; + s2 = std::move(s1); + assert(*i == k); + s2.erase(i); + assert(s2.size() == 2); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/move.pass.cpp b/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/move.pass.cpp index 3d4e5920876..997d31907b2 100644 --- a/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/move.pass.cpp +++ b/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/move.pass.cpp @@ -228,5 +228,16 @@ int main() assert(c0.empty()); } #endif +#if _LIBCPP_DEBUG2 >= 1 + { + std::unordered_multimap<int, int> s1 = {{1, 1}, {2, 2}, {3, 3}}; + std::unordered_multimap<int, int>::iterator i = s1.begin(); + std::pair<const int, int> k = *i; + std::unordered_multimap<int, int> s2 = std::move(s1); + assert(*i == k); + s2.erase(i); + assert(s2.size() == 2); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_db1.pass.cpp b/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_db1.pass.cpp new file mode 100644 index 00000000000..248b93f0c4e --- /dev/null +++ b/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_db1.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_map> + +// Call erase(const_iterator position) with end() + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_map> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, int> P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_multimap<int, int> l1(a1, a1+3); + std::unordered_multimap<int, int>::const_iterator i = l1.end(); + l1.erase(i); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_db2.pass.cpp b/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_db2.pass.cpp new file mode 100644 index 00000000000..e966986692d --- /dev/null +++ b/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_db2.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_map> + +// Call erase(const_iterator position) with iterator from another container + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_map> +#include <cassert> +#include <cstdlib> +#include <exception> + +int main() +{ + { + typedef std::pair<int, int> P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_multimap<int, int> l1(a1, a1+3); + std::unordered_multimap<int, int> l2(a1, a1+3); + std::unordered_multimap<int, int>::const_iterator i = l2.begin(); + l1.erase(i); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db1.pass.cpp b/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db1.pass.cpp new file mode 100644 index 00000000000..87240d2ba5a --- /dev/null +++ b/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db1.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_map> + +// Call erase(const_iterator first, const_iterator last); with first iterator from another container + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_map> +#include <cassert> +#include <exception> +#include <cstdlib> + +int main() +{ + { + typedef std::pair<int, int> P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_multimap<int, int> l1(a1, a1+3); + std::unordered_multimap<int, int> l2(a1, a1+3); + std::unordered_multimap<int, int>::iterator i = l1.erase(l2.cbegin(), next(l1.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db2.pass.cpp b/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db2.pass.cpp new file mode 100644 index 00000000000..fe88b392f78 --- /dev/null +++ b/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db2.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_map> + +// Call erase(const_iterator first, const_iterator last); with second iterator from another container + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_map> +#include <cassert> +#include <exception> +#include <cstdlib> + +int main() +{ + { + typedef std::pair<int, int> P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_multimap<int, int> l1(a1, a1+3); + std::unordered_multimap<int, int> l2(a1, a1+3); + std::unordered_multimap<int, int>::iterator i = l1.erase(l1.cbegin(), next(l2.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db3.pass.cpp b/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db3.pass.cpp new file mode 100644 index 00000000000..7130b8b59e5 --- /dev/null +++ b/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db3.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_map> + +// Call erase(const_iterator first, const_iterator last); with both iterators from another container + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_map> +#include <cassert> +#include <exception> +#include <cstdlib> + +int main() +{ + { + typedef std::pair<int, int> P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_multimap<int, int> l1(a1, a1+3); + std::unordered_multimap<int, int> l2(a1, a1+3); + std::unordered_multimap<int, int>::iterator i = l1.erase(l2.cbegin(), next(l2.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db4.pass.cpp b/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db4.pass.cpp new file mode 100644 index 00000000000..a9433de5516 --- /dev/null +++ b/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db4.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_map> + +// Call erase(const_iterator first, const_iterator last); with a bad range + +#if _LIBCPP_DEBUG2 >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_map> +#include <cassert> +#include <exception> +#include <cstdlib> + +int main() +{ + { + typedef std::pair<int, int> P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_multimap<int, int> l1(a1, a1+3); + std::unordered_multimap<int, int>::iterator i = l1.erase(next(l1.cbegin()), l1.cbegin()); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp b/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp index e5d5b536227..0d77660495a 100644 --- a/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp +++ b/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp @@ -15,6 +15,10 @@ // iterator insert(const_iterator p, const value_type& x); +#if _LIBCPP_DEBUG2 >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + #include <unordered_map> #include <cassert> @@ -77,4 +81,17 @@ int main() assert(r->second == 4); } #endif +#if _LIBCPP_DEBUG2 >= 1 + { + typedef std::unordered_multimap<double, int> C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C c2; + C::const_iterator e = c2.end(); + P v(3.5, 3); + R r = c.insert(e, v); + assert(false); + } +#endif } diff --git a/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_rvalue.pass.cpp b/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_rvalue.pass.cpp index 7be2811e1c2..fc0919d3782 100644 --- a/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_rvalue.pass.cpp +++ b/libcxx/test/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_rvalue.pass.cpp @@ -17,6 +17,10 @@ // class = typename enable_if<is_convertible<P, value_type>::value>::type> // iterator insert(const_iterator p, P&& x); +#if _LIBCPP_DEBUG2 >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + #include <unordered_map> #include <cassert> @@ -136,5 +140,17 @@ int main() assert(r->second == 4); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_DEBUG2 >= 1 + { + typedef std::unordered_multimap<double, int> C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C c2; + C::const_iterator e = c2.end(); + R r = c.insert(e, P(3.5, 3)); + assert(false); + } +#endif #endif } diff --git a/libcxx/test/containers/unord/unord.multimap/unord.multimap.swap/db_swap_1.pass.cpp b/libcxx/test/containers/unord/unord.multimap/unord.multimap.swap/db_swap_1.pass.cpp new file mode 100644 index 00000000000..311f9c10cfd --- /dev/null +++ b/libcxx/test/containers/unord/unord.multimap/unord.multimap.swap/db_swap_1.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_map> + +// template <class Key, class Value, class Hash = hash<Key>, class Pred = equal_to<Key>, +// class Alloc = allocator<pair<const Key, Value>>> +// class unordered_multimap + +// void swap(unordered_multimap& x, unordered_multimap& y); + +#if _LIBCPP_DEBUG2 >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <unordered_map> +#include <cassert> + +int main() +{ +#if _LIBCPP_DEBUG2 >= 1 + { + typedef std::pair<int, int> P; + P a1[] = {P(1, 1), P(3, 3), P(7, 7), P(9, 9), P(10, 10)}; + P a2[] = {P(0, 0), P(2, 2), P(4, 4), P(5, 5), P(6, 6), P(8, 8), P(11, 11)}; + std::unordered_multimap<int, int> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::unordered_multimap<int, int> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + std::unordered_multimap<int, int>::iterator i1 = c1.begin(); + std::unordered_multimap<int, int>::iterator i2 = c2.begin(); + swap(c1, c2); + c1.erase(i2); + c2.erase(i1); + std::unordered_multimap<int, int>::iterator j = i1; + c1.erase(i1); + assert(false); + } +#endif +} |