[libc++] [test] Test that unordered_*::swap/move/assign does not invalidate iterators.

And remove the dedicated debug-iterator tests; we want to test this in all modes.
We have a CI step for testing the whole test suite with `--debug_level=1` now.

Part of https://reviews.llvm.org/D102003

GitOrigin-RevId: f42355e17c3f3d1d099d028a388796a64724ffdb
diff --git a/test/libcxx/containers/unord/unord.map/db_move.pass.cpp b/test/libcxx/containers/unord/unord.map/db_move.pass.cpp
deleted file mode 100644
index 5f18cb3..0000000
--- a/test/libcxx/containers/unord/unord.map/db_move.pass.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <unordered_map>
-
-// unordered_map(unordered_map&& u);
-
-// UNSUPPORTED: c++03
-// UNSUPPORTED: libcxx-no-debug-mode
-
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
-#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
-
-#include <unordered_map>
-#include <cassert>
-#include <utility>
-
-#include "test_macros.h"
-
-int main(int, char**) {
-    std::unordered_map<int, int> s1 = {{1, 1}, {2, 2}, {3, 3}};
-    std::unordered_map<int, int>::iterator i = s1.begin();
-    std::pair<const int, int> k = *i;
-    std::unordered_map<int, int> s2 = std::move(s1);
-    assert(*i == k);
-    s2.erase(i);
-    assert(s2.size() == 2);
-
-    return 0;
-}
diff --git a/test/libcxx/containers/unord/unord.multimap/db_move.pass.cpp b/test/libcxx/containers/unord/unord.multimap/db_move.pass.cpp
deleted file mode 100644
index 0aff618..0000000
--- a/test/libcxx/containers/unord/unord.multimap/db_move.pass.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++03
-
-// <unordered_map>
-
-// unordered_multimap(unordered_multimap&& u);
-
-// UNSUPPORTED: libcxx-no-debug-mode
-
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
-#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
-
-#include <unordered_map>
-#include <cassert>
-#include <utility>
-
-#include "test_macros.h"
-
-int main(int, char**) {
-    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);
-
-    return 0;
-}
diff --git a/test/libcxx/containers/unord/unord.multiset/db_move.pass.cpp b/test/libcxx/containers/unord/unord.multiset/db_move.pass.cpp
deleted file mode 100644
index 6e89ff2..0000000
--- a/test/libcxx/containers/unord/unord.multiset/db_move.pass.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++03
-
-// <unordered_set>
-
-// unordered_multiset(unordered_multiset&& u);
-
-// UNSUPPORTED: libcxx-no-debug-mode
-
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
-#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
-
-#include <unordered_set>
-#include <cassert>
-#include <utility>
-
-#include "test_macros.h"
-
-int main(int, char**) {
-    std::unordered_multiset<int> s1 = {1, 2, 3};
-    std::unordered_multiset<int>::iterator i = s1.begin();
-    int k = *i;
-    std::unordered_multiset<int> s2 = std::move(s1);
-    assert(*i == k);
-    s2.erase(i);
-    assert(s2.size() == 2);
-
-    return 0;
-}
diff --git a/test/libcxx/containers/unord/unord.set/db_move.pass.cpp b/test/libcxx/containers/unord/unord.set/db_move.pass.cpp
deleted file mode 100644
index ba7c095..0000000
--- a/test/libcxx/containers/unord/unord.set/db_move.pass.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++03
-// UNSUPPORTED: libcxx-no-debug-mode
-
-// <unordered_set>
-
-// unordered_set(unordered_set&& u);
-
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
-#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
-
-#include <unordered_set>
-#include <cassert>
-#include <utility>
-
-#include "test_macros.h"
-
-int main(int, char**) {
-    std::unordered_set<int> s1 = {1, 2, 3};
-    std::unordered_set<int>::iterator i = s1.begin();
-    int k = *i;
-    std::unordered_set<int> s2 = std::move(s1);
-    assert(*i == k);
-    s2.erase(i);
-    assert(s2.size() == 2);
-
-    return 0;
-}
diff --git a/test/std/containers/unord/unord.map/unord.map.cnstr/assign_move.pass.cpp b/test/std/containers/unord/unord.map/unord.map.cnstr/assign_move.pass.cpp
index ceb7a02..2378a5d 100644
--- a/test/std/containers/unord/unord.map/unord.map.cnstr/assign_move.pass.cpp
+++ b/test/std/containers/unord/unord.map/unord.map.cnstr/assign_move.pass.cpp
@@ -105,6 +105,7 @@
             test_compare<std::equal_to<int> >(3),
             A(10)
            );
