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

And remove the dedicated debug-iterator test; 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: 8935c8449b7b17049990d29443ed29dde315f281
diff --git a/test/libcxx/containers/sequences/list/list.cons/db_move.pass.cpp b/test/libcxx/containers/sequences/list/list.cons/db_move.pass.cpp
deleted file mode 100644
index 7c08c4c..0000000
--- a/test/libcxx/containers/sequences/list/list.cons/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
-//
-//===----------------------------------------------------------------------===//
-
-// <list>
-
-// list(list&& c);
-
-// 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(1))
-
-#include <list>
-#include <cstdlib>
-#include <cassert>
-#include "test_macros.h"
-#include "MoveOnly.h"
-#include "test_allocator.h"
-#include "min_allocator.h"
-
-int main(int, char**)
-{
-    std::list<int> l1 = {1, 2, 3};
-    std::list<int>::iterator i = l1.begin();
-    std::list<int> l2 = std::move(l1);
-    assert(*l2.erase(i) == 2);
-
-  return 0;
-}
diff --git a/test/std/containers/sequences/list/list.cons/assign_move.pass.cpp b/test/std/containers/sequences/list/list.cons/assign_move.pass.cpp
index 3a89c56..1e459a2 100644
--- a/test/std/containers/sequences/list/list.cons/assign_move.pass.cpp
+++ b/test/std/containers/sequences/list/list.cons/assign_move.pass.cpp
@@ -30,10 +30,12 @@
             lo.push_back(i);
         }
         std::list<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(5));
+        std::list<MoveOnly, test_allocator<MoveOnly> >::iterator it = l.begin();
         l2 = std::move(l);
         assert(l2 == lo);
         assert(l.empty());
         assert(l2.get_allocator() == lo.get_allocator());
+        assert(it == l2.begin());  // Iterators remain valid
     }
     {
         std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
@@ -58,10 +60,12 @@
             lo.push_back(i);
         }
         std::list<MoveOnly, other_allocator<MoveOnly> > l2(other_allocator<MoveOnly>(6));
+        std::list<MoveOnly, other_allocator<MoveOnly> >::iterator it = l.begin();
         l2 = std::move(l);
         assert(l2 == lo);
         assert(l.empty());
         assert(l2.get_allocator() == lo.get_allocator());
+        assert(it == l2.begin());  // Iterators remain valid
     }
     {
         std::list<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
@@ -72,10 +76,12 @@
             lo.push_back(i);
         }
         std::list<MoveOnly, min_allocator<MoveOnly> > l2(min_allocator<MoveOnly>{});
+        std::list<MoveOnly, min_allocator<MoveOnly> >::iterator it = l.begin();
         l2 = std::move(l);
         assert(l2 == lo);
         assert(l.empty());
         assert(l2.get_allocator() == lo.get_allocator());
+        assert(it == l2.begin());  // Iterators remain valid
     }
 
   return 0;
diff --git a/test/std/containers/sequences/list/list.cons/move.pass.cpp b/test/std/containers/sequences/list/list.cons/move.pass.cpp
index 1b4e770..d5e09ca 100644
--- a/test/std/containers/sequences/list/list.cons/move.pass.cpp
+++ b/test/std/containers/sequences/list/list.cons/move.pass.cpp
@@ -29,10 +29,12 @@
             l.push_back(i);
             lo.push_back(i);
         }
+        std::list<MoveOnly, test_allocator<MoveOnly> >::iterator it = l.begin();
         std::list<MoveOnly, test_allocator<MoveOnly> > l2 = std::move(l);
         assert(l2 == lo);
         assert(l.empty());
         assert(l2.get_allocator() == lo.get_allocator());
+        assert(it == l2.begin());  // Iterators remain valid
     }
     {
         std::list<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5));
@@ -42,10 +44,12 @@
             l.push_back(i);
             lo.push_back(i);
         }
+        std::list<MoveOnly, other_allocator<MoveOnly> >::iterator it = l.begin();
         std::list<MoveOnly, other_allocator<MoveOnly> > l2 = std::move(l);
         assert(l2 == lo);
         assert(l.empty());
         assert(l2.get_allocator() == lo.get_allocator());
+        assert(it == l2.begin());  // Iterators remain valid
     }
     {
         std::list<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
@@ -55,10 +59,12 @@
             l.push_back(i);
             lo.push_back(i);
         }
+        std::list<MoveOnly, min_allocator<MoveOnly> >::iterator it = l.begin();
         std::list<MoveOnly, min_allocator<MoveOnly> > l2 = std::move(l);
         assert(l2 == lo);
         assert(l.empty());
         assert(l2.get_allocator() == lo.get_allocator());
+        assert(it == l2.begin());  // Iterators remain valid
     }
 
   return 0;
diff --git a/test/std/containers/sequences/list/list.special/swap.pass.cpp b/test/std/containers/sequences/list/list.special/swap.pass.cpp
index a82070d..bb1efdc 100644
--- a/test/std/containers/sequences/list/list.special/swap.pass.cpp
+++ b/test/std/containers/sequences/list/list.special/swap.pass.cpp
@@ -22,11 +22,15 @@
     {
         int a1[] = {1, 3, 7, 9, 10};
         int a2[] = {0, 2, 4, 5, 6, 8, 11};
-        std::list<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
-        std::list<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
+        std::list<int> c1(a1, a1 + sizeof(a1)/sizeof(a1[0]));
+        std::list<int> c2(a2, a2 + sizeof(a2)/sizeof(a2[0]));
+        std::list<int>::iterator it1 = c1.begin();
+        std::list<int>::const_iterator it2 = c2.begin();
         swap(c1, c2);
         assert(c1 == std::list<int>(a2, a2+sizeof(a2)/sizeof(a2[0])));
         assert(c2 == std::list<int>(a1, a1+sizeof(a1)/sizeof(a1[0])));
+        assert(it1 == c2.begin()); // Iterators remain valid
+        assert(it2 == c1.begin()); // Iterators remain valid
     }
     {
         int a1[] = {1, 3, 7, 9, 10};