+        C::iterator it0 = c0.begin();
         c = std::move(c0);
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 4);
@@ -121,6 +122,7 @@
         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
         assert(c.max_load_factor() == 1);
         assert(c0.size() == 0);
+        assert(it0 == c.begin()); // Iterators remain valid
     }
     {
         typedef other_allocator<std::pair<const int, std::string> > A;
@@ -151,6 +153,7 @@
             test_compare<std::equal_to<int> >(3),
             A(4)
            );
+        C::iterator it0 = c0.begin();
         c = std::move(c0);
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 4);
@@ -167,6 +170,7 @@
         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
         assert(c.max_load_factor() == 1);
         assert(c0.size() == 0);
+        assert(it0 == c.begin()); // Iterators remain valid
     }
     {
         typedef min_allocator<std::pair<const int, std::string> > A;
@@ -197,6 +201,7 @@
             test_compare<std::equal_to<int> >(3),
             A()
            );
+        C::iterator it0 = c0.begin();
         c = std::move(c0);
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 4);
@@ -213,6 +218,7 @@
         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
         assert(c.max_load_factor() == 1);
         assert(c0.size() == 0);
+        assert(it0 == c.begin()); // Iterators remain valid
     }
 
   return 0;
diff --git a/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp b/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp
index 6efaa63..363f2f8 100644
--- a/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp
+++ b/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp
@@ -42,6 +42,7 @@
             test_compare<std::equal_to<int> >(9),
             test_allocator<std::pair<const int, std::string> >(10)
            );
+        C::iterator it0 = c0.begin();
         C c = std::move(c0);
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 0);
@@ -54,6 +55,7 @@
         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
         assert(c.load_factor() == 0);
         assert(c.max_load_factor() == 1);
+        assert(it0 == c.begin()); // Iterators remain valid
 
         assert(c0.empty());
     }
@@ -79,6 +81,7 @@
             test_compare<std::equal_to<int> >(9),
             test_allocator<std::pair<const int, std::string> >(10)
            );
+        C::iterator it0 = c0.begin();
         C c = std::move(c0);
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 4);
@@ -95,6 +98,7 @@
         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
         assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
         assert(c.max_load_factor() == 1);
+        assert(it0 == c.begin()); // Iterators remain valid
 
         assert(c0.empty());
     }
@@ -109,6 +113,7 @@
             test_compare<std::equal_to<int> >(9),
             min_allocator<std::pair<const int, std::string> >()
            );
+        C::iterator it0 = c0.begin();
         C c = std::move(c0);
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 0);
@@ -121,6 +126,7 @@
         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
         assert(c.load_factor() == 0);
         assert(c.max_load_factor() == 1);
+        assert(it0 == c.begin()); // Iterators remain valid
 
         assert(c0.empty());
     }
@@ -146,6 +152,7 @@
             test_compare<std::equal_to<int> >(9),
             min_allocator<std::pair<const int, std::string> >()
            );
+        C::iterator it0 = c0.begin();
         C c = std::move(c0);
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 4);
@@ -162,6 +169,7 @@
         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
         assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
         assert(c.max_load_factor() == 1);
+        assert(it0 == c.begin()); // Iterators remain valid
 
         assert(c0.empty());
     }
diff --git a/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp b/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp
index 7852394..d145c74 100644
--- a/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp
+++ b/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp
@@ -75,6 +75,7 @@
         C c1(0, Hash(1), Compare(1), Alloc(1, 1));
         C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
         c2.max_load_factor(2);
+        C::iterator it2 = c2.begin();
         swap(c1, c2);
 
         assert(c1.bucket_count() >= 8);
@@ -93,6 +94,7 @@
         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
         assert(c1.max_load_factor() == 2);
+        assert(it2 == c1.begin()); // Iterators are not invalidated
 
         LIBCPP_ASSERT(c2.bucket_count() == 0);
         assert(c2.size() == 0);
@@ -121,6 +123,7 @@
         C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
         C c2(0, Hash(2), Compare(2), Alloc(1, 2));
         c2.max_load_factor(2);
+        C::iterator it1 = c1.begin();
         swap(c1, c2);
 
         LIBCPP_ASSERT(c1.bucket_count() == 0);
@@ -144,6 +147,7 @@
         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
         assert(c2.max_load_factor() == 1);
+        assert(it1 == c2.begin()); // Iterators are not invalidated
     }
     {
         typedef test_hash<std::hash<int> > Hash;
@@ -174,6 +178,8 @@
         C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
         C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
         c2.max_load_factor(2);
+        C::iterator it1 = c1.begin();
+        C::iterator it2 = c2.begin();
         swap(c1, c2);
 
         assert(c1.bucket_count() >= 8);
@@ -192,6 +198,7 @@
         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
         assert(c1.max_load_factor() == 2);
+        assert(it2 == c1.begin()); // Iterators are not invalidated
 
         assert(c2.bucket_count() >= 4);
         assert(c2.size() == 4);
@@ -205,6 +212,7 @@
         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
         assert(c2.max_load_factor() == 1);
+        assert(it1 == c2.begin()); // Iterators are not invalidated
     }
 
     {
diff --git a/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_move.pass.cpp b/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_move.pass.cpp
index dfc64bd..e163d0a 100644
--- a/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_move.pass.cpp
+++ b/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_move.pass.cpp
@@ -122,7 +122,9 @@
             test_compare<std::equal_to<int> >(3),
             A(10)
            );
+        C::iterator it0 = c0.begin();
         c = std::move(c0);
+        assert(it0 == c.begin()); // Iterators remain valid
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 6);
         typedef std::pair<C::const_iterator, C::const_iterator> Eq;
@@ -182,7 +184,9 @@
             test_compare<std::equal_to<int> >(3),
             A(4)
            );
+        C::iterator it0 = c0.begin();
         c = std::move(c0);
+        assert(it0 == c.begin()); // Iterators remain valid
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 6);
         typedef std::pair<C::const_iterator, C::const_iterator> Eq;
@@ -242,7 +246,9 @@
             test_compare<std::equal_to<int> >(3),
             A()
            );
+        C::iterator it0 = c0.begin();
         c = std::move(c0);
+        assert(it0 == c.begin()); // Iterators remain valid
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 6);
         typedef std::pair<C::const_iterator, C::const_iterator> Eq;
diff --git a/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move.pass.cpp b/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move.pass.cpp
index a0a707c..d61d58a 100644
--- a/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move.pass.cpp
+++ b/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move.pass.cpp
@@ -82,7 +82,9 @@
             test_compare<std::equal_to<int> >(9),
             test_allocator<std::pair<const int, std::string> >(10)
            );
+        C::iterator it0 = c0.begin();
         C c = std::move(c0);
+        assert(it0 == c.begin()); // Iterators remain valid
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 6);
         typedef std::pair<C::const_iterator, C::const_iterator> Eq;
@@ -166,7 +168,9 @@
             test_compare<std::equal_to<int> >(9),
             min_allocator<std::pair<const int, std::string> >()
            );
+        C::iterator it0 = c0.begin();
         C c = std::move(c0);
+        assert(it0 == c.begin()); // Iterators remain valid
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 6);
         typedef std::pair<C::const_iterator, C::const_iterator> Eq;
diff --git a/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_non_member.pass.cpp b/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_non_member.pass.cpp
index 9fcd6cc..1d0532f 100644
--- a/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_non_member.pass.cpp
+++ b/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_non_member.pass.cpp
@@ -77,6 +77,7 @@
         C c1(0, Hash(1), Compare(1), Alloc(1, 1));
         C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
         c2.max_load_factor(2);
+        C::iterator it2 = c2.begin();
         swap(c1, c2);
 
         assert(c1.bucket_count() >= 8);
@@ -95,6 +96,7 @@
         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
         assert(c1.max_load_factor() == 2);
+        assert(it2 == c1.begin()); // Iterators are not invalidated
 
         LIBCPP_ASSERT(c2.bucket_count() == 0);
         assert(c2.size() == 0);
@@ -123,6 +125,7 @@
         C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
         C c2(0, Hash(2), Compare(2), Alloc(1, 2));
         c2.max_load_factor(2);
+        C::iterator it1 = c1.begin();
         swap(c1, c2);
 
         LIBCPP_ASSERT(c1.bucket_count() == 0);
@@ -151,6 +154,7 @@
         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
         assert(c2.max_load_factor() == 1);
+        assert(it1 == c2.begin()); // Iterators are not invalidated
     }
     {
         typedef test_hash<std::hash<int> > Hash;
@@ -181,6 +185,8 @@
         C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
         C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
         c2.max_load_factor(2);
+        C::iterator it1 = c1.begin();
+        C::iterator it2 = c2.begin();
         swap(c1, c2);
 
         assert(c1.bucket_count() >= 8);
@@ -199,6 +205,7 @@
         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
         assert(c1.max_load_factor() == 2);
+        assert(it2 == c1.begin()); // Iterators are not invalidated
 
         assert(c2.bucket_count() >= 6);
         assert(c2.size() == 6);
@@ -217,6 +224,7 @@
         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
         assert(c2.max_load_factor() == 1);
+        assert(it1 == c2.begin()); // Iterators are not invalidated
     }
 
     {
diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_move.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_move.pass.cpp
index 9a9069e..26c9c59 100644
--- a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_move.pass.cpp
+++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_move.pass.cpp
@@ -105,6 +105,7 @@
             test_compare<std::equal_to<int> >(3),
             A(10)
            );
+        C::iterator it0 = c0.begin();
         c = std::move(c0);
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 6);
@@ -120,6 +121,7 @@
         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
         assert(c.max_load_factor() == 1);
+        assert(it0 == c.begin()); // Iterators remain valid
     }
     {
         typedef other_allocator<int> A;
@@ -150,6 +152,7 @@
             test_compare<std::equal_to<int> >(3),
             A(4)
            );
+        C::iterator it0 = c0.begin();
         c = std::move(c0);
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 6);
@@ -165,6 +168,7 @@
         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
         assert(c.max_load_factor() == 1);
+        assert(it0 == c.begin()); // Iterators remain valid
     }
     {
         typedef test_allocator<int> A;
@@ -195,6 +199,7 @@
             test_compare<std::equal_to<int> >(3),
             A()
            );
+        C::iterator it0 = c0.begin();
         c = std::move(c0);
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 6);
@@ -210,6 +215,7 @@
         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
         assert(c.max_load_factor() == 1);
+        assert(it0 == c.begin()); // Iterators remain valid
     }
     {
         typedef min_allocator<int> A;
@@ -240,6 +246,7 @@
             test_compare<std::equal_to<int> >(3),
             A()
            );
+        C::iterator it0 = c0.begin();
         c = std::move(c0);
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 6);
@@ -255,6 +262,7 @@
         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
         assert(c.max_load_factor() == 1);
+        assert(it0 == c.begin()); // Iterators remain valid
     }
 
   return 0;
diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move.pass.cpp
index fbb4f5f..fa02494 100644
--- a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move.pass.cpp
+++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move.pass.cpp
@@ -77,7 +77,9 @@
             test_compare<std::equal_to<int> >(9),
             test_allocator<int>(10)
            );
+        C::iterator it0 = c0.begin();
         C c = std::move(c0);
+        assert(it0 == c.begin()); // Iterators remain valid
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 6);
         assert(c.count(1) == 2);
@@ -142,7 +144,9 @@
             test_compare<std::equal_to<int> >(9),
             min_allocator<int>()
            );
+        C::iterator it0 = c0.begin();
         C c = std::move(c0);
+        assert(it0 == c.begin()); // Iterators remain valid
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 6);
         assert(c.count(1) == 2);
diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_non_member.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_non_member.pass.cpp
index 706c995..5b5a4cd 100644
--- a/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_non_member.pass.cpp
+++ b/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_non_member.pass.cpp
@@ -74,6 +74,7 @@
         C c1(0, Hash(1), Compare(1), Alloc(1, 1));
         C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
         c2.max_load_factor(2);
+        C::iterator it2 = c2.begin();
         swap(c1, c2);
 
         assert(c1.bucket_count() >= 8);
@@ -92,6 +93,7 @@
         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
         assert(c1.max_load_factor() == 2);
+        assert(it2 == c1.begin()); // Iterators are not invalidated
 
         LIBCPP_ASSERT(c2.bucket_count() == 0);
         assert(c2.size() == 0);
@@ -120,6 +122,7 @@
         C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
         C c2(0, Hash(2), Compare(2), Alloc(1, 2));
         c2.max_load_factor(2);
+        C::iterator it1 = c1.begin();
         swap(c1, c2);
 
         LIBCPP_ASSERT(c1.bucket_count() == 0);
@@ -143,6 +146,7 @@
         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
         assert(c2.max_load_factor() == 1);
+        assert(it1 == c2.begin()); // Iterators are not invalidated
     }
     {
         typedef test_hash<std::hash<int> > Hash;
@@ -173,6 +177,8 @@
         C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
         C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
         c2.max_load_factor(2);
+        C::iterator it1 = c1.begin();
+        C::iterator it2 = c2.begin();
         swap(c1, c2);
 
         assert(c1.bucket_count() >= 8);
@@ -191,6 +197,7 @@
         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
         assert(c1.max_load_factor() == 2);
+        assert(it2 == c1.begin()); // Iterators are not invalidated
 
         assert(c2.bucket_count() >= 6);
         assert(c2.size() == 6);
@@ -204,6 +211,7 @@
         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
         assert(c2.max_load_factor() == 1);
+        assert(it1 == c2.begin()); // Iterators are not invalidated
     }
 
     {
diff --git a/test/std/containers/unord/unord.set/unord.set.cnstr/assign_move.pass.cpp b/test/std/containers/unord/unord.set/unord.set.cnstr/assign_move.pass.cpp
index 276d724..1edbe0b 100644
--- a/test/std/containers/unord/unord.set/unord.set.cnstr/assign_move.pass.cpp
+++ b/test/std/containers/unord/unord.set/unord.set.cnstr/assign_move.pass.cpp
@@ -104,6 +104,7 @@
             test_compare<std::equal_to<int> >(3),
             A(10)
            );
+        C::iterator it0 = c0.begin();
         c = std::move(c0);
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 4);
@@ -119,6 +120,7 @@
         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
         assert(c.max_load_factor() == 1);
+        assert(it0 == c.begin()); // Iterators remain valid
     }
     {
         typedef other_allocator<int> A;
@@ -149,6 +151,7 @@
             test_compare<std::equal_to<int> >(3),
             A(4)
            );
+        C::iterator it0 = c0.begin();
         c = std::move(c0);
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 4);
@@ -164,6 +167,7 @@
         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
         assert(c.max_load_factor() == 1);
+        assert(it0 == c.begin()); // Iterators remain valid
     }
     {
         typedef min_allocator<int> A;
@@ -194,6 +198,7 @@
             test_compare<std::equal_to<int> >(3),
             A()
            );
+        C::iterator it0 = c0.begin();
         c = std::move(c0);
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 4);
@@ -209,6 +214,7 @@
         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
         assert(c.max_load_factor() == 1);
+        assert(it0 == c.begin()); // Iterators remain valid
     }
 
   return 0;
diff --git a/test/std/containers/unord/unord.set/unord.set.cnstr/move.pass.cpp b/test/std/containers/unord/unord.set/unord.set.cnstr/move.pass.cpp
index 2fc64ed..dd3822e 100644
--- a/test/std/containers/unord/unord.set/unord.set.cnstr/move.pass.cpp
+++ b/test/std/containers/unord/unord.set/unord.set.cnstr/move.pass.cpp
@@ -77,7 +77,9 @@
             test_compare<std::equal_to<int> >(9),
             test_allocator<int>(10)
            );
+        C::iterator it0 = c0.begin();
         C c = std::move(c0);
+        assert(it0 == c.begin()); // Iterators remain valid
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 4);
         assert(c.count(1) == 1);
@@ -142,7 +144,9 @@
             test_compare<std::equal_to<int> >(9),
             min_allocator<int>()
            );
+        C::iterator it0 = c0.begin();
         C c = std::move(c0);
+        assert(it0 == c.begin()); // Iterators remain valid
         LIBCPP_ASSERT(c.bucket_count() == 7);
         assert(c.size() == 4);
         assert(c.count(1) == 1);
diff --git a/test/std/containers/unord/unord.set/unord.set.swap/swap_non_member.pass.cpp b/test/std/containers/unord/unord.set/unord.set.swap/swap_non_member.pass.cpp
index 8f1d9f0..c128bd5 100644
--- a/test/std/containers/unord/unord.set/unord.set.swap/swap_non_member.pass.cpp
+++ b/test/std/containers/unord/unord.set/unord.set.swap/swap_non_member.pass.cpp
@@ -74,6 +74,7 @@
         C c1(0, Hash(1), Compare(1), Alloc(1, 1));
         C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
         c2.max_load_factor(2);
+        C::iterator it2 = c2.begin();
         swap(c1, c2);
 
         assert(c1.bucket_count() >= 8);
@@ -92,6 +93,7 @@
         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
         assert(c1.max_load_factor() == 2);
+        assert(it2 == c1.begin()); // Iterators are not invalidated
 
         LIBCPP_ASSERT(c2.bucket_count() == 0);
         assert(c2.size() == 0);
@@ -120,6 +122,7 @@
         C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
         C c2(0, Hash(2), Compare(2), Alloc(1, 2));
         c2.max_load_factor(2);
+        C::iterator it1 = c1.begin();
         swap(c1, c2);
 
         LIBCPP_ASSERT(c1.bucket_count() == 0);
@@ -143,6 +146,7 @@
         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
         assert(c2.max_load_factor() == 1);
+        assert(it1 == c2.begin()); // Iterators are not invalidated
     }
     {
         typedef test_hash<std::hash<int> > Hash;
@@ -173,6 +177,8 @@
         C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
         C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
         c2.max_load_factor(2);
+        C::iterator it1 = c1.begin();
+        C::iterator it2 = c2.begin();
         swap(c1, c2);
 
         assert(c1.bucket_count() >= 8);
@@ -191,6 +197,7 @@
         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
         assert(c1.max_load_factor() == 2);
+        assert(it2 == c1.begin()); // Iterators are not invalidated
 
         assert(c2.bucket_count() >= 4);
         assert(c2.size() == 4);
@@ -204,6 +211,7 @@
         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
         assert(c2.max_load_factor() == 1);
+        assert(it1 == c2.begin()); // Iterators are not invalidated
     }
 
     {