[libcxx-commits] [libcxx] 786366b - [libc++][NFC] Remove some of the code duplication in the string tests

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Fri Aug 26 12:57:54 PDT 2022


Author: Nikolas Klauser
Date: 2022-08-26T21:57:42+02:00
New Revision: 786366b18fadc3d7c4f150e89ef49c165767a668

URL: https://github.com/llvm/llvm-project/commit/786366b18fadc3d7c4f150e89ef49c165767a668
DIFF: https://github.com/llvm/llvm-project/commit/786366b18fadc3d7c4f150e89ef49c165767a668.diff

LOG: [libc++][NFC] Remove some of the code duplication in the string tests

Reviewed By: ldionne, #libc, huixie90

Spies: huixie90, libcxx-commits, arphaman

Differential Revision: https://reviews.llvm.org/D131856

Added: 
    

Modified: 
    libcxx/test/std/strings/basic.string/string.access/at.pass.cpp
    libcxx/test/std/strings/basic.string/string.access/back.pass.cpp
    libcxx/test/std/strings/basic.string/string.access/front.pass.cpp
    libcxx/test/std/strings/basic.string/string.access/index.pass.cpp
    libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp
    libcxx/test/std/strings/basic.string/string.capacity/empty.pass.cpp
    libcxx/test/std/strings/basic.string/string.capacity/length.pass.cpp
    libcxx/test/std/strings/basic.string/string.capacity/max_size.pass.cpp
    libcxx/test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp
    libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp
    libcxx/test/std/strings/basic.string/string.capacity/reserve_size.pass.cpp
    libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
    libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
    libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp
    libcxx/test/std/strings/basic.string/string.capacity/size.pass.cpp
    libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp
    libcxx/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp
    libcxx/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp
    libcxx/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp
    libcxx/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp
    libcxx/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_view.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_assign/rv_string.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_view.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter_iter.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_size_char.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_insert/string_view.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
    libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.pass.cpp
    libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/pointer_string.pass.cpp
    libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_pointer.pass.cpp
    libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_string.pass.cpp
    libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_string_view.pass.cpp
    libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_view_string.pass.cpp
    libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
    libcxx/test/std/strings/basic.string/string.ops/string_compare/string.pass.cpp
    libcxx/test/std/strings/basic.string/string.ops/string_find.first.not.of/string_size.pass.cpp
    libcxx/test/std/strings/basic.string/string.ops/string_find.first.of/string_size.pass.cpp
    libcxx/test/std/strings/basic.string/string.ops/string_find.last.not.of/string_size.pass.cpp
    libcxx/test/std/strings/basic.string/string.ops/string_find.last.of/string_size.pass.cpp
    libcxx/test/std/strings/basic.string/string.ops/string_find/string_size.pass.cpp
    libcxx/test/std/strings/basic.string/string.ops/string_rfind/string_size.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/strings/basic.string/string.access/at.pass.cpp b/libcxx/test/std/strings/basic.string/string.access/at.pass.cpp
index 58556d176207d..3b991c54e6c91 100644
--- a/libcxx/test/std/strings/basic.string/string.access/at.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.access/at.pass.cpp
@@ -54,27 +54,22 @@ test(S s, typename S::size_type pos)
 #endif
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), 0);
+  test(S("123"), 0);
+  test(S("123"), 1);
+  test(S("123"), 2);
+  test(S("123"), 3);
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), 0);
-    test(S("123"), 0);
-    test(S("123"), 1);
-    test(S("123"), 2);
-    test(S("123"), 3);
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), 0);
-    test(S("123"), 0);
-    test(S("123"), 1);
-    test(S("123"), 2);
-    test(S("123"), 3);
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
-    return true;
+  return true;
 }
 
 int main(int, char**)

diff  --git a/libcxx/test/std/strings/basic.string/string.access/back.pass.cpp b/libcxx/test/std/strings/basic.string/string.access/back.pass.cpp
index 3dd4bf91d108e..9428b08b16d4c 100644
--- a/libcxx/test/std/strings/basic.string/string.access/back.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.access/back.pass.cpp
@@ -32,18 +32,16 @@ test(S s)
     assert(s.back() == typename S::value_type('z'));
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S("1"));
+  test(S("1234567890123456789012345678901234567890"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S("1"));
-    test(S("1234567890123456789012345678901234567890"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S("1"));
-    test(S("1234567890123456789012345678901234567890"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.access/front.pass.cpp b/libcxx/test/std/strings/basic.string/string.access/front.pass.cpp
index 888d9f3b76441..e389d335b1983 100644
--- a/libcxx/test/std/strings/basic.string/string.access/front.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.access/front.pass.cpp
@@ -32,18 +32,16 @@ test(S s)
     assert(s.front() == typename S::value_type('z'));
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S("1"));
+  test(S("1234567890123456789012345678901234567890"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S("1"));
-    test(S("1234567890123456789012345678901234567890"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S("1"));
-    test(S("1234567890123456789012345678901234567890"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.access/index.pass.cpp b/libcxx/test/std/strings/basic.string/string.access/index.pass.cpp
index 0a4d91da78d1c..3fe9324607273 100644
--- a/libcxx/test/std/strings/basic.string/string.access/index.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.access/index.pass.cpp
@@ -17,42 +17,28 @@
 #include "test_macros.h"
 #include "min_allocator.h"
 
-TEST_CONSTEXPR_CXX20 bool test() {
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  S s("0123456789");
+  const S& cs = s;
+  ASSERT_SAME_TYPE(decltype( s[0]), typename S::reference);
+  ASSERT_SAME_TYPE(decltype(cs[0]), typename S::const_reference);
+  LIBCPP_ASSERT_NOEXCEPT(    s[0]);
+  LIBCPP_ASSERT_NOEXCEPT(   cs[0]);
+  for (typename S::size_type i = 0; i < cs.size(); ++i)
   {
-    typedef std::string S;
-    S s("0123456789");
-    const S& cs = s;
-    ASSERT_SAME_TYPE(decltype( s[0]), typename S::reference);
-    ASSERT_SAME_TYPE(decltype(cs[0]), typename S::const_reference);
-    LIBCPP_ASSERT_NOEXCEPT(    s[0]);
-    LIBCPP_ASSERT_NOEXCEPT(   cs[0]);
-    for (S::size_type i = 0; i < cs.size(); ++i)
-    {
-        assert(s[i] == static_cast<char>('0' + i));
-        assert(cs[i] == s[i]);
-    }
-    assert(cs[cs.size()] == '\0');
-    const S s2 = S();
-    assert(s2[0] == '\0');
+      assert(s[i] == static_cast<char>('0' + i));
+      assert(cs[i] == s[i]);
   }
+  assert(cs[cs.size()] == '\0');
+  const S s2 = S();
+  assert(s2[0] == '\0');
+}
+
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    S s("0123456789");
-    const S& cs = s;
-    ASSERT_SAME_TYPE(decltype( s[0]), typename S::reference);
-    ASSERT_SAME_TYPE(decltype(cs[0]), typename S::const_reference);
-    LIBCPP_ASSERT_NOEXCEPT(    s[0]);
-    LIBCPP_ASSERT_NOEXCEPT(   cs[0]);
-    for (S::size_type i = 0; i < cs.size(); ++i)
-    {
-        assert(s[i] == static_cast<char>('0' + i));
-        assert(cs[i] == s[i]);
-    }
-    assert(cs[cs.size()] == '\0');
-    const S s2 = S();
-    assert(s2[0] == '\0');
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp
index 892eb8f739144..24191a3e7e69a 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp
@@ -24,34 +24,24 @@ test(S s)
     assert(s.size() == 0);
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    S s;
-    test(s);
-
-    s.assign(10, 'a');
-    s.erase(5);
-    test(s);
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  S s;
+  test(s);
 
-    s.assign(100, 'a');
-    s.erase(50);
-    test(s);
-  }
-#if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    S s;
-    test(s);
+  s.assign(10, 'a');
+  s.erase(5);
+  test(s);
 
-    s.assign(10, 'a');
-    s.erase(5);
-    test(s);
+  s.assign(100, 'a');
+  s.erase(50);
+  test(s);
+}
 
-    s.assign(100, 'a');
-    s.erase(50);
-    test(s);
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
+#if TEST_STD_VER >= 11
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.capacity/empty.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/empty.pass.cpp
index 668b1a23eb3f5..578f068e09609 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/empty.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/empty.pass.cpp
@@ -24,20 +24,17 @@ test(const S& s)
     assert(s.empty() == (s.size() == 0));
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S());
+  test(S("123"));
+  test(S("12345678901234567890123456789012345678901234567890"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S());
-    test(S("123"));
-    test(S("12345678901234567890123456789012345678901234567890"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S());
-    test(S("123"));
-    test(S("12345678901234567890123456789012345678901234567890"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.capacity/length.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/length.pass.cpp
index a1f7ad2041062..9ef48845c4201 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/length.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/length.pass.cpp
@@ -23,20 +23,17 @@ test(const S& s)
     assert(s.length() == s.size());
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S());
+  test(S("123"));
+  test(S("12345678901234567890123456789012345678901234567890"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S());
-    test(S("123"));
-    test(S("12345678901234567890123456789012345678901234567890"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S());
-    test(S("123"));
-    test(S("12345678901234567890123456789012345678901234567890"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.capacity/max_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/max_size.pass.cpp
index a2971ad72ef92..230c844e93b6b 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/max_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/max_size.pass.cpp
@@ -55,21 +55,20 @@ test(const S& s)
     test2(s);
 }
 
-void test() {
-  {
-    typedef std::string S;
-    test(S());
-    test(S("123"));
-    test(S("12345678901234567890123456789012345678901234567890"));
-  }
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S());
+  test(S("123"));
+  test(S("12345678901234567890123456789012345678901234567890"));
+}
+
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S());
-    test(S("123"));
-    test(S("12345678901234567890123456789012345678901234567890"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
+
+  return true;
 }
 
 #if TEST_STD_VER > 17

diff  --git a/libcxx/test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp
index fed6daa6fa7da..65907e03b0e2f 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp
@@ -37,20 +37,17 @@ test(const S& s)
     assert ( false );
 }
 
+template <class S>
+void test_string() {
+  test(S());
+  test(S("123"));
+  test(S("12345678901234567890123456789012345678901234567890"));
+}
+
 bool test() {
-  {
-    typedef std::string S;
-    test(S());
-    test(S("123"));
-    test(S("12345678901234567890123456789012345678901234567890"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S());
-    test(S("123"));
-    test(S("12345678901234567890123456789012345678901234567890"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp
index a5ef265788697..840fd14c54537 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp
@@ -37,24 +37,17 @@ test(typename S::size_type min_cap, typename S::size_type erased_index)
     assert(s.capacity() >= s.size());
 }
 
+template <class S>
+void test_string() {
+  test<S>(0, 0);
+  test<S>(10, 5);
+  test<S>(100, 50);
+}
+
 bool test() {
-    {
-    typedef std::string S;
-    {
-    test<S>(0, 0);
-    test<S>(10, 5);
-    test<S>(100, 50);
-    }
-    }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-    {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    {
-    test<S>(0, 0);
-    test<S>(10, 5);
-    test<S>(100, 50);
-    }
-    }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.capacity/reserve_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/reserve_size.pass.cpp
index 7df6bb2847a67..299911495b62b 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/reserve_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/reserve_size.pass.cpp
@@ -62,40 +62,27 @@ test(typename S::size_type min_cap, typename S::size_type erased_index, typename
 #endif
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
   {
-    typedef std::string S;
-    {
-      test<S>(0, 0, 5);
-      test<S>(0, 0, 10);
-      test<S>(0, 0, 50);
-    }
-    {
-      test<S>(100, 50, 5);
-      test<S>(100, 50, 10);
-      test<S>(100, 50, 50);
-      test<S>(100, 50, 100);
-      test<S>(100, 50, 1000);
-      test<S>(100, 50, S::npos);
-    }
+    test<S>(0, 0, 5);
+    test<S>(0, 0, 10);
+    test<S>(0, 0, 50);
   }
-#if TEST_STD_VER >= 11
   {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    {
-      test<S>(0, 0, 5);
-      test<S>(0, 0, 10);
-      test<S>(0, 0, 50);
-    }
-    {
-      test<S>(100, 50, 5);
-      test<S>(100, 50, 10);
-      test<S>(100, 50, 50);
-      test<S>(100, 50, 100);
-      test<S>(100, 50, 1000);
-      test<S>(100, 50, S::npos);
-    }
+    test<S>(100, 50, 5);
+    test<S>(100, 50, 10);
+    test<S>(100, 50, 50);
+    test<S>(100, 50, 100);
+    test<S>(100, 50, 1000);
+    test<S>(100, 50, S::npos);
   }
+}
+
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
+#if TEST_STD_VER >= 11
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
index 7e898f12034f5..16e1323e7a75f 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
@@ -43,46 +43,30 @@ test(S s, typename S::size_type n, S expected)
 #endif
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), 0, S());
+  test(S(), 1, S(1, '\0'));
+  test(S(), 10, S(10, '\0'));
+  test(S(), 100, S(100, '\0'));
+  test(S("12345"), 0, S());
+  test(S("12345"), 2, S("12"));
+  test(S("12345"), 5, S("12345"));
+  test(S("12345"), 15, S("12345\0\0\0\0\0\0\0\0\0\0", 15));
+  test(S("12345678901234567890123456789012345678901234567890"), 0, S());
+  test(S("12345678901234567890123456789012345678901234567890"), 10,
+        S("1234567890"));
+  test(S("12345678901234567890123456789012345678901234567890"), 50,
+        S("12345678901234567890123456789012345678901234567890"));
+  test(S("12345678901234567890123456789012345678901234567890"), 60,
+        S("12345678901234567890123456789012345678901234567890\0\0\0\0\0\0\0\0\0\0", 60));
+  test(S(), S::npos, S("not going to happen"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), 0, S());
-    test(S(), 1, S(1, '\0'));
-    test(S(), 10, S(10, '\0'));
-    test(S(), 100, S(100, '\0'));
-    test(S("12345"), 0, S());
-    test(S("12345"), 2, S("12"));
-    test(S("12345"), 5, S("12345"));
-    test(S("12345"), 15, S("12345\0\0\0\0\0\0\0\0\0\0", 15));
-    test(S("12345678901234567890123456789012345678901234567890"), 0, S());
-    test(S("12345678901234567890123456789012345678901234567890"), 10,
-         S("1234567890"));
-    test(S("12345678901234567890123456789012345678901234567890"), 50,
-         S("12345678901234567890123456789012345678901234567890"));
-    test(S("12345678901234567890123456789012345678901234567890"), 60,
-         S("12345678901234567890123456789012345678901234567890\0\0\0\0\0\0\0\0\0\0", 60));
-    test(S(), S::npos, S("not going to happen"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), 0, S());
-    test(S(), 1, S(1, '\0'));
-    test(S(), 10, S(10, '\0'));
-    test(S(), 100, S(100, '\0'));
-    test(S("12345"), 0, S());
-    test(S("12345"), 2, S("12"));
-    test(S("12345"), 5, S("12345"));
-    test(S("12345"), 15, S("12345\0\0\0\0\0\0\0\0\0\0", 15));
-    test(S("12345678901234567890123456789012345678901234567890"), 0, S());
-    test(S("12345678901234567890123456789012345678901234567890"), 10,
-         S("1234567890"));
-    test(S("12345678901234567890123456789012345678901234567890"), 50,
-         S("12345678901234567890123456789012345678901234567890"));
-    test(S("12345678901234567890123456789012345678901234567890"), 60,
-         S("12345678901234567890123456789012345678901234567890\0\0\0\0\0\0\0\0\0\0", 60));
-    test(S(), S::npos, S("not going to happen"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
index 95317aa53ad3e..c35ffc2294239 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
@@ -43,46 +43,30 @@ test(S s, typename S::size_type n, typename S::value_type c, S expected)
 #endif
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), 0, 'a', S());
+  test(S(), 1, 'a', S("a"));
+  test(S(), 10, 'a', S(10, 'a'));
+  test(S(), 100, 'a', S(100, 'a'));
+  test(S("12345"), 0, 'a', S());
+  test(S("12345"), 2, 'a', S("12"));
+  test(S("12345"), 5, 'a', S("12345"));
+  test(S("12345"), 15, 'a', S("12345aaaaaaaaaa"));
+  test(S("12345678901234567890123456789012345678901234567890"), 0, 'a', S());
+  test(S("12345678901234567890123456789012345678901234567890"), 10, 'a',
+        S("1234567890"));
+  test(S("12345678901234567890123456789012345678901234567890"), 50, 'a',
+        S("12345678901234567890123456789012345678901234567890"));
+  test(S("12345678901234567890123456789012345678901234567890"), 60, 'a',
+        S("12345678901234567890123456789012345678901234567890aaaaaaaaaa"));
+  test(S(), S::npos, 'a', S("not going to happen"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), 0, 'a', S());
-    test(S(), 1, 'a', S("a"));
-    test(S(), 10, 'a', S(10, 'a'));
-    test(S(), 100, 'a', S(100, 'a'));
-    test(S("12345"), 0, 'a', S());
-    test(S("12345"), 2, 'a', S("12"));
-    test(S("12345"), 5, 'a', S("12345"));
-    test(S("12345"), 15, 'a', S("12345aaaaaaaaaa"));
-    test(S("12345678901234567890123456789012345678901234567890"), 0, 'a', S());
-    test(S("12345678901234567890123456789012345678901234567890"), 10, 'a',
-         S("1234567890"));
-    test(S("12345678901234567890123456789012345678901234567890"), 50, 'a',
-         S("12345678901234567890123456789012345678901234567890"));
-    test(S("12345678901234567890123456789012345678901234567890"), 60, 'a',
-         S("12345678901234567890123456789012345678901234567890aaaaaaaaaa"));
-    test(S(), S::npos, 'a', S("not going to happen"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), 0, 'a', S());
-    test(S(), 1, 'a', S("a"));
-    test(S(), 10, 'a', S(10, 'a'));
-    test(S(), 100, 'a', S(100, 'a'));
-    test(S("12345"), 0, 'a', S());
-    test(S("12345"), 2, 'a', S("12"));
-    test(S("12345"), 5, 'a', S("12345"));
-    test(S("12345"), 15, 'a', S("12345aaaaaaaaaa"));
-    test(S("12345678901234567890123456789012345678901234567890"), 0, 'a', S());
-    test(S("12345678901234567890123456789012345678901234567890"), 10, 'a',
-         S("1234567890"));
-    test(S("12345678901234567890123456789012345678901234567890"), 50, 'a',
-         S("12345678901234567890123456789012345678901234567890"));
-    test(S("12345678901234567890123456789012345678901234567890"), 60, 'a',
-         S("12345678901234567890123456789012345678901234567890aaaaaaaaaa"));
-    test(S(), S::npos, 'a', S("not going to happen"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp
index 1e85b3d3b51f0..376182e3cbfff 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp
@@ -29,34 +29,24 @@ test(S s)
     assert(s.capacity() >= s.size());
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    S s;
-    test(s);
-
-    s.assign(10, 'a');
-    s.erase(5);
-    test(s);
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  S s;
+  test(s);
 
-    s.assign(100, 'a');
-    s.erase(50);
-    test(s);
-  }
-#if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    S s;
-    test(s);
+  s.assign(10, 'a');
+  s.erase(5);
+  test(s);
 
-    s.assign(10, 'a');
-    s.erase(5);
-    test(s);
+  s.assign(100, 'a');
+  s.erase(50);
+  test(s);
+}
 
-    s.assign(100, 'a');
-    s.erase(50);
-    test(s);
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
+#if TEST_STD_VER >= 11
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.capacity/size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/size.pass.cpp
index fac0da78cecbb..05d77487131bf 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/size.pass.cpp
@@ -23,20 +23,17 @@ test(const S& s, typename S::size_type c)
     assert(s.size() == c);
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), 0);
+  test(S("123"), 3);
+  test(S("12345678901234567890123456789012345678901234567890"), 50);
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), 0);
-    test(S("123"), 3);
-    test(S("12345678901234567890123456789012345678901234567890"), 50);
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), 0);
-    test(S("123"), 3);
-    test(S("12345678901234567890123456789012345678901234567890"), 50);
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp
index ee516df15c9fd..38130b1b4bcb5 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp
@@ -28,22 +28,18 @@ test(S s1, typename S::value_type s2)
     assert(s1.capacity() >= s1.size());
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), 'a');
+  test(S("1"), 'a');
+  test(S("123456789"), 'a');
+  test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a');
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), 'a');
-    test(S("1"), 'a');
-    test(S("123456789"), 'a');
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a');
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), 'a');
-    test(S("1"), 'a');
-    test(S("123456789"), 'a');
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a');
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp
index 455655b4910c8..3b925d31cb913 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp
@@ -27,47 +27,32 @@ test(S s1, const S& s2)
     assert(s1.capacity() >= s1.size());
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), S());
-    test(S("1"), S());
-    test(S(), S("1"));
-    test(S("1"), S("2"));
-    test(S("1"), S("2"));
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), S());
+  test(S("1"), S());
+  test(S(), S("1"));
+  test(S("1"), S("2"));
+  test(S("1"), S("2"));
 
-    test(S(),
-         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("123456789"),
-         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
-         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
-           "1234567890123456789012345678901234567890123456789012345678901234567890"),
-         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-  }
-#if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), S());
-    test(S("1"), S());
-    test(S(), S("1"));
-    test(S("1"), S("2"));
-    test(S("1"), S("2"));
+  test(S(),
+        S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+  test(S("123456789"),
+        S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+  test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
+        S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+  test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
+          "1234567890123456789012345678901234567890123456789012345678901234567890"),
+        S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+}
 
-    test(S(),
-         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("123456789"),
-         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
-         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
-           "1234567890123456789012345678901234567890123456789012345678901234567890"),
-         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
+#if TEST_STD_VER >= 11
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
-#if TEST_STD_VER > 3
+#if TEST_STD_VER >= 11
   {   // LWG 2946
     std::string s;
     s = {"abc", 1};

diff  --git a/libcxx/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp
index eff8a025847a4..bdae97a332f20 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp
@@ -32,43 +32,30 @@ test(S s1, S s2)
     assert(s1.capacity() >= s1.size());
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), S());
-    test(S("1"), S());
-    test(S(), S("1"));
-    test(S("1"), S("2"));
-    test(S("1"), S("2"));
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), S());
+  test(S("1"), S());
+  test(S(), S("1"));
+  test(S("1"), S("2"));
+  test(S("1"), S("2"));
 
-    test(S(),
-         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("123456789"),
-         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
-         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
-           "1234567890123456789012345678901234567890123456789012345678901234567890"),
-         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-  }
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), S());
-    test(S("1"), S());
-    test(S(), S("1"));
-    test(S("1"), S("2"));
-    test(S("1"), S("2"));
+  test(S(),
+        S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+  test(S("123456789"),
+        S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+  test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
+        S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+  test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
+          "1234567890123456789012345678901234567890123456789012345678901234567890"),
+        S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+}
 
-    test(S(),
-         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("123456789"),
-         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
-         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
-           "1234567890123456789012345678901234567890123456789012345678901234567890"),
-         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
+#if TEST_STD_VER >= 11
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
+#endif
 
   return true;
 }

diff  --git a/libcxx/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp
index 5e8110bdce26f..b8318dec6c061 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp
@@ -29,44 +29,29 @@ test(S s1, const typename S::value_type* s2)
     assert(s1.capacity() >= s1.size());
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), "");
-    test(S("1"), "");
-    test(S(), "1");
-    test(S("1"), "2");
-    test(S("1"), "2");
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), "");
+  test(S("1"), "");
+  test(S(), "1");
+  test(S("1"), "2");
+  test(S("1"), "2");
 
-    test(S(),
-         "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
-    test(S("123456789"),
-         "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
-         "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
-           "1234567890123456789012345678901234567890123456789012345678901234567890"),
-         "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
-  }
-#if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), "");
-    test(S("1"), "");
-    test(S(), "1");
-    test(S("1"), "2");
-    test(S("1"), "2");
+  test(S(),
+        "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
+  test(S("123456789"),
+        "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
+  test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
+        "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
+  test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
+          "1234567890123456789012345678901234567890123456789012345678901234567890"),
+        "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
+}
 
-    test(S(),
-         "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
-    test(S("123456789"),
-         "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
-         "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
-           "1234567890123456789012345678901234567890123456789012345678901234567890"),
-         "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
+#if TEST_STD_VER >= 11
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp
index aaa787aad8c68..d98771c9129b6 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp
@@ -82,7 +82,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
   }
 #endif
 
-#if TEST_STD_VER > 3
+#if TEST_STD_VER >= 11
   {   // LWG 2946
     std::string s({"abc", 1});
     assert(s.size() == 1);

diff  --git a/libcxx/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp
index 79e680972b6af..ed09a1741d198 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp
@@ -28,46 +28,30 @@ test(S s1, SV sv)
     assert(s1.capacity() >= s1.size());
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    typedef std::string_view SV;
-    test(S(), SV(""));
-    test(S("1"), SV(""));
-    test(S(), SV("1"));
-    test(S("1"), SV("2"));
-    test(S("1"), SV("2"));
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  typedef std::string_view SV;
+  test(S(), SV(""));
+  test(S("1"), SV(""));
+  test(S(), SV("1"));
+  test(S("1"), SV("2"));
+  test(S("1"), SV("2"));
 
-    test(S(),
-         SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("123456789"),
-         SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
-         SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
-           "1234567890123456789012345678901234567890123456789012345678901234567890"),
-         SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-  }
-#if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    typedef std::string_view SV;
-    test(S(), SV(""));
-    test(S("1"), SV(""));
-    test(S(), SV("1"));
-    test(S("1"), SV("2"));
-    test(S("1"), SV("2"));
+  test(S(),
+        SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+  test(S("123456789"),
+        SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+  test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
+        SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+  test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
+          "1234567890123456789012345678901234567890123456789012345678901234567890"),
+        SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+}
 
-    test(S(),
-         SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("123456789"),
-         SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
-         SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
-           "1234567890123456789012345678901234567890123456789012345678901234567890"),
-         SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
+#if TEST_STD_VER >= 11
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp
index 465a26c7cd552..52239246ac5ca 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp
@@ -71,59 +71,38 @@ test_npos(S s, SV sv, typename S::size_type pos, S expected)
 #endif
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  typedef std::string_view SV;
+  test(S(), SV(), 0, 0, S());
+  test(S(), SV(), 1, 0, S());
+  test(S(), SV("12345"), 0, 3, S("123"));
+  test(S(), SV("12345"), 1, 4, S("2345"));
+  test(S(), SV("12345"), 3, 15, S("45"));
+  test(S(), SV("12345"), 5, 15, S(""));
+  test(S(), SV("12345"), 6, 15, S("not happening"));
+  test(S(), SV("12345678901234567890"), 0, 0, S());
+  test(S(), SV("12345678901234567890"), 1, 1, S("2"));
+  test(S(), SV("12345678901234567890"), 2, 3, S("345"));
+  test(S(), SV("12345678901234567890"), 12, 13, S("34567890"));
+  test(S(), SV("12345678901234567890"), 21, 13, S("not happening"));
+
+  test(S("12345"), SV(), 0, 0, S("12345"));
+  test(S("12345"), SV("12345"), 2, 2, S("1234534"));
+  test(S("12345"), SV("1234567890"), 0, 100, S("123451234567890"));
+
+  test(S("12345678901234567890"), SV(), 0, 0, S("12345678901234567890"));
+  test(S("12345678901234567890"), SV("12345"), 1, 3, S("12345678901234567890234"));
+  test(S("12345678901234567890"), SV("12345678901234567890"), 5, 10,
+        S("123456789012345678906789012345"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    typedef std::string_view SV;
-    test(S(), SV(), 0, 0, S());
-    test(S(), SV(), 1, 0, S());
-    test(S(), SV("12345"), 0, 3, S("123"));
-    test(S(), SV("12345"), 1, 4, S("2345"));
-    test(S(), SV("12345"), 3, 15, S("45"));
-    test(S(), SV("12345"), 5, 15, S(""));
-    test(S(), SV("12345"), 6, 15, S("not happening"));
-    test(S(), SV("12345678901234567890"), 0, 0, S());
-    test(S(), SV("12345678901234567890"), 1, 1, S("2"));
-    test(S(), SV("12345678901234567890"), 2, 3, S("345"));
-    test(S(), SV("12345678901234567890"), 12, 13, S("34567890"));
-    test(S(), SV("12345678901234567890"), 21, 13, S("not happening"));
-
-    test(S("12345"), SV(), 0, 0, S("12345"));
-    test(S("12345"), SV("12345"), 2, 2, S("1234534"));
-    test(S("12345"), SV("1234567890"), 0, 100, S("123451234567890"));
-
-    test(S("12345678901234567890"), SV(), 0, 0, S("12345678901234567890"));
-    test(S("12345678901234567890"), SV("12345"), 1, 3, S("12345678901234567890234"));
-    test(S("12345678901234567890"), SV("12345678901234567890"), 5, 10,
-         S("123456789012345678906789012345"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string     <char, std::char_traits<char>, min_allocator<char>> S;
-    typedef std::basic_string_view<char, std::char_traits<char> > SV;
-    test(S(), SV(), 0, 0, S());
-    test(S(), SV(), 1, 0, S());
-    test(S(), SV("12345"), 0, 3, S("123"));
-    test(S(), SV("12345"), 1, 4, S("2345"));
-    test(S(), SV("12345"), 3, 15, S("45"));
-    test(S(), SV("12345"), 5, 15, S(""));
-    test(S(), SV("12345"), 6, 15, S("not happening"));
-    test(S(), SV("12345678901234567890"), 0, 0, S());
-    test(S(), SV("12345678901234567890"), 1, 1, S("2"));
-    test(S(), SV("12345678901234567890"), 2, 3, S("345"));
-    test(S(), SV("12345678901234567890"), 12, 13, S("34567890"));
-    test(S(), SV("12345678901234567890"), 21, 13, S("not happening"));
-
-    test(S("12345"), SV(), 0, 0, S("12345"));
-    test(S("12345"), SV("12345"), 2, 2, S("1234534"));
-    test(S("12345"), SV("1234567890"), 0, 100, S("123451234567890"));
-
-    test(S("12345678901234567890"), SV(), 0, 0, S("12345678901234567890"));
-    test(S("12345678901234567890"), SV("12345"), 1, 3, S("12345678901234567890234"));
-    test(S("12345678901234567890"), SV("12345678901234567890"), 5, 10,
-         S("123456789012345678906789012345"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
+
   {
     typedef std::string S;
     typedef std::string_view SV;
@@ -195,7 +174,6 @@ TEST_CONSTEXPR_CXX20 bool test() {
     s.append(sv, 0, std::string::npos);
     assert(s == "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ");
   }
-
   return true;
 }
 

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
index 4c65fd1f89826..83b8d8a1147a6 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
@@ -52,125 +52,71 @@ test_exceptions(S s, It first, It last)
 }
 #endif
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+  test(S(), s, s, S());
+  test(S(), s, s+1, S("A"));
+  test(S(), s, s+10, S("ABCDEFGHIJ"));
+  test(S(), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S("12345"), s, s, S("12345"));
+  test(S("12345"), s, s+1, S("12345A"));
+  test(S("12345"), s, s+10, S("12345ABCDEFGHIJ"));
+  test(S("12345"), s, s+52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S("1234567890"), s, s, S("1234567890"));
+  test(S("1234567890"), s, s+1, S("1234567890A"));
+  test(S("1234567890"), s, s+10, S("1234567890ABCDEFGHIJ"));
+  test(S("1234567890"), s, s+52, S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S("12345678901234567890"), s, s, S("12345678901234567890"));
+  test(S("12345678901234567890"), s, s+1, S("12345678901234567890""A"));
+  test(S("12345678901234567890"), s, s+10, S("12345678901234567890""ABCDEFGHIJ"));
+  test(S("12345678901234567890"), s, s+52,
+      S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S());
+  test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("A"));
+  test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
+      S("ABCDEFGHIJ"));
+  test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
+      S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
+      S("12345"));
+  test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
+      S("12345A"));
+  test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
+      S("12345ABCDEFGHIJ"));
+  test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
+      S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
+      S("1234567890"));
+  test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
+      S("1234567890A"));
+  test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
+      S("1234567890ABCDEFGHIJ"));
+  test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
+      S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
+      S("12345678901234567890"));
+  test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
+      S("12345678901234567890""A"));
+  test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
+      S("12345678901234567890""ABCDEFGHIJ"));
+  test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
+      S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-    test(S(), s, s, S());
-    test(S(), s, s+1, S("A"));
-    test(S(), s, s+10, S("ABCDEFGHIJ"));
-    test(S(), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345"), s, s, S("12345"));
-    test(S("12345"), s, s+1, S("12345A"));
-    test(S("12345"), s, s+10, S("12345ABCDEFGHIJ"));
-    test(S("12345"), s, s+52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("1234567890"), s, s, S("1234567890"));
-    test(S("1234567890"), s, s+1, S("1234567890A"));
-    test(S("1234567890"), s, s+10, S("1234567890ABCDEFGHIJ"));
-    test(S("1234567890"), s, s+52, S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345678901234567890"), s, s, S("12345678901234567890"));
-    test(S("12345678901234567890"), s, s+1, S("12345678901234567890""A"));
-    test(S("12345678901234567890"), s, s+10, S("12345678901234567890""ABCDEFGHIJ"));
-    test(S("12345678901234567890"), s, s+52,
-         S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S());
-    test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("A"));
-    test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
-         S("ABCDEFGHIJ"));
-    test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
-         S("12345"));
-    test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
-         S("12345A"));
-    test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
-         S("12345ABCDEFGHIJ"));
-    test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
-         S("1234567890"));
-    test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
-         S("1234567890A"));
-    test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
-         S("1234567890ABCDEFGHIJ"));
-    test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
-         S("12345678901234567890"));
-    test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
-         S("12345678901234567890""A"));
-    test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
-         S("12345678901234567890""ABCDEFGHIJ"));
-    test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-    test(S(), s, s, S());
-    test(S(), s, s+1, S("A"));
-    test(S(), s, s+10, S("ABCDEFGHIJ"));
-    test(S(), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345"), s, s, S("12345"));
-    test(S("12345"), s, s+1, S("12345A"));
-    test(S("12345"), s, s+10, S("12345ABCDEFGHIJ"));
-    test(S("12345"), s, s+52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("1234567890"), s, s, S("1234567890"));
-    test(S("1234567890"), s, s+1, S("1234567890A"));
-    test(S("1234567890"), s, s+10, S("1234567890ABCDEFGHIJ"));
-    test(S("1234567890"), s, s+52, S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345678901234567890"), s, s, S("12345678901234567890"));
-    test(S("12345678901234567890"), s, s+1, S("12345678901234567890""A"));
-    test(S("12345678901234567890"), s, s+10, S("12345678901234567890""ABCDEFGHIJ"));
-    test(S("12345678901234567890"), s, s+52,
-         S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S());
-    test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("A"));
-    test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
-         S("ABCDEFGHIJ"));
-    test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
-         S("12345"));
-    test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
-         S("12345A"));
-    test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
-         S("12345ABCDEFGHIJ"));
-    test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
-         S("1234567890"));
-    test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
-         S("1234567890A"));
-    test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
-         S("1234567890ABCDEFGHIJ"));
-    test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
-         S("12345678901234567890"));
-    test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
-         S("12345678901234567890""A"));
-    test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
-         S("12345678901234567890""ABCDEFGHIJ"));
-    test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
+
 #ifndef TEST_HAS_NO_EXCEPTIONS
   if (!TEST_IS_CONSTANT_EVALUATED) { // test iterator operations that throw
     typedef std::string S;

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp
index 294645f766083..526fed83daca3 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp
@@ -26,38 +26,26 @@ test(S s, const typename S::value_type* str, S expected)
     assert(s == expected);
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), "", S());
-    test(S(), "12345", S("12345"));
-    test(S(), "12345678901234567890", S("12345678901234567890"));
-
-    test(S("12345"), "", S("12345"));
-    test(S("12345"), "12345", S("1234512345"));
-    test(S("12345"), "1234567890", S("123451234567890"));
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), "", S());
+  test(S(), "12345", S("12345"));
+  test(S(), "12345678901234567890", S("12345678901234567890"));
+
+  test(S("12345"), "", S("12345"));
+  test(S("12345"), "12345", S("1234512345"));
+  test(S("12345"), "1234567890", S("123451234567890"));
+
+  test(S("12345678901234567890"), "", S("12345678901234567890"));
+  test(S("12345678901234567890"), "12345", S("1234567890123456789012345"));
+  test(S("12345678901234567890"), "12345678901234567890",
+        S("1234567890123456789012345678901234567890"));
+}
 
-    test(S("12345678901234567890"), "", S("12345678901234567890"));
-    test(S("12345678901234567890"), "12345", S("1234567890123456789012345"));
-    test(S("12345678901234567890"), "12345678901234567890",
-         S("1234567890123456789012345678901234567890"));
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), "", S());
-    test(S(), "12345", S("12345"));
-    test(S(), "12345678901234567890", S("12345678901234567890"));
-
-    test(S("12345"), "", S("12345"));
-    test(S("12345"), "12345", S("1234512345"));
-    test(S("12345"), "1234567890", S("123451234567890"));
-
-    test(S("12345678901234567890"), "", S("12345678901234567890"));
-    test(S("12345678901234567890"), "12345", S("1234567890123456789012345"));
-    test(S("12345678901234567890"), "12345678901234567890",
-         S("1234567890123456789012345678901234567890"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   { // test appending to self
@@ -75,7 +63,6 @@ TEST_CONSTEXPR_CXX20 bool test() {
     s_long.append(s_long.c_str());
     assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
   }
-
   return true;
 }
 

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp
index dd15ca2d0cbbd..57390cadb7c4a 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp
@@ -27,46 +27,30 @@ test(S s, const typename S::value_type* str, typename S::size_type n, S expected
     assert(s == expected);
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), "", 0, S());
-    test(S(), "12345", 3, S("123"));
-    test(S(), "12345", 4, S("1234"));
-    test(S(), "12345678901234567890", 0, S());
-    test(S(), "12345678901234567890", 1, S("1"));
-    test(S(), "12345678901234567890", 3, S("123"));
-    test(S(), "12345678901234567890", 20, S("12345678901234567890"));
-
-    test(S("12345"), "", 0, S("12345"));
-    test(S("12345"), "12345", 5, S("1234512345"));
-    test(S("12345"), "1234567890", 10, S("123451234567890"));
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), "", 0, S());
+  test(S(), "12345", 3, S("123"));
+  test(S(), "12345", 4, S("1234"));
+  test(S(), "12345678901234567890", 0, S());
+  test(S(), "12345678901234567890", 1, S("1"));
+  test(S(), "12345678901234567890", 3, S("123"));
+  test(S(), "12345678901234567890", 20, S("12345678901234567890"));
+
+  test(S("12345"), "", 0, S("12345"));
+  test(S("12345"), "12345", 5, S("1234512345"));
+  test(S("12345"), "1234567890", 10, S("123451234567890"));
+
+  test(S("12345678901234567890"), "", 0, S("12345678901234567890"));
+  test(S("12345678901234567890"), "12345", 5, S("1234567890123456789012345"));
+  test(S("12345678901234567890"), "12345678901234567890", 20,
+        S("1234567890123456789012345678901234567890"));
+}
 
-    test(S("12345678901234567890"), "", 0, S("12345678901234567890"));
-    test(S("12345678901234567890"), "12345", 5, S("1234567890123456789012345"));
-    test(S("12345678901234567890"), "12345678901234567890", 20,
-         S("1234567890123456789012345678901234567890"));
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), "", 0, S());
-    test(S(), "12345", 3, S("123"));
-    test(S(), "12345", 4, S("1234"));
-    test(S(), "12345678901234567890", 0, S());
-    test(S(), "12345678901234567890", 1, S("1"));
-    test(S(), "12345678901234567890", 3, S("123"));
-    test(S(), "12345678901234567890", 20, S("12345678901234567890"));
-
-    test(S("12345"), "", 0, S("12345"));
-    test(S("12345"), "12345", 5, S("1234512345"));
-    test(S("12345"), "1234567890", 10, S("123451234567890"));
-
-    test(S("12345678901234567890"), "", 0, S("12345678901234567890"));
-    test(S("12345678901234567890"), "12345", 5, S("1234567890123456789012345"));
-    test(S("12345678901234567890"), "12345678901234567890", 20,
-         S("1234567890123456789012345678901234567890"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   { // test appending to self

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp
index a366bebe1cc13..d6c38d2f00d31 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp
@@ -26,38 +26,26 @@ test(S s, typename S::size_type n, typename S::value_type c, S expected)
     assert(s == expected);
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), 0, 'a', S());
-    test(S(), 1, 'a', S(1, 'a'));
-    test(S(), 10, 'a', S(10, 'a'));
-    test(S(), 100, 'a', S(100, 'a'));
-
-    test(S("12345"), 0, 'a', S("12345"));
-    test(S("12345"), 1, 'a', S("12345a"));
-    test(S("12345"), 10, 'a', S("12345aaaaaaaaaa"));
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), 0, 'a', S());
+  test(S(), 1, 'a', S(1, 'a'));
+  test(S(), 10, 'a', S(10, 'a'));
+  test(S(), 100, 'a', S(100, 'a'));
+
+  test(S("12345"), 0, 'a', S("12345"));
+  test(S("12345"), 1, 'a', S("12345a"));
+  test(S("12345"), 10, 'a', S("12345aaaaaaaaaa"));
+
+  test(S("12345678901234567890"), 0, 'a', S("12345678901234567890"));
+  test(S("12345678901234567890"), 1, 'a', S("12345678901234567890a"));
+  test(S("12345678901234567890"), 10, 'a', S("12345678901234567890aaaaaaaaaa"));
+}
 
-    test(S("12345678901234567890"), 0, 'a', S("12345678901234567890"));
-    test(S("12345678901234567890"), 1, 'a', S("12345678901234567890a"));
-    test(S("12345678901234567890"), 10, 'a', S("12345678901234567890aaaaaaaaaa"));
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), 0, 'a', S());
-    test(S(), 1, 'a', S(1, 'a'));
-    test(S(), 10, 'a', S(10, 'a'));
-    test(S(), 100, 'a', S(100, 'a'));
-
-    test(S("12345"), 0, 'a', S("12345"));
-    test(S("12345"), 1, 'a', S("12345a"));
-    test(S("12345"), 10, 'a', S("12345aaaaaaaaaa"));
-
-    test(S("12345678901234567890"), 0, 'a', S("12345678901234567890"));
-    test(S("12345678901234567890"), 1, 'a', S("12345678901234567890a"));
-    test(S("12345678901234567890"), 10, 'a', S("12345678901234567890aaaaaaaaaa"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp
index 49ef72fce718a..cd4b1a4ec5c92 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp
@@ -26,57 +26,37 @@ test(S s, S str, S expected)
     assert(s == expected);
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), S(), S());
-    test(S(), S("12345"), S("12345"));
-    test(S(), S("1234567890"), S("1234567890"));
-    test(S(), S("12345678901234567890"), S("12345678901234567890"));
-
-    test(S("12345"), S(), S("12345"));
-    test(S("12345"), S("12345"), S("1234512345"));
-    test(S("12345"), S("1234567890"), S("123451234567890"));
-    test(S("12345"), S("12345678901234567890"), S("1234512345678901234567890"));
-
-    test(S("1234567890"), S(), S("1234567890"));
-    test(S("1234567890"), S("12345"), S("123456789012345"));
-    test(S("1234567890"), S("1234567890"), S("12345678901234567890"));
-    test(S("1234567890"), S("12345678901234567890"), S("123456789012345678901234567890"));
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), S(), S());
+  test(S(), S("12345"), S("12345"));
+  test(S(), S("1234567890"), S("1234567890"));
+  test(S(), S("12345678901234567890"), S("12345678901234567890"));
+
+  test(S("12345"), S(), S("12345"));
+  test(S("12345"), S("12345"), S("1234512345"));
+  test(S("12345"), S("1234567890"), S("123451234567890"));
+  test(S("12345"), S("12345678901234567890"), S("1234512345678901234567890"));
+
+  test(S("1234567890"), S(), S("1234567890"));
+  test(S("1234567890"), S("12345"), S("123456789012345"));
+  test(S("1234567890"), S("1234567890"), S("12345678901234567890"));
+  test(S("1234567890"), S("12345678901234567890"), S("123456789012345678901234567890"));
+
+  test(S("12345678901234567890"), S(), S("12345678901234567890"));
+  test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
+  test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
+  test(S("12345678901234567890"), S("12345678901234567890"),
+        S("1234567890123456789012345678901234567890"));
+}
 
-    test(S("12345678901234567890"), S(), S("12345678901234567890"));
-    test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
-    test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
-    test(S("12345678901234567890"), S("12345678901234567890"),
-         S("1234567890123456789012345678901234567890"));
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), S(), S());
-    test(S(), S("12345"), S("12345"));
-    test(S(), S("1234567890"), S("1234567890"));
-    test(S(), S("12345678901234567890"), S("12345678901234567890"));
-
-    test(S("12345"), S(), S("12345"));
-    test(S("12345"), S("12345"), S("1234512345"));
-    test(S("12345"), S("1234567890"), S("123451234567890"));
-    test(S("12345"), S("12345678901234567890"), S("1234512345678901234567890"));
-
-    test(S("1234567890"), S(), S("1234567890"));
-    test(S("1234567890"), S("12345"), S("123456789012345"));
-    test(S("1234567890"), S("1234567890"), S("12345678901234567890"));
-    test(S("1234567890"), S("12345678901234567890"), S("123456789012345678901234567890"));
-
-    test(S("12345678901234567890"), S(), S("12345678901234567890"));
-    test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
-    test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
-    test(S("12345678901234567890"), S("12345678901234567890"),
-         S("1234567890123456789012345678901234567890"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
-#if TEST_STD_VER > 3
+#if TEST_STD_VER >= 11
   {   // LWG 2946
     std::string s;
     s.append({"abc", 1});

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
index 7dc0a327053e1..069775d4b3091 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
@@ -71,57 +71,37 @@ test_npos(S s, S str, typename S::size_type pos, S expected)
 #endif
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), S(), 0, 0, S());
-    test(S(), S(), 1, 0, S());
-    test(S(), S("12345"), 0, 3, S("123"));
-    test(S(), S("12345"), 1, 4, S("2345"));
-    test(S(), S("12345"), 3, 15, S("45"));
-    test(S(), S("12345"), 5, 15, S(""));
-    test(S(), S("12345"), 6, 15, S("not happening"));
-    test(S(), S("12345678901234567890"), 0, 0, S());
-    test(S(), S("12345678901234567890"), 1, 1, S("2"));
-    test(S(), S("12345678901234567890"), 2, 3, S("345"));
-    test(S(), S("12345678901234567890"), 12, 13, S("34567890"));
-    test(S(), S("12345678901234567890"), 21, 13, S("not happening"));
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), S(), 0, 0, S());
+  test(S(), S(), 1, 0, S());
+  test(S(), S("12345"), 0, 3, S("123"));
+  test(S(), S("12345"), 1, 4, S("2345"));
+  test(S(), S("12345"), 3, 15, S("45"));
+  test(S(), S("12345"), 5, 15, S(""));
+  test(S(), S("12345"), 6, 15, S("not happening"));
+  test(S(), S("12345678901234567890"), 0, 0, S());
+  test(S(), S("12345678901234567890"), 1, 1, S("2"));
+  test(S(), S("12345678901234567890"), 2, 3, S("345"));
+  test(S(), S("12345678901234567890"), 12, 13, S("34567890"));
+  test(S(), S("12345678901234567890"), 21, 13, S("not happening"));
 
-    test(S("12345"), S(), 0, 0, S("12345"));
-    test(S("12345"), S("12345"), 2, 2, S("1234534"));
-    test(S("12345"), S("1234567890"), 0, 100, S("123451234567890"));
+  test(S("12345"), S(), 0, 0, S("12345"));
+  test(S("12345"), S("12345"), 2, 2, S("1234534"));
+  test(S("12345"), S("1234567890"), 0, 100, S("123451234567890"));
 
-    test(S("12345678901234567890"), S(), 0, 0, S("12345678901234567890"));
-    test(S("12345678901234567890"), S("12345"), 1, 3, S("12345678901234567890234"));
-    test(S("12345678901234567890"), S("12345678901234567890"), 5, 10,
-         S("123456789012345678906789012345"));
-  }
-#if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), S(), 0, 0, S());
-    test(S(), S(), 1, 0, S());
-    test(S(), S("12345"), 0, 3, S("123"));
-    test(S(), S("12345"), 1, 4, S("2345"));
-    test(S(), S("12345"), 3, 15, S("45"));
-    test(S(), S("12345"), 5, 15, S(""));
-    test(S(), S("12345"), 6, 15, S("not happening"));
-    test(S(), S("12345678901234567890"), 0, 0, S());
-    test(S(), S("12345678901234567890"), 1, 1, S("2"));
-    test(S(), S("12345678901234567890"), 2, 3, S("345"));
-    test(S(), S("12345678901234567890"), 12, 13, S("34567890"));
-    test(S(), S("12345678901234567890"), 21, 13, S("not happening"));
-
-    test(S("12345"), S(), 0, 0, S("12345"));
-    test(S("12345"), S("12345"), 2, 2, S("1234534"));
-    test(S("12345"), S("1234567890"), 0, 100, S("123451234567890"));
+  test(S("12345678901234567890"), S(), 0, 0, S("12345678901234567890"));
+  test(S("12345678901234567890"), S("12345"), 1, 3, S("12345678901234567890234"));
+  test(S("12345678901234567890"), S("12345678901234567890"), 5, 10,
+        S("123456789012345678906789012345"));
+}
 
-    test(S("12345678901234567890"), S(), 0, 0, S("12345678901234567890"));
-    test(S("12345678901234567890"), S("12345"), 1, 3, S("12345678901234567890234"));
-    test(S("12345678901234567890"), S("12345678901234567890"), 5, 10,
-         S("123456789012345678906789012345"));
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
+#if TEST_STD_VER >= 11
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
+
   {
     typedef std::string S;
     test_npos(S(), S(), 0, S());

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_view.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_view.pass.cpp
index 55f8e5d8584d9..c68445eaa08ea 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_view.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/string_view.pass.cpp
@@ -27,56 +27,35 @@ test(S s, SV sv, S expected)
     assert(s == expected);
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    typedef std::string_view SV;
-    test(S(), SV(), S());
-    test(S(), SV("12345"), S("12345"));
-    test(S(), SV("1234567890"), S("1234567890"));
-    test(S(), SV("12345678901234567890"), S("12345678901234567890"));
-
-    test(S("12345"), SV(), S("12345"));
-    test(S("12345"), SV("12345"), S("1234512345"));
-    test(S("12345"), SV("1234567890"), S("123451234567890"));
-    test(S("12345"), SV("12345678901234567890"), S("1234512345678901234567890"));
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  typedef std::string_view SV;
+  test(S(), SV(), S());
+  test(S(), SV("12345"), S("12345"));
+  test(S(), SV("1234567890"), S("1234567890"));
+  test(S(), SV("12345678901234567890"), S("12345678901234567890"));
 
-    test(S("1234567890"), SV(), S("1234567890"));
-    test(S("1234567890"), SV("12345"), S("123456789012345"));
-    test(S("1234567890"), SV("1234567890"), S("12345678901234567890"));
-    test(S("1234567890"), SV("12345678901234567890"), S("123456789012345678901234567890"));
-
-    test(S("12345678901234567890"), SV(), S("12345678901234567890"));
-    test(S("12345678901234567890"), SV("12345"), S("1234567890123456789012345"));
-    test(S("12345678901234567890"), SV("1234567890"), S("123456789012345678901234567890"));
-    test(S("12345678901234567890"), SV("12345678901234567890"),
-         S("1234567890123456789012345678901234567890"));
-  }
-#if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string     <char, std::char_traits<char>, min_allocator<char>> S;
-    typedef std::basic_string_view<char, std::char_traits<char> > SV;
-    test(S(), SV(), S());
-    test(S(), SV("12345"), S("12345"));
-    test(S(), SV("1234567890"), S("1234567890"));
-    test(S(), SV("12345678901234567890"), S("12345678901234567890"));
+  test(S("12345"), SV(), S("12345"));
+  test(S("12345"), SV("12345"), S("1234512345"));
+  test(S("12345"), SV("1234567890"), S("123451234567890"));
+  test(S("12345"), SV("12345678901234567890"), S("1234512345678901234567890"));
 
-    test(S("12345"), SV(), S("12345"));
-    test(S("12345"), SV("12345"), S("1234512345"));
-    test(S("12345"), SV("1234567890"), S("123451234567890"));
-    test(S("12345"), SV("12345678901234567890"), S("1234512345678901234567890"));
+  test(S("1234567890"), SV(), S("1234567890"));
+  test(S("1234567890"), SV("12345"), S("123456789012345"));
+  test(S("1234567890"), SV("1234567890"), S("12345678901234567890"));
+  test(S("1234567890"), SV("12345678901234567890"), S("123456789012345678901234567890"));
 
-    test(S("1234567890"), SV(), S("1234567890"));
-    test(S("1234567890"), SV("12345"), S("123456789012345"));
-    test(S("1234567890"), SV("1234567890"), S("12345678901234567890"));
-    test(S("1234567890"), SV("12345678901234567890"), S("123456789012345678901234567890"));
+  test(S("12345678901234567890"), SV(), S("12345678901234567890"));
+  test(S("12345678901234567890"), SV("12345"), S("1234567890123456789012345"));
+  test(S("12345678901234567890"), SV("1234567890"), S("123456789012345678901234567890"));
+  test(S("12345678901234567890"), SV("12345678901234567890"),
+        S("1234567890123456789012345678901234567890"));
+}
 
-    test(S("12345678901234567890"), SV(), S("12345678901234567890"));
-    test(S("12345678901234567890"), SV("12345"), S("1234567890123456789012345"));
-    test(S("12345678901234567890"), SV("1234567890"), S("123456789012345678901234567890"));
-    test(S("12345678901234567890"), SV("12345678901234567890"),
-         S("1234567890123456789012345678901234567890"));
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
+#if TEST_STD_VER >= 11
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
index 00a085ffba936..727e1986f37a4 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
@@ -70,59 +70,38 @@ test_npos(S s, SV sv, typename S::size_type pos, S expected)
 #endif
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  typedef std::string_view SV;
+  test(S(), SV(), 0, 0, S());
+  test(S(), SV(), 1, 0, S());
+  test(S(), SV("12345"), 0, 3, S("123"));
+  test(S(), SV("12345"), 1, 4, S("2345"));
+  test(S(), SV("12345"), 3, 15, S("45"));
+  test(S(), SV("12345"), 5, 15, S(""));
+  test(S(), SV("12345"), 6, 15, S("not happening"));
+  test(S(), SV("12345678901234567890"), 0, 0, S());
+  test(S(), SV("12345678901234567890"), 1, 1, S("2"));
+  test(S(), SV("12345678901234567890"), 2, 3, S("345"));
+  test(S(), SV("12345678901234567890"), 12, 13, S("34567890"));
+  test(S(), SV("12345678901234567890"), 21, 13, S("not happening"));
+
+  test(S("12345"), SV(), 0, 0, S());
+  test(S("12345"), SV("12345"), 2, 2, S("34"));
+  test(S("12345"), SV("1234567890"), 0, 100, S("1234567890"));
+
+  test(S("12345678901234567890"), SV(), 0, 0, S());
+  test(S("12345678901234567890"), SV("12345"), 1, 3, S("234"));
+  test(S("12345678901234567890"), SV("12345678901234567890"), 5, 10,
+        S("6789012345"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    typedef std::string_view SV;
-    test(S(), SV(), 0, 0, S());
-    test(S(), SV(), 1, 0, S());
-    test(S(), SV("12345"), 0, 3, S("123"));
-    test(S(), SV("12345"), 1, 4, S("2345"));
-    test(S(), SV("12345"), 3, 15, S("45"));
-    test(S(), SV("12345"), 5, 15, S(""));
-    test(S(), SV("12345"), 6, 15, S("not happening"));
-    test(S(), SV("12345678901234567890"), 0, 0, S());
-    test(S(), SV("12345678901234567890"), 1, 1, S("2"));
-    test(S(), SV("12345678901234567890"), 2, 3, S("345"));
-    test(S(), SV("12345678901234567890"), 12, 13, S("34567890"));
-    test(S(), SV("12345678901234567890"), 21, 13, S("not happening"));
-
-    test(S("12345"), SV(), 0, 0, S());
-    test(S("12345"), SV("12345"), 2, 2, S("34"));
-    test(S("12345"), SV("1234567890"), 0, 100, S("1234567890"));
-
-    test(S("12345678901234567890"), SV(), 0, 0, S());
-    test(S("12345678901234567890"), SV("12345"), 1, 3, S("234"));
-    test(S("12345678901234567890"), SV("12345678901234567890"), 5, 10,
-         S("6789012345"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string     <char, std::char_traits<char>, min_allocator<char>> S;
-    typedef std::basic_string_view<char, std::char_traits<char> > SV;
-    test(S(), SV(), 0, 0, S());
-    test(S(), SV(), 1, 0, S());
-    test(S(), SV("12345"), 0, 3, S("123"));
-    test(S(), SV("12345"), 1, 4, S("2345"));
-    test(S(), SV("12345"), 3, 15, S("45"));
-    test(S(), SV("12345"), 5, 15, S(""));
-    test(S(), SV("12345"), 6, 15, S("not happening"));
-    test(S(), SV("12345678901234567890"), 0, 0, S());
-    test(S(), SV("12345678901234567890"), 1, 1, S("2"));
-    test(S(), SV("12345678901234567890"), 2, 3, S("345"));
-    test(S(), SV("12345678901234567890"), 12, 13, S("34567890"));
-    test(S(), SV("12345678901234567890"), 21, 13, S("not happening"));
-
-    test(S("12345"), SV(), 0, 0, S());
-    test(S("12345"), SV("12345"), 2, 2, S("34"));
-    test(S("12345"), SV("1234567890"), 0, 100, S("1234567890"));
-
-    test(S("12345678901234567890"), SV(), 0, 0, S());
-    test(S("12345678901234567890"), SV("12345"), 1, 3, S("234"));
-    test(S("12345678901234567890"), SV("12345678901234567890"), 5, 10,
-         S("6789012345"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
+
   {
     typedef std::string S;
     typedef std::string_view SV;
@@ -190,7 +169,6 @@ TEST_CONSTEXPR_CXX20 bool test() {
     s.assign(sv, 0, std::string::npos);
     assert(s == "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
   }
-
   return true;
 }
 

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
index 0a68b2f4b4c80..3b8d0dcc0a6b0 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
@@ -52,125 +52,71 @@ test_exceptions(S s, It first, It last)
 }
 #endif
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+  test(S(), s, s, S());
+  test(S(), s, s+1, S("A"));
+  test(S(), s, s+10, S("ABCDEFGHIJ"));
+  test(S(), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S("12345"), s, s, S());
+  test(S("12345"), s, s+1, S("A"));
+  test(S("12345"), s, s+10, S("ABCDEFGHIJ"));
+  test(S("12345"), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S("1234567890"), s, s, S());
+  test(S("1234567890"), s, s+1, S("A"));
+  test(S("1234567890"), s, s+10, S("ABCDEFGHIJ"));
+  test(S("1234567890"), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S("12345678901234567890"), s, s, S());
+  test(S("12345678901234567890"), s, s+1, S("A"));
+  test(S("12345678901234567890"), s, s+10, S("ABCDEFGHIJ"));
+  test(S("12345678901234567890"), s, s+52,
+      S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S());
+  test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("A"));
+  test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
+      S("ABCDEFGHIJ"));
+  test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
+      S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
+      S());
+  test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
+      S("A"));
+  test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
+      S("ABCDEFGHIJ"));
+  test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
+      S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
+      S());
+  test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
+      S("A"));
+  test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
+      S("ABCDEFGHIJ"));
+  test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
+      S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
+      S());
+  test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
+      S("A"));
+  test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
+      S("ABCDEFGHIJ"));
+  test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
+      S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-    test(S(), s, s, S());
-    test(S(), s, s+1, S("A"));
-    test(S(), s, s+10, S("ABCDEFGHIJ"));
-    test(S(), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345"), s, s, S());
-    test(S("12345"), s, s+1, S("A"));
-    test(S("12345"), s, s+10, S("ABCDEFGHIJ"));
-    test(S("12345"), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("1234567890"), s, s, S());
-    test(S("1234567890"), s, s+1, S("A"));
-    test(S("1234567890"), s, s+10, S("ABCDEFGHIJ"));
-    test(S("1234567890"), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345678901234567890"), s, s, S());
-    test(S("12345678901234567890"), s, s+1, S("A"));
-    test(S("12345678901234567890"), s, s+10, S("ABCDEFGHIJ"));
-    test(S("12345678901234567890"), s, s+52,
-         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S());
-    test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("A"));
-    test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
-         S("ABCDEFGHIJ"));
-    test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
-         S());
-    test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
-         S("A"));
-    test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
-         S("ABCDEFGHIJ"));
-    test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
-         S());
-    test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
-         S("A"));
-    test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
-         S("ABCDEFGHIJ"));
-    test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
-         S());
-    test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
-         S("A"));
-    test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
-         S("ABCDEFGHIJ"));
-    test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-    test(S(), s, s, S());
-    test(S(), s, s+1, S("A"));
-    test(S(), s, s+10, S("ABCDEFGHIJ"));
-    test(S(), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345"), s, s, S());
-    test(S("12345"), s, s+1, S("A"));
-    test(S("12345"), s, s+10, S("ABCDEFGHIJ"));
-    test(S("12345"), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("1234567890"), s, s, S());
-    test(S("1234567890"), s, s+1, S("A"));
-    test(S("1234567890"), s, s+10, S("ABCDEFGHIJ"));
-    test(S("1234567890"), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345678901234567890"), s, s, S());
-    test(S("12345678901234567890"), s, s+1, S("A"));
-    test(S("12345678901234567890"), s, s+10, S("ABCDEFGHIJ"));
-    test(S("12345678901234567890"), s, s+52,
-         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S());
-    test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("A"));
-    test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
-         S("ABCDEFGHIJ"));
-    test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
-         S());
-    test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
-         S("A"));
-    test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
-         S("ABCDEFGHIJ"));
-    test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
-         S());
-    test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
-         S("A"));
-    test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
-         S("ABCDEFGHIJ"));
-    test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
-         S());
-    test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
-         S("A"));
-    test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
-         S("ABCDEFGHIJ"));
-    test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
+
 #ifndef TEST_HAS_NO_EXCEPTIONS
   if (!TEST_IS_CONSTANT_EVALUATED) { // test iterator operations that throw
     typedef std::string S;
@@ -222,7 +168,6 @@ TEST_CONSTEXPR_CXX20 bool test() {
     std::string expected = sneaky + std::string(1, '\0');
     test(sneaky, sneaky.data(), sneaky.data() + sneaky.size() + 1, expected);
   }
-
   return true;
 }
 

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp
index b55f577485f51..5148f46c1891f 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp
@@ -26,38 +26,26 @@ test(S s, const typename S::value_type* str, S expected)
     assert(s == expected);
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), "", S());
-    test(S(), "12345", S("12345"));
-    test(S(), "12345678901234567890", S("12345678901234567890"));
-
-    test(S("12345"), "", S());
-    test(S("12345"), "12345", S("12345"));
-    test(S("12345"), "1234567890", S("1234567890"));
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), "", S());
+  test(S(), "12345", S("12345"));
+  test(S(), "12345678901234567890", S("12345678901234567890"));
+
+  test(S("12345"), "", S());
+  test(S("12345"), "12345", S("12345"));
+  test(S("12345"), "1234567890", S("1234567890"));
+
+  test(S("12345678901234567890"), "", S());
+  test(S("12345678901234567890"), "12345", S("12345"));
+  test(S("12345678901234567890"), "12345678901234567890",
+        S("12345678901234567890"));
+}
 
-    test(S("12345678901234567890"), "", S());
-    test(S("12345678901234567890"), "12345", S("12345"));
-    test(S("12345678901234567890"), "12345678901234567890",
-         S("12345678901234567890"));
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), "", S());
-    test(S(), "12345", S("12345"));
-    test(S(), "12345678901234567890", S("12345678901234567890"));
-
-    test(S("12345"), "", S());
-    test(S("12345"), "12345", S("12345"));
-    test(S("12345"), "1234567890", S("1234567890"));
-
-    test(S("12345678901234567890"), "", S());
-    test(S("12345678901234567890"), "12345", S("12345"));
-    test(S("12345678901234567890"), "12345678901234567890",
-         S("12345678901234567890"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   { // test assignment to self

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp
index 8b4ec9ce16753..25a62b72b75e0 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp
@@ -27,47 +27,32 @@ test(S s, const typename S::value_type* str, typename S::size_type n, S expected
     assert(s == expected);
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), "", 0, S());
-    test(S(), "12345", 3, S("123"));
-    test(S(), "12345", 4, S("1234"));
-    test(S(), "12345678901234567890", 0, S());
-    test(S(), "12345678901234567890", 1, S("1"));
-    test(S(), "12345678901234567890", 3, S("123"));
-    test(S(), "12345678901234567890", 20, S("12345678901234567890"));
-
-    test(S("12345"), "", 0, S());
-    test(S("12345"), "12345", 5, S("12345"));
-    test(S("12345"), "1234567890", 10, S("1234567890"));
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), "", 0, S());
+  test(S(), "12345", 3, S("123"));
+  test(S(), "12345", 4, S("1234"));
+  test(S(), "12345678901234567890", 0, S());
+  test(S(), "12345678901234567890", 1, S("1"));
+  test(S(), "12345678901234567890", 3, S("123"));
+  test(S(), "12345678901234567890", 20, S("12345678901234567890"));
+
+  test(S("12345"), "", 0, S());
+  test(S("12345"), "12345", 5, S("12345"));
+  test(S("12345"), "1234567890", 10, S("1234567890"));
+
+  test(S("12345678901234567890"), "", 0, S());
+  test(S("12345678901234567890"), "12345", 5, S("12345"));
+  test(S("12345678901234567890"), "12345678901234567890", 20,
+        S("12345678901234567890"));
+}
 
-    test(S("12345678901234567890"), "", 0, S());
-    test(S("12345678901234567890"), "12345", 5, S("12345"));
-    test(S("12345678901234567890"), "12345678901234567890", 20,
-         S("12345678901234567890"));
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), "", 0, S());
-    test(S(), "12345", 3, S("123"));
-    test(S(), "12345", 4, S("1234"));
-    test(S(), "12345678901234567890", 0, S());
-    test(S(), "12345678901234567890", 1, S("1"));
-    test(S(), "12345678901234567890", 3, S("123"));
-    test(S(), "12345678901234567890", 20, S("12345678901234567890"));
-
-    test(S("12345"), "", 0, S());
-    test(S("12345"), "12345", 5, S("12345"));
-    test(S("12345"), "1234567890", 10, S("1234567890"));
-
-    test(S("12345678901234567890"), "", 0, S());
-    test(S("12345678901234567890"), "12345", 5, S("12345"));
-    test(S("12345678901234567890"), "12345678901234567890", 20,
-         S("12345678901234567890"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
+
   { // test assign to self
     typedef std::string S;
     S s_short = "123/";
@@ -84,7 +69,6 @@ TEST_CONSTEXPR_CXX20 bool test() {
     s_long.assign(s_long.data() + 2, 8 );
     assert(s_long == "rem ipsu");
   }
-
   return true;
 }
 

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/rv_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/rv_string.pass.cpp
index ecc1b83ce89f1..f491ae04e597c 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/rv_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/rv_string.pass.cpp
@@ -27,54 +27,34 @@ test(S s, S str, S expected)
     assert(s == expected);
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), S(), S());
-    test(S(), S("12345"), S("12345"));
-    test(S(), S("1234567890"), S("1234567890"));
-    test(S(), S("12345678901234567890"), S("12345678901234567890"));
-
-    test(S("12345"), S(), S());
-    test(S("12345"), S("12345"), S("12345"));
-    test(S("12345"), S("1234567890"), S("1234567890"));
-    test(S("12345"), S("12345678901234567890"), S("12345678901234567890"));
-
-    test(S("1234567890"), S(), S());
-    test(S("1234567890"), S("12345"), S("12345"));
-    test(S("1234567890"), S("1234567890"), S("1234567890"));
-    test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890"));
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), S(), S());
+  test(S(), S("12345"), S("12345"));
+  test(S(), S("1234567890"), S("1234567890"));
+  test(S(), S("12345678901234567890"), S("12345678901234567890"));
 
-    test(S("12345678901234567890"), S(), S());
-    test(S("12345678901234567890"), S("12345"), S("12345"));
-    test(S("12345678901234567890"), S("1234567890"), S("1234567890"));
-    test(S("12345678901234567890"), S("12345678901234567890"),
-         S("12345678901234567890"));
-  }
-#if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), S(), S());
-    test(S(), S("12345"), S("12345"));
-    test(S(), S("1234567890"), S("1234567890"));
-    test(S(), S("12345678901234567890"), S("12345678901234567890"));
+  test(S("12345"), S(), S());
+  test(S("12345"), S("12345"), S("12345"));
+  test(S("12345"), S("1234567890"), S("1234567890"));
+  test(S("12345"), S("12345678901234567890"), S("12345678901234567890"));
 
-    test(S("12345"), S(), S());
-    test(S("12345"), S("12345"), S("12345"));
-    test(S("12345"), S("1234567890"), S("1234567890"));
-    test(S("12345"), S("12345678901234567890"), S("12345678901234567890"));
+  test(S("1234567890"), S(), S());
+  test(S("1234567890"), S("12345"), S("12345"));
+  test(S("1234567890"), S("1234567890"), S("1234567890"));
+  test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890"));
 
-    test(S("1234567890"), S(), S());
-    test(S("1234567890"), S("12345"), S("12345"));
-    test(S("1234567890"), S("1234567890"), S("1234567890"));
-    test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890"));
+  test(S("12345678901234567890"), S(), S());
+  test(S("12345678901234567890"), S("12345"), S("12345"));
+  test(S("12345678901234567890"), S("1234567890"), S("1234567890"));
+  test(S("12345678901234567890"), S("12345678901234567890"),
+        S("12345678901234567890"));
+}
 
-    test(S("12345678901234567890"), S(), S());
-    test(S("12345678901234567890"), S("12345"), S("12345"));
-    test(S("12345678901234567890"), S("1234567890"), S("1234567890"));
-    test(S("12345678901234567890"), S("12345678901234567890"),
-         S("12345678901234567890"));
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
+#if TEST_STD_VER >= 11
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp
index 0da607db8545b..82672e07d2fb0 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp
@@ -26,38 +26,26 @@ test(S s, typename S::size_type n, typename S::value_type c, S expected)
     assert(s == expected);
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), 0, 'a', S());
-    test(S(), 1, 'a', S(1, 'a'));
-    test(S(), 10, 'a', S(10, 'a'));
-    test(S(), 100, 'a', S(100, 'a'));
-
-    test(S("12345"), 0, 'a', S());
-    test(S("12345"), 1, 'a', S(1, 'a'));
-    test(S("12345"), 10, 'a', S(10, 'a'));
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), 0, 'a', S());
+  test(S(), 1, 'a', S(1, 'a'));
+  test(S(), 10, 'a', S(10, 'a'));
+  test(S(), 100, 'a', S(100, 'a'));
+
+  test(S("12345"), 0, 'a', S());
+  test(S("12345"), 1, 'a', S(1, 'a'));
+  test(S("12345"), 10, 'a', S(10, 'a'));
+
+  test(S("12345678901234567890"), 0, 'a', S());
+  test(S("12345678901234567890"), 1, 'a', S(1, 'a'));
+  test(S("12345678901234567890"), 10, 'a', S(10, 'a'));
+}
 
-    test(S("12345678901234567890"), 0, 'a', S());
-    test(S("12345678901234567890"), 1, 'a', S(1, 'a'));
-    test(S("12345678901234567890"), 10, 'a', S(10, 'a'));
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), 0, 'a', S());
-    test(S(), 1, 'a', S(1, 'a'));
-    test(S(), 10, 'a', S(10, 'a'));
-    test(S(), 100, 'a', S(100, 'a'));
-
-    test(S("12345"), 0, 'a', S());
-    test(S("12345"), 1, 'a', S(1, 'a'));
-    test(S("12345"), 10, 'a', S(10, 'a'));
-
-    test(S("12345678901234567890"), 0, 'a', S());
-    test(S("12345678901234567890"), 1, 'a', S(1, 'a'));
-    test(S("12345678901234567890"), 10, 'a', S(10, 'a'));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
index de20c6e56641d..4246366a29f0c 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
@@ -71,57 +71,37 @@ test_npos(S s, S str, typename S::size_type pos, S expected)
 #endif
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), S(), 0, 0, S());
-    test(S(), S(), 1, 0, S());
-    test(S(), S("12345"), 0, 3, S("123"));
-    test(S(), S("12345"), 1, 4, S("2345"));
-    test(S(), S("12345"), 3, 15, S("45"));
-    test(S(), S("12345"), 5, 15, S(""));
-    test(S(), S("12345"), 6, 15, S("not happening"));
-    test(S(), S("12345678901234567890"), 0, 0, S());
-    test(S(), S("12345678901234567890"), 1, 1, S("2"));
-    test(S(), S("12345678901234567890"), 2, 3, S("345"));
-    test(S(), S("12345678901234567890"), 12, 13, S("34567890"));
-    test(S(), S("12345678901234567890"), 21, 13, S("not happening"));
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), S(), 0, 0, S());
+  test(S(), S(), 1, 0, S());
+  test(S(), S("12345"), 0, 3, S("123"));
+  test(S(), S("12345"), 1, 4, S("2345"));
+  test(S(), S("12345"), 3, 15, S("45"));
+  test(S(), S("12345"), 5, 15, S(""));
+  test(S(), S("12345"), 6, 15, S("not happening"));
+  test(S(), S("12345678901234567890"), 0, 0, S());
+  test(S(), S("12345678901234567890"), 1, 1, S("2"));
+  test(S(), S("12345678901234567890"), 2, 3, S("345"));
+  test(S(), S("12345678901234567890"), 12, 13, S("34567890"));
+  test(S(), S("12345678901234567890"), 21, 13, S("not happening"));
 
-    test(S("12345"), S(), 0, 0, S());
-    test(S("12345"), S("12345"), 2, 2, S("34"));
-    test(S("12345"), S("1234567890"), 0, 100, S("1234567890"));
+  test(S("12345"), S(), 0, 0, S());
+  test(S("12345"), S("12345"), 2, 2, S("34"));
+  test(S("12345"), S("1234567890"), 0, 100, S("1234567890"));
 
-    test(S("12345678901234567890"), S(), 0, 0, S());
-    test(S("12345678901234567890"), S("12345"), 1, 3, S("234"));
-    test(S("12345678901234567890"), S("12345678901234567890"), 5, 10,
-         S("6789012345"));
-  }
-#if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), S(), 0, 0, S());
-    test(S(), S(), 1, 0, S());
-    test(S(), S("12345"), 0, 3, S("123"));
-    test(S(), S("12345"), 1, 4, S("2345"));
-    test(S(), S("12345"), 3, 15, S("45"));
-    test(S(), S("12345"), 5, 15, S(""));
-    test(S(), S("12345"), 6, 15, S("not happening"));
-    test(S(), S("12345678901234567890"), 0, 0, S());
-    test(S(), S("12345678901234567890"), 1, 1, S("2"));
-    test(S(), S("12345678901234567890"), 2, 3, S("345"));
-    test(S(), S("12345678901234567890"), 12, 13, S("34567890"));
-    test(S(), S("12345678901234567890"), 21, 13, S("not happening"));
-
-    test(S("12345"), S(), 0, 0, S());
-    test(S("12345"), S("12345"), 2, 2, S("34"));
-    test(S("12345"), S("1234567890"), 0, 100, S("1234567890"));
+  test(S("12345678901234567890"), S(), 0, 0, S());
+  test(S("12345678901234567890"), S("12345"), 1, 3, S("234"));
+  test(S("12345678901234567890"), S("12345678901234567890"), 5, 10,
+        S("6789012345"));
+}
 
-    test(S("12345678901234567890"), S(), 0, 0, S());
-    test(S("12345678901234567890"), S("12345"), 1, 3, S("234"));
-    test(S("12345678901234567890"), S("12345678901234567890"), 5, 10,
-         S("6789012345"));
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
+#if TEST_STD_VER >= 11
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
+
   {
     typedef std::string S;
     test_npos(S(), S(), 0, S());

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_view.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_view.pass.cpp
index 07cd7e4700e3c..2a07424b78a08 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_view.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string_view.pass.cpp
@@ -38,67 +38,42 @@ testAlloc(S s, SV sv, const typename S::allocator_type& a)
     assert(s.get_allocator() == a);
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    typedef std::string_view SV;
-    test(S(), SV(), S());
-    test(S(), SV("12345"), S("12345"));
-    test(S(), SV("1234567890"), S("1234567890"));
-    test(S(), SV("12345678901234567890"), S("12345678901234567890"));
-
-    test(S("12345"), SV(), S());
-    test(S("12345"), SV("12345"), S("12345"));
-    test(S("12345"), SV("1234567890"), S("1234567890"));
-    test(S("12345"), SV("12345678901234567890"), S("12345678901234567890"));
-
-    test(S("1234567890"), SV(), S());
-    test(S("1234567890"), SV("12345"), S("12345"));
-    test(S("1234567890"), SV("1234567890"), S("1234567890"));
-    test(S("1234567890"), SV("12345678901234567890"), S("12345678901234567890"));
-
-    test(S("12345678901234567890"), SV(), S());
-    test(S("12345678901234567890"), SV("12345"), S("12345"));
-    test(S("12345678901234567890"), SV("1234567890"), S("1234567890"));
-    test(S("12345678901234567890"), SV("12345678901234567890"),
-         S("12345678901234567890"));
-
-    testAlloc(S(), SV(), std::allocator<char>());
-    testAlloc(S(), SV("12345"), std::allocator<char>());
-    testAlloc(S(), SV("1234567890"), std::allocator<char>());
-    testAlloc(S(), SV("12345678901234567890"), std::allocator<char>());
-  }
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  typedef std::string_view SV;
+  test(S(), SV(), S());
+  test(S(), SV("12345"), S("12345"));
+  test(S(), SV("1234567890"), S("1234567890"));
+  test(S(), SV("12345678901234567890"), S("12345678901234567890"));
+
+  test(S("12345"), SV(), S());
+  test(S("12345"), SV("12345"), S("12345"));
+  test(S("12345"), SV("1234567890"), S("1234567890"));
+  test(S("12345"), SV("12345678901234567890"), S("12345678901234567890"));
+
+  test(S("1234567890"), SV(), S());
+  test(S("1234567890"), SV("12345"), S("12345"));
+  test(S("1234567890"), SV("1234567890"), S("1234567890"));
+  test(S("1234567890"), SV("12345678901234567890"), S("12345678901234567890"));
+
+  test(S("12345678901234567890"), SV(), S());
+  test(S("12345678901234567890"), SV("12345"), S("12345"));
+  test(S("12345678901234567890"), SV("1234567890"), S("1234567890"));
+  test(S("12345678901234567890"), SV("12345678901234567890"),
+        S("12345678901234567890"));
+
+  using A = typename S::allocator_type;
+
+  testAlloc(S(), SV(), A());
+  testAlloc(S(), SV("12345"), A());
+  testAlloc(S(), SV("1234567890"), A());
+  testAlloc(S(), SV("12345678901234567890"), A());
+}
 
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string     <char, std::char_traits<char>, min_allocator<char>> S;
-    typedef std::basic_string_view<char, std::char_traits<char> > SV;
-    test(S(), SV(), S());
-    test(S(), SV("12345"), S("12345"));
-    test(S(), SV("1234567890"), S("1234567890"));
-    test(S(), SV("12345678901234567890"), S("12345678901234567890"));
-
-    test(S("12345"), SV(), S());
-    test(S("12345"), SV("12345"), S("12345"));
-    test(S("12345"), SV("1234567890"), S("1234567890"));
-    test(S("12345"), SV("12345678901234567890"), S("12345678901234567890"));
-
-    test(S("1234567890"), SV(), S());
-    test(S("1234567890"), SV("12345"), S("12345"));
-    test(S("1234567890"), SV("1234567890"), S("1234567890"));
-    test(S("1234567890"), SV("12345678901234567890"), S("12345678901234567890"));
-
-    test(S("12345678901234567890"), SV(), S());
-    test(S("12345678901234567890"), SV("12345"), S("12345"));
-    test(S("12345678901234567890"), SV("1234567890"), S("1234567890"));
-    test(S("12345678901234567890"), SV("12345678901234567890"),
-         S("12345678901234567890"));
-
-    testAlloc(S(), SV(), min_allocator<char>());
-    testAlloc(S(), SV("12345"), min_allocator<char>());
-    testAlloc(S(), SV("1234567890"), min_allocator<char>());
-    testAlloc(S(), SV("12345678901234567890"), min_allocator<char>());
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
index 64a5f75dc1d51..9c8c01878a734 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
@@ -49,132 +49,73 @@ test(S str, typename S::value_type* s, typename S::size_type n,
 #endif
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  char s[50];
+  test(S(""), s, 0, 0);
+  test(S(""), s, 0, 1);
+  test(S(""), s, 1, 0);
+  test(S("abcde"), s, 0, 0);
+  test(S("abcde"), s, 0, 1);
+  test(S("abcde"), s, 0, 2);
+  test(S("abcde"), s, 0, 4);
+  test(S("abcde"), s, 0, 5);
+  test(S("abcde"), s, 0, 6);
+  test(S("abcde"), s, 1, 0);
+  test(S("abcde"), s, 1, 1);
+  test(S("abcde"), s, 1, 2);
+  test(S("abcde"), s, 1, 4);
+  test(S("abcde"), s, 1, 5);
+  test(S("abcde"), s, 2, 0);
+  test(S("abcde"), s, 2, 1);
+  test(S("abcde"), s, 2, 2);
+  test(S("abcde"), s, 2, 4);
+  test(S("abcde"), s, 4, 0);
+  test(S("abcde"), s, 4, 1);
+  test(S("abcde"), s, 4, 2);
+  test(S("abcde"), s, 5, 0);
+  test(S("abcde"), s, 5, 1);
+  test(S("abcde"), s, 6, 0);
+  test(S("abcdefghijklmnopqrst"), s, 0, 0);
+  test(S("abcdefghijklmnopqrst"), s, 0, 1);
+  test(S("abcdefghijklmnopqrst"), s, 0, 2);
+  test(S("abcdefghijklmnopqrst"), s, 0, 10);
+  test(S("abcdefghijklmnopqrst"), s, 0, 19);
+  test(S("abcdefghijklmnopqrst"), s, 0, 20);
+  test(S("abcdefghijklmnopqrst"), s, 0, 21);
+  test(S("abcdefghijklmnopqrst"), s, 1, 0);
+  test(S("abcdefghijklmnopqrst"), s, 1, 1);
+  test(S("abcdefghijklmnopqrst"), s, 1, 2);
+  test(S("abcdefghijklmnopqrst"), s, 1, 9);
+  test(S("abcdefghijklmnopqrst"), s, 1, 18);
+  test(S("abcdefghijklmnopqrst"), s, 1, 19);
+  test(S("abcdefghijklmnopqrst"), s, 1, 20);
+  test(S("abcdefghijklmnopqrst"), s, 2, 0);
+  test(S("abcdefghijklmnopqrst"), s, 2, 1);
+  test(S("abcdefghijklmnopqrst"), s, 2, 2);
+  test(S("abcdefghijklmnopqrst"), s, 2, 9);
+  test(S("abcdefghijklmnopqrst"), s, 2, 17);
+  test(S("abcdefghijklmnopqrst"), s, 2, 18);
+  test(S("abcdefghijklmnopqrst"), s, 2, 19);
+  test(S("abcdefghijklmnopqrst"), s, 10, 0);
+  test(S("abcdefghijklmnopqrst"), s, 10, 1);
+  test(S("abcdefghijklmnopqrst"), s, 10, 2);
+  test(S("abcdefghijklmnopqrst"), s, 10, 5);
+  test(S("abcdefghijklmnopqrst"), s, 10, 9);
+  test(S("abcdefghijklmnopqrst"), s, 10, 10);
+  test(S("abcdefghijklmnopqrst"), s, 10, 11);
+  test(S("abcdefghijklmnopqrst"), s, 19, 0);
+  test(S("abcdefghijklmnopqrst"), s, 19, 1);
+  test(S("abcdefghijklmnopqrst"), s, 19, 2);
+  test(S("abcdefghijklmnopqrst"), s, 20, 0);
+  test(S("abcdefghijklmnopqrst"), s, 20, 1);
+  test(S("abcdefghijklmnopqrst"), s, 21, 0);
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    char s[50];
-    test(S(""), s, 0, 0);
-    test(S(""), s, 0, 1);
-    test(S(""), s, 1, 0);
-    test(S("abcde"), s, 0, 0);
-    test(S("abcde"), s, 0, 1);
-    test(S("abcde"), s, 0, 2);
-    test(S("abcde"), s, 0, 4);
-    test(S("abcde"), s, 0, 5);
-    test(S("abcde"), s, 0, 6);
-    test(S("abcde"), s, 1, 0);
-    test(S("abcde"), s, 1, 1);
-    test(S("abcde"), s, 1, 2);
-    test(S("abcde"), s, 1, 4);
-    test(S("abcde"), s, 1, 5);
-    test(S("abcde"), s, 2, 0);
-    test(S("abcde"), s, 2, 1);
-    test(S("abcde"), s, 2, 2);
-    test(S("abcde"), s, 2, 4);
-    test(S("abcde"), s, 4, 0);
-    test(S("abcde"), s, 4, 1);
-    test(S("abcde"), s, 4, 2);
-    test(S("abcde"), s, 5, 0);
-    test(S("abcde"), s, 5, 1);
-    test(S("abcde"), s, 6, 0);
-    test(S("abcdefghijklmnopqrst"), s, 0, 0);
-    test(S("abcdefghijklmnopqrst"), s, 0, 1);
-    test(S("abcdefghijklmnopqrst"), s, 0, 2);
-    test(S("abcdefghijklmnopqrst"), s, 0, 10);
-    test(S("abcdefghijklmnopqrst"), s, 0, 19);
-    test(S("abcdefghijklmnopqrst"), s, 0, 20);
-    test(S("abcdefghijklmnopqrst"), s, 0, 21);
-    test(S("abcdefghijklmnopqrst"), s, 1, 0);
-    test(S("abcdefghijklmnopqrst"), s, 1, 1);
-    test(S("abcdefghijklmnopqrst"), s, 1, 2);
-    test(S("abcdefghijklmnopqrst"), s, 1, 9);
-    test(S("abcdefghijklmnopqrst"), s, 1, 18);
-    test(S("abcdefghijklmnopqrst"), s, 1, 19);
-    test(S("abcdefghijklmnopqrst"), s, 1, 20);
-    test(S("abcdefghijklmnopqrst"), s, 2, 0);
-    test(S("abcdefghijklmnopqrst"), s, 2, 1);
-    test(S("abcdefghijklmnopqrst"), s, 2, 2);
-    test(S("abcdefghijklmnopqrst"), s, 2, 9);
-    test(S("abcdefghijklmnopqrst"), s, 2, 17);
-    test(S("abcdefghijklmnopqrst"), s, 2, 18);
-    test(S("abcdefghijklmnopqrst"), s, 2, 19);
-    test(S("abcdefghijklmnopqrst"), s, 10, 0);
-    test(S("abcdefghijklmnopqrst"), s, 10, 1);
-    test(S("abcdefghijklmnopqrst"), s, 10, 2);
-    test(S("abcdefghijklmnopqrst"), s, 10, 5);
-    test(S("abcdefghijklmnopqrst"), s, 10, 9);
-    test(S("abcdefghijklmnopqrst"), s, 10, 10);
-    test(S("abcdefghijklmnopqrst"), s, 10, 11);
-    test(S("abcdefghijklmnopqrst"), s, 19, 0);
-    test(S("abcdefghijklmnopqrst"), s, 19, 1);
-    test(S("abcdefghijklmnopqrst"), s, 19, 2);
-    test(S("abcdefghijklmnopqrst"), s, 20, 0);
-    test(S("abcdefghijklmnopqrst"), s, 20, 1);
-    test(S("abcdefghijklmnopqrst"), s, 21, 0);
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    char s[50];
-    test(S(""), s, 0, 0);
-    test(S(""), s, 0, 1);
-    test(S(""), s, 1, 0);
-    test(S("abcde"), s, 0, 0);
-    test(S("abcde"), s, 0, 1);
-    test(S("abcde"), s, 0, 2);
-    test(S("abcde"), s, 0, 4);
-    test(S("abcde"), s, 0, 5);
-    test(S("abcde"), s, 0, 6);
-    test(S("abcde"), s, 1, 0);
-    test(S("abcde"), s, 1, 1);
-    test(S("abcde"), s, 1, 2);
-    test(S("abcde"), s, 1, 4);
-    test(S("abcde"), s, 1, 5);
-    test(S("abcde"), s, 2, 0);
-    test(S("abcde"), s, 2, 1);
-    test(S("abcde"), s, 2, 2);
-    test(S("abcde"), s, 2, 4);
-    test(S("abcde"), s, 4, 0);
-    test(S("abcde"), s, 4, 1);
-    test(S("abcde"), s, 4, 2);
-    test(S("abcde"), s, 5, 0);
-    test(S("abcde"), s, 5, 1);
-    test(S("abcde"), s, 6, 0);
-    test(S("abcdefghijklmnopqrst"), s, 0, 0);
-    test(S("abcdefghijklmnopqrst"), s, 0, 1);
-    test(S("abcdefghijklmnopqrst"), s, 0, 2);
-    test(S("abcdefghijklmnopqrst"), s, 0, 10);
-    test(S("abcdefghijklmnopqrst"), s, 0, 19);
-    test(S("abcdefghijklmnopqrst"), s, 0, 20);
-    test(S("abcdefghijklmnopqrst"), s, 0, 21);
-    test(S("abcdefghijklmnopqrst"), s, 1, 0);
-    test(S("abcdefghijklmnopqrst"), s, 1, 1);
-    test(S("abcdefghijklmnopqrst"), s, 1, 2);
-    test(S("abcdefghijklmnopqrst"), s, 1, 9);
-    test(S("abcdefghijklmnopqrst"), s, 1, 18);
-    test(S("abcdefghijklmnopqrst"), s, 1, 19);
-    test(S("abcdefghijklmnopqrst"), s, 1, 20);
-    test(S("abcdefghijklmnopqrst"), s, 2, 0);
-    test(S("abcdefghijklmnopqrst"), s, 2, 1);
-    test(S("abcdefghijklmnopqrst"), s, 2, 2);
-    test(S("abcdefghijklmnopqrst"), s, 2, 9);
-    test(S("abcdefghijklmnopqrst"), s, 2, 17);
-    test(S("abcdefghijklmnopqrst"), s, 2, 18);
-    test(S("abcdefghijklmnopqrst"), s, 2, 19);
-    test(S("abcdefghijklmnopqrst"), s, 10, 0);
-    test(S("abcdefghijklmnopqrst"), s, 10, 1);
-    test(S("abcdefghijklmnopqrst"), s, 10, 2);
-    test(S("abcdefghijklmnopqrst"), s, 10, 5);
-    test(S("abcdefghijklmnopqrst"), s, 10, 9);
-    test(S("abcdefghijklmnopqrst"), s, 10, 10);
-    test(S("abcdefghijklmnopqrst"), s, 10, 11);
-    test(S("abcdefghijklmnopqrst"), s, 19, 0);
-    test(S("abcdefghijklmnopqrst"), s, 19, 1);
-    test(S("abcdefghijklmnopqrst"), s, 19, 2);
-    test(S("abcdefghijklmnopqrst"), s, 20, 0);
-    test(S("abcdefghijklmnopqrst"), s, 20, 1);
-    test(S("abcdefghijklmnopqrst"), s, 21, 0);
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter.pass.cpp
index 08eddaeea4b9c..dde2e65a2cc5e 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter.pass.cpp
@@ -28,38 +28,26 @@ test(S s, typename S::
diff erence_type pos, S expected)
     assert(i - s.begin() == pos);
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S("abcde"), 0, S("bcde"));
+  test(S("abcde"), 1, S("acde"));
+  test(S("abcde"), 2, S("abde"));
+  test(S("abcde"), 4, S("abcd"));
+  test(S("abcdefghij"), 0, S("bcdefghij"));
+  test(S("abcdefghij"), 1, S("acdefghij"));
+  test(S("abcdefghij"), 5, S("abcdeghij"));
+  test(S("abcdefghij"), 9, S("abcdefghi"));
+  test(S("abcdefghijklmnopqrst"), 0, S("bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, S("acdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, S("abcdefghijlmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S("abcde"), 0, S("bcde"));
-    test(S("abcde"), 1, S("acde"));
-    test(S("abcde"), 2, S("abde"));
-    test(S("abcde"), 4, S("abcd"));
-    test(S("abcdefghij"), 0, S("bcdefghij"));
-    test(S("abcdefghij"), 1, S("acdefghij"));
-    test(S("abcdefghij"), 5, S("abcdeghij"));
-    test(S("abcdefghij"), 9, S("abcdefghi"));
-    test(S("abcdefghijklmnopqrst"), 0, S("bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, S("acdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, S("abcdefghijlmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S("abcde"), 0, S("bcde"));
-    test(S("abcde"), 1, S("acde"));
-    test(S("abcde"), 2, S("abde"));
-    test(S("abcde"), 4, S("abcd"));
-    test(S("abcdefghij"), 0, S("bcdefghij"));
-    test(S("abcdefghij"), 1, S("acdefghij"));
-    test(S("abcdefghij"), 5, S("abcdeghij"));
-    test(S("abcdefghij"), 9, S("abcdefghi"));
-    test(S("abcdefghijklmnopqrst"), 0, S("bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, S("acdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, S("abcdefghijlmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter_iter.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter_iter.pass.cpp
index 6aa08304b0648..7976ab3b8ffda 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter_iter.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/iter_iter.pass.cpp
@@ -29,122 +29,68 @@ test(S s, typename S::
diff erence_type pos, typename S::
diff erence_type n, S expe
     assert(i - s.begin() == pos);
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(""), 0, 0, S(""));
+  test(S("abcde"), 0, 0, S("abcde"));
+  test(S("abcde"), 0, 1, S("bcde"));
+  test(S("abcde"), 0, 2, S("cde"));
+  test(S("abcde"), 0, 4, S("e"));
+  test(S("abcde"), 0, 5, S(""));
+  test(S("abcde"), 1, 0, S("abcde"));
+  test(S("abcde"), 1, 1, S("acde"));
+  test(S("abcde"), 1, 2, S("ade"));
+  test(S("abcde"), 1, 3, S("ae"));
+  test(S("abcde"), 1, 4, S("a"));
+  test(S("abcde"), 2, 0, S("abcde"));
+  test(S("abcde"), 2, 1, S("abde"));
+  test(S("abcde"), 2, 2, S("abe"));
+  test(S("abcde"), 2, 3, S("ab"));
+  test(S("abcde"), 4, 0, S("abcde"));
+  test(S("abcde"), 4, 1, S("abcd"));
+  test(S("abcde"), 5, 0, S("abcde"));
+  test(S("abcdefghij"), 0, 0, S("abcdefghij"));
+  test(S("abcdefghij"), 0, 1, S("bcdefghij"));
+  test(S("abcdefghij"), 0, 5, S("fghij"));
+  test(S("abcdefghij"), 0, 9, S("j"));
+  test(S("abcdefghij"), 0, 10, S(""));
+  test(S("abcdefghij"), 1, 0, S("abcdefghij"));
+  test(S("abcdefghij"), 1, 1, S("acdefghij"));
+  test(S("abcdefghij"), 1, 4, S("afghij"));
+  test(S("abcdefghij"), 1, 8, S("aj"));
+  test(S("abcdefghij"), 1, 9, S("a"));
+  test(S("abcdefghij"), 5, 0, S("abcdefghij"));
+  test(S("abcdefghij"), 5, 1, S("abcdeghij"));
+  test(S("abcdefghij"), 5, 2, S("abcdehij"));
+  test(S("abcdefghij"), 5, 4, S("abcdej"));
+  test(S("abcdefghij"), 5, 5, S("abcde"));
+  test(S("abcdefghij"), 9, 0, S("abcdefghij"));
+  test(S("abcdefghij"), 9, 1, S("abcdefghi"));
+  test(S("abcdefghij"), 10, 0, S("abcdefghij"));
+  test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, 1, S("bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, 10, S("klmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, 19, S("t"));
+  test(S("abcdefghijklmnopqrst"), 0, 20, S(""));
+  test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, 1, S("acdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, 9, S("aklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, 18, S("at"));
+  test(S("abcdefghijklmnopqrst"), 1, 19, S("a"));
+  test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijlmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijpqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijt"));
+  test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"));
+  test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrs"));
+  test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(""), 0, 0, S(""));
-    test(S("abcde"), 0, 0, S("abcde"));
-    test(S("abcde"), 0, 1, S("bcde"));
-    test(S("abcde"), 0, 2, S("cde"));
-    test(S("abcde"), 0, 4, S("e"));
-    test(S("abcde"), 0, 5, S(""));
-    test(S("abcde"), 1, 0, S("abcde"));
-    test(S("abcde"), 1, 1, S("acde"));
-    test(S("abcde"), 1, 2, S("ade"));
-    test(S("abcde"), 1, 3, S("ae"));
-    test(S("abcde"), 1, 4, S("a"));
-    test(S("abcde"), 2, 0, S("abcde"));
-    test(S("abcde"), 2, 1, S("abde"));
-    test(S("abcde"), 2, 2, S("abe"));
-    test(S("abcde"), 2, 3, S("ab"));
-    test(S("abcde"), 4, 0, S("abcde"));
-    test(S("abcde"), 4, 1, S("abcd"));
-    test(S("abcde"), 5, 0, S("abcde"));
-    test(S("abcdefghij"), 0, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 0, 1, S("bcdefghij"));
-    test(S("abcdefghij"), 0, 5, S("fghij"));
-    test(S("abcdefghij"), 0, 9, S("j"));
-    test(S("abcdefghij"), 0, 10, S(""));
-    test(S("abcdefghij"), 1, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 1, 1, S("acdefghij"));
-    test(S("abcdefghij"), 1, 4, S("afghij"));
-    test(S("abcdefghij"), 1, 8, S("aj"));
-    test(S("abcdefghij"), 1, 9, S("a"));
-    test(S("abcdefghij"), 5, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 5, 1, S("abcdeghij"));
-    test(S("abcdefghij"), 5, 2, S("abcdehij"));
-    test(S("abcdefghij"), 5, 4, S("abcdej"));
-    test(S("abcdefghij"), 5, 5, S("abcde"));
-    test(S("abcdefghij"), 9, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 9, 1, S("abcdefghi"));
-    test(S("abcdefghij"), 10, 0, S("abcdefghij"));
-    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 1, S("bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 10, S("klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 19, S("t"));
-    test(S("abcdefghijklmnopqrst"), 0, 20, S(""));
-    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 1, S("acdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 9, S("aklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 18, S("at"));
-    test(S("abcdefghijklmnopqrst"), 1, 19, S("a"));
-    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijlmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijpqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijt"));
-    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"));
-    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrs"));
-    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(""), 0, 0, S(""));
-    test(S("abcde"), 0, 0, S("abcde"));
-    test(S("abcde"), 0, 1, S("bcde"));
-    test(S("abcde"), 0, 2, S("cde"));
-    test(S("abcde"), 0, 4, S("e"));
-    test(S("abcde"), 0, 5, S(""));
-    test(S("abcde"), 1, 0, S("abcde"));
-    test(S("abcde"), 1, 1, S("acde"));
-    test(S("abcde"), 1, 2, S("ade"));
-    test(S("abcde"), 1, 3, S("ae"));
-    test(S("abcde"), 1, 4, S("a"));
-    test(S("abcde"), 2, 0, S("abcde"));
-    test(S("abcde"), 2, 1, S("abde"));
-    test(S("abcde"), 2, 2, S("abe"));
-    test(S("abcde"), 2, 3, S("ab"));
-    test(S("abcde"), 4, 0, S("abcde"));
-    test(S("abcde"), 4, 1, S("abcd"));
-    test(S("abcde"), 5, 0, S("abcde"));
-    test(S("abcdefghij"), 0, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 0, 1, S("bcdefghij"));
-    test(S("abcdefghij"), 0, 5, S("fghij"));
-    test(S("abcdefghij"), 0, 9, S("j"));
-    test(S("abcdefghij"), 0, 10, S(""));
-    test(S("abcdefghij"), 1, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 1, 1, S("acdefghij"));
-    test(S("abcdefghij"), 1, 4, S("afghij"));
-    test(S("abcdefghij"), 1, 8, S("aj"));
-    test(S("abcdefghij"), 1, 9, S("a"));
-    test(S("abcdefghij"), 5, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 5, 1, S("abcdeghij"));
-    test(S("abcdefghij"), 5, 2, S("abcdehij"));
-    test(S("abcdefghij"), 5, 4, S("abcdej"));
-    test(S("abcdefghij"), 5, 5, S("abcde"));
-    test(S("abcdefghij"), 9, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 9, 1, S("abcdefghi"));
-    test(S("abcdefghij"), 10, 0, S("abcdefghij"));
-    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 1, S("bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 10, S("klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 19, S("t"));
-    test(S("abcdefghijklmnopqrst"), 0, 20, S(""));
-    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 1, S("acdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 9, S("aklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 18, S("at"));
-    test(S("abcdefghijklmnopqrst"), 1, 19, S("a"));
-    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijlmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijpqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijt"));
-    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"));
-    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrs"));
-    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp
index 7379ab9194f2e..28c8d0572b762 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp
@@ -26,20 +26,17 @@ test(S s, S expected)
     assert(s == expected);
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S("abcde"), S("abcd"));
+  test(S("abcdefghij"), S("abcdefghi"));
+  test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrs"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S("abcde"), S("abcd"));
-    test(S("abcdefghij"), S("abcdefghi"));
-    test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrs"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S("abcde"), S("abcd"));
-    test(S("abcdefghij"), S("abcdefghi"));
-    test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrs"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
index e673e74b27eda..28b650740a105 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
@@ -88,214 +88,114 @@ test(S s, S expected)
     assert(s == expected);
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(""), 0, 0, S(""));
-    test(S(""), 0, 1, S(""));
-    test(S(""), 1, 0, S("can't happen"));
-    test(S("abcde"), 0, 0, S("abcde"));
-    test(S("abcde"), 0, 1, S("bcde"));
-    test(S("abcde"), 0, 2, S("cde"));
-    test(S("abcde"), 0, 4, S("e"));
-    test(S("abcde"), 0, 5, S(""));
-    test(S("abcde"), 0, 6, S(""));
-    test(S("abcde"), 1, 0, S("abcde"));
-    test(S("abcde"), 1, 1, S("acde"));
-    test(S("abcde"), 1, 2, S("ade"));
-    test(S("abcde"), 1, 3, S("ae"));
-    test(S("abcde"), 1, 4, S("a"));
-    test(S("abcde"), 1, 5, S("a"));
-    test(S("abcde"), 2, 0, S("abcde"));
-    test(S("abcde"), 2, 1, S("abde"));
-    test(S("abcde"), 2, 2, S("abe"));
-    test(S("abcde"), 2, 3, S("ab"));
-    test(S("abcde"), 2, 4, S("ab"));
-    test(S("abcde"), 4, 0, S("abcde"));
-    test(S("abcde"), 4, 1, S("abcd"));
-    test(S("abcde"), 4, 2, S("abcd"));
-    test(S("abcde"), 5, 0, S("abcde"));
-    test(S("abcde"), 5, 1, S("abcde"));
-    test(S("abcde"), 6, 0, S("can't happen"));
-    test(S("abcdefghij"), 0, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 0, 1, S("bcdefghij"));
-    test(S("abcdefghij"), 0, 5, S("fghij"));
-    test(S("abcdefghij"), 0, 9, S("j"));
-    test(S("abcdefghij"), 0, 10, S(""));
-    test(S("abcdefghij"), 0, 11, S(""));
-    test(S("abcdefghij"), 1, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 1, 1, S("acdefghij"));
-    test(S("abcdefghij"), 1, 4, S("afghij"));
-    test(S("abcdefghij"), 1, 8, S("aj"));
-    test(S("abcdefghij"), 1, 9, S("a"));
-    test(S("abcdefghij"), 1, 10, S("a"));
-    test(S("abcdefghij"), 5, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 5, 1, S("abcdeghij"));
-    test(S("abcdefghij"), 5, 2, S("abcdehij"));
-    test(S("abcdefghij"), 5, 4, S("abcdej"));
-    test(S("abcdefghij"), 5, 5, S("abcde"));
-    test(S("abcdefghij"), 5, 6, S("abcde"));
-    test(S("abcdefghij"), 9, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 9, 1, S("abcdefghi"));
-    test(S("abcdefghij"), 9, 2, S("abcdefghi"));
-    test(S("abcdefghij"), 10, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 10, 1, S("abcdefghij"));
-    test(S("abcdefghij"), 11, 0, S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 1, S("bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 10, S("klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 19, S("t"));
-    test(S("abcdefghijklmnopqrst"), 0, 20, S(""));
-    test(S("abcdefghijklmnopqrst"), 0, 21, S(""));
-    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 1, S("acdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 9, S("aklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 18, S("at"));
-    test(S("abcdefghijklmnopqrst"), 1, 19, S("a"));
-    test(S("abcdefghijklmnopqrst"), 1, 20, S("a"));
-    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijlmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijpqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijt"));
-    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"));
-    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"));
-    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrs"));
-    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrs"));
-    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 21, 0, S("can't happen"));
-
-    test(S(""), 0, S(""));
-    test(S(""), 1, S("can't happen"));
-    test(S("abcde"), 0, S(""));
-    test(S("abcde"), 1, S("a"));
-    test(S("abcde"), 2, S("ab"));
-    test(S("abcde"), 4, S("abcd"));
-    test(S("abcde"), 5, S("abcde"));
-    test(S("abcde"), 6, S("can't happen"));
-    test(S("abcdefghij"), 0, S(""));
-    test(S("abcdefghij"), 1, S("a"));
-    test(S("abcdefghij"), 5, S("abcde"));
-    test(S("abcdefghij"), 9, S("abcdefghi"));
-    test(S("abcdefghij"), 10, S("abcdefghij"));
-    test(S("abcdefghij"), 11, S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 0, S(""));
-    test(S("abcdefghijklmnopqrst"), 1, S("a"));
-    test(S("abcdefghijklmnopqrst"), 10, S("abcdefghij"));
-    test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs"));
-    test(S("abcdefghijklmnopqrst"), 20, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 21, S("can't happen"));
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(""), 0, 0, S(""));
+  test(S(""), 0, 1, S(""));
+  test(S(""), 1, 0, S("can't happen"));
+  test(S("abcde"), 0, 0, S("abcde"));
+  test(S("abcde"), 0, 1, S("bcde"));
+  test(S("abcde"), 0, 2, S("cde"));
+  test(S("abcde"), 0, 4, S("e"));
+  test(S("abcde"), 0, 5, S(""));
+  test(S("abcde"), 0, 6, S(""));
+  test(S("abcde"), 1, 0, S("abcde"));
+  test(S("abcde"), 1, 1, S("acde"));
+  test(S("abcde"), 1, 2, S("ade"));
+  test(S("abcde"), 1, 3, S("ae"));
+  test(S("abcde"), 1, 4, S("a"));
+  test(S("abcde"), 1, 5, S("a"));
+  test(S("abcde"), 2, 0, S("abcde"));
+  test(S("abcde"), 2, 1, S("abde"));
+  test(S("abcde"), 2, 2, S("abe"));
+  test(S("abcde"), 2, 3, S("ab"));
+  test(S("abcde"), 2, 4, S("ab"));
+  test(S("abcde"), 4, 0, S("abcde"));
+  test(S("abcde"), 4, 1, S("abcd"));
+  test(S("abcde"), 4, 2, S("abcd"));
+  test(S("abcde"), 5, 0, S("abcde"));
+  test(S("abcde"), 5, 1, S("abcde"));
+  test(S("abcde"), 6, 0, S("can't happen"));
+  test(S("abcdefghij"), 0, 0, S("abcdefghij"));
+  test(S("abcdefghij"), 0, 1, S("bcdefghij"));
+  test(S("abcdefghij"), 0, 5, S("fghij"));
+  test(S("abcdefghij"), 0, 9, S("j"));
+  test(S("abcdefghij"), 0, 10, S(""));
+  test(S("abcdefghij"), 0, 11, S(""));
+  test(S("abcdefghij"), 1, 0, S("abcdefghij"));
+  test(S("abcdefghij"), 1, 1, S("acdefghij"));
+  test(S("abcdefghij"), 1, 4, S("afghij"));
+  test(S("abcdefghij"), 1, 8, S("aj"));
+  test(S("abcdefghij"), 1, 9, S("a"));
+  test(S("abcdefghij"), 1, 10, S("a"));
+  test(S("abcdefghij"), 5, 0, S("abcdefghij"));
+  test(S("abcdefghij"), 5, 1, S("abcdeghij"));
+  test(S("abcdefghij"), 5, 2, S("abcdehij"));
+  test(S("abcdefghij"), 5, 4, S("abcdej"));
+  test(S("abcdefghij"), 5, 5, S("abcde"));
+  test(S("abcdefghij"), 5, 6, S("abcde"));
+  test(S("abcdefghij"), 9, 0, S("abcdefghij"));
+  test(S("abcdefghij"), 9, 1, S("abcdefghi"));
+  test(S("abcdefghij"), 9, 2, S("abcdefghi"));
+  test(S("abcdefghij"), 10, 0, S("abcdefghij"));
+  test(S("abcdefghij"), 10, 1, S("abcdefghij"));
+  test(S("abcdefghij"), 11, 0, S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, 1, S("bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, 10, S("klmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, 19, S("t"));
+  test(S("abcdefghijklmnopqrst"), 0, 20, S(""));
+  test(S("abcdefghijklmnopqrst"), 0, 21, S(""));
+  test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, 1, S("acdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, 9, S("aklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, 18, S("at"));
+  test(S("abcdefghijklmnopqrst"), 1, 19, S("a"));
+  test(S("abcdefghijklmnopqrst"), 1, 20, S("a"));
+  test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijlmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijpqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijt"));
+  test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"));
+  test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"));
+  test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrs"));
+  test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrs"));
+  test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 21, 0, S("can't happen"));
 
-    test(S(""), S(""));
-    test(S("abcde"), S(""));
-    test(S("abcdefghij"), S(""));
-    test(S("abcdefghijklmnopqrst"), S(""));
-  }
-#if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(""), 0, 0, S(""));
-    test(S(""), 0, 1, S(""));
-    test(S(""), 1, 0, S("can't happen"));
-    test(S("abcde"), 0, 0, S("abcde"));
-    test(S("abcde"), 0, 1, S("bcde"));
-    test(S("abcde"), 0, 2, S("cde"));
-    test(S("abcde"), 0, 4, S("e"));
-    test(S("abcde"), 0, 5, S(""));
-    test(S("abcde"), 0, 6, S(""));
-    test(S("abcde"), 1, 0, S("abcde"));
-    test(S("abcde"), 1, 1, S("acde"));
-    test(S("abcde"), 1, 2, S("ade"));
-    test(S("abcde"), 1, 3, S("ae"));
-    test(S("abcde"), 1, 4, S("a"));
-    test(S("abcde"), 1, 5, S("a"));
-    test(S("abcde"), 2, 0, S("abcde"));
-    test(S("abcde"), 2, 1, S("abde"));
-    test(S("abcde"), 2, 2, S("abe"));
-    test(S("abcde"), 2, 3, S("ab"));
-    test(S("abcde"), 2, 4, S("ab"));
-    test(S("abcde"), 4, 0, S("abcde"));
-    test(S("abcde"), 4, 1, S("abcd"));
-    test(S("abcde"), 4, 2, S("abcd"));
-    test(S("abcde"), 5, 0, S("abcde"));
-    test(S("abcde"), 5, 1, S("abcde"));
-    test(S("abcde"), 6, 0, S("can't happen"));
-    test(S("abcdefghij"), 0, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 0, 1, S("bcdefghij"));
-    test(S("abcdefghij"), 0, 5, S("fghij"));
-    test(S("abcdefghij"), 0, 9, S("j"));
-    test(S("abcdefghij"), 0, 10, S(""));
-    test(S("abcdefghij"), 0, 11, S(""));
-    test(S("abcdefghij"), 1, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 1, 1, S("acdefghij"));
-    test(S("abcdefghij"), 1, 4, S("afghij"));
-    test(S("abcdefghij"), 1, 8, S("aj"));
-    test(S("abcdefghij"), 1, 9, S("a"));
-    test(S("abcdefghij"), 1, 10, S("a"));
-    test(S("abcdefghij"), 5, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 5, 1, S("abcdeghij"));
-    test(S("abcdefghij"), 5, 2, S("abcdehij"));
-    test(S("abcdefghij"), 5, 4, S("abcdej"));
-    test(S("abcdefghij"), 5, 5, S("abcde"));
-    test(S("abcdefghij"), 5, 6, S("abcde"));
-    test(S("abcdefghij"), 9, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 9, 1, S("abcdefghi"));
-    test(S("abcdefghij"), 9, 2, S("abcdefghi"));
-    test(S("abcdefghij"), 10, 0, S("abcdefghij"));
-    test(S("abcdefghij"), 10, 1, S("abcdefghij"));
-    test(S("abcdefghij"), 11, 0, S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 1, S("bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 10, S("klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 19, S("t"));
-    test(S("abcdefghijklmnopqrst"), 0, 20, S(""));
-    test(S("abcdefghijklmnopqrst"), 0, 21, S(""));
-    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 1, S("acdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 9, S("aklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 18, S("at"));
-    test(S("abcdefghijklmnopqrst"), 1, 19, S("a"));
-    test(S("abcdefghijklmnopqrst"), 1, 20, S("a"));
-    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijlmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijpqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijt"));
-    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"));
-    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"));
-    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrs"));
-    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrs"));
-    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 21, 0, S("can't happen"));
+  test(S(""), 0, S(""));
+  test(S(""), 1, S("can't happen"));
+  test(S("abcde"), 0, S(""));
+  test(S("abcde"), 1, S("a"));
+  test(S("abcde"), 2, S("ab"));
+  test(S("abcde"), 4, S("abcd"));
+  test(S("abcde"), 5, S("abcde"));
+  test(S("abcde"), 6, S("can't happen"));
+  test(S("abcdefghij"), 0, S(""));
+  test(S("abcdefghij"), 1, S("a"));
+  test(S("abcdefghij"), 5, S("abcde"));
+  test(S("abcdefghij"), 9, S("abcdefghi"));
+  test(S("abcdefghij"), 10, S("abcdefghij"));
+  test(S("abcdefghij"), 11, S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 0, S(""));
+  test(S("abcdefghijklmnopqrst"), 1, S("a"));
+  test(S("abcdefghijklmnopqrst"), 10, S("abcdefghij"));
+  test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs"));
+  test(S("abcdefghijklmnopqrst"), 20, S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 21, S("can't happen"));
 
-    test(S(""), 0, S(""));
-    test(S(""), 1, S("can't happen"));
-    test(S("abcde"), 0, S(""));
-    test(S("abcde"), 1, S("a"));
-    test(S("abcde"), 2, S("ab"));
-    test(S("abcde"), 4, S("abcd"));
-    test(S("abcde"), 5, S("abcde"));
-    test(S("abcde"), 6, S("can't happen"));
-    test(S("abcdefghij"), 0, S(""));
-    test(S("abcdefghij"), 1, S("a"));
-    test(S("abcdefghij"), 5, S("abcde"));
-    test(S("abcdefghij"), 9, S("abcdefghi"));
-    test(S("abcdefghij"), 10, S("abcdefghij"));
-    test(S("abcdefghij"), 11, S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 0, S(""));
-    test(S("abcdefghijklmnopqrst"), 1, S("a"));
-    test(S("abcdefghijklmnopqrst"), 10, S("abcdefghij"));
-    test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs"));
-    test(S("abcdefghijklmnopqrst"), 20, S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 21, S("can't happen"));
+  test(S(""), S(""));
+  test(S("abcde"), S(""));
+  test(S("abcdefghij"), S(""));
+  test(S("abcdefghijklmnopqrst"), S(""));
+}
 
-    test(S(""), S(""));
-    test(S("abcde"), S(""));
-    test(S("abcdefghij"), S(""));
-    test(S("abcdefghijklmnopqrst"), S(""));
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
+#if TEST_STD_VER >= 11
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp
index c360119e31a43..0e5eb1b607006 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp
@@ -32,44 +32,29 @@ test(S& s, typename S::const_iterator p, typename S::value_type c, S expected)
         assert(i == p);
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  S s;
+  test(s, s.begin(), '1', S("1"));
+  test(s, s.begin(), 'a', S("a1"));
+  test(s, s.end(), 'b', S("a1b"));
+  test(s, s.end()-1, 'c', S("a1cb"));
+  test(s, s.end()-2, 'd', S("a1dcb"));
+  test(s, s.end()-3, '2', S("a12dcb"));
+  test(s, s.end()-4, '3', S("a132dcb"));
+  test(s, s.end()-5, '4', S("a1432dcb"));
+  test(s, s.begin()+1, '5', S("a51432dcb"));
+  test(s, s.begin()+2, '6', S("a561432dcb"));
+  test(s, s.begin()+3, '7', S("a5671432dcb"));
+  test(s, s.begin()+4, 'A', S("a567A1432dcb"));
+  test(s, s.begin()+5, 'B', S("a567AB1432dcb"));
+  test(s, s.begin()+6, 'C', S("a567ABC1432dcb"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    S s;
-    test(s, s.begin(), '1', S("1"));
-    test(s, s.begin(), 'a', S("a1"));
-    test(s, s.end(), 'b', S("a1b"));
-    test(s, s.end()-1, 'c', S("a1cb"));
-    test(s, s.end()-2, 'd', S("a1dcb"));
-    test(s, s.end()-3, '2', S("a12dcb"));
-    test(s, s.end()-4, '3', S("a132dcb"));
-    test(s, s.end()-5, '4', S("a1432dcb"));
-    test(s, s.begin()+1, '5', S("a51432dcb"));
-    test(s, s.begin()+2, '6', S("a561432dcb"));
-    test(s, s.begin()+3, '7', S("a5671432dcb"));
-    test(s, s.begin()+4, 'A', S("a567A1432dcb"));
-    test(s, s.begin()+5, 'B', S("a567AB1432dcb"));
-    test(s, s.begin()+6, 'C', S("a567ABC1432dcb"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    S s;
-    test(s, s.begin(), '1', S("1"));
-    test(s, s.begin(), 'a', S("a1"));
-    test(s, s.end(), 'b', S("a1b"));
-    test(s, s.end()-1, 'c', S("a1cb"));
-    test(s, s.end()-2, 'd', S("a1dcb"));
-    test(s, s.end()-3, '2', S("a12dcb"));
-    test(s, s.end()-4, '3', S("a132dcb"));
-    test(s, s.end()-5, '4', S("a1432dcb"));
-    test(s, s.begin()+1, '5', S("a51432dcb"));
-    test(s, s.begin()+2, '6', S("a561432dcb"));
-    test(s, s.begin()+3, '7', S("a5671432dcb"));
-    test(s, s.begin()+4, 'A', S("a567A1432dcb"));
-    test(s, s.begin()+5, 'B', S("a567AB1432dcb"));
-    test(s, s.begin()+6, 'C', S("a567ABC1432dcb"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp
index 07c5094855479..fb32892d10ada 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp
@@ -56,99 +56,58 @@ test_exceptions(S s, typename S::
diff erence_type pos, It first, It last)
 }
 #endif
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+  test(S(), 0, s, s, S());
+  test(S(), 0, s, s+1, S("A"));
+  test(S(), 0, s, s+10, S("ABCDEFGHIJ"));
+  test(S(), 0, s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S("12345"), 0, s, s, S("12345"));
+  test(S("12345"), 1, s, s+1, S("1A2345"));
+  test(S("12345"), 4, s, s+10, S("1234ABCDEFGHIJ5"));
+  test(S("12345"), 5, s, s+52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S("1234567890"), 0, s, s, S("1234567890"));
+  test(S("1234567890"), 1, s, s+1, S("1A234567890"));
+  test(S("1234567890"), 10, s, s+10, S("1234567890ABCDEFGHIJ"));
+  test(S("1234567890"), 8, s, s+52, S("12345678ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz90"));
+
+  test(S("12345678901234567890"), 3, s, s, S("12345678901234567890"));
+  test(S("12345678901234567890"), 3, s, s+1, S("123A45678901234567890"));
+  test(S("12345678901234567890"), 15, s, s+10, S("123456789012345ABCDEFGHIJ67890"));
+  test(S("12345678901234567890"), 20, s, s+52,
+        S("12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S());
+  test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("A"));
+  test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("ABCDEFGHIJ"));
+  test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52), S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S("12345"), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S("12345"));
+  test(S("12345"), 1, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("1A2345"));
+  test(S("12345"), 4, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("1234ABCDEFGHIJ5"));
+  test(S("12345"), 5, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52), S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+  test(S("1234567890"), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S("1234567890"));
+  test(S("1234567890"), 1, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("1A234567890"));
+  test(S("1234567890"), 10, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("1234567890ABCDEFGHIJ"));
+  test(S("1234567890"), 8, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52), S("12345678ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz90"));
+
+  test(S("12345678901234567890"), 3, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S("12345678901234567890"));
+  test(S("12345678901234567890"), 3, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("123A45678901234567890"));
+  test(S("12345678901234567890"), 15, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("123456789012345ABCDEFGHIJ67890"));
+  test(S("12345678901234567890"), 20, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
+        S("12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-    test(S(), 0, s, s, S());
-    test(S(), 0, s, s+1, S("A"));
-    test(S(), 0, s, s+10, S("ABCDEFGHIJ"));
-    test(S(), 0, s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345"), 0, s, s, S("12345"));
-    test(S("12345"), 1, s, s+1, S("1A2345"));
-    test(S("12345"), 4, s, s+10, S("1234ABCDEFGHIJ5"));
-    test(S("12345"), 5, s, s+52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("1234567890"), 0, s, s, S("1234567890"));
-    test(S("1234567890"), 1, s, s+1, S("1A234567890"));
-    test(S("1234567890"), 10, s, s+10, S("1234567890ABCDEFGHIJ"));
-    test(S("1234567890"), 8, s, s+52, S("12345678ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz90"));
-
-    test(S("12345678901234567890"), 3, s, s, S("12345678901234567890"));
-    test(S("12345678901234567890"), 3, s, s+1, S("123A45678901234567890"));
-    test(S("12345678901234567890"), 15, s, s+10, S("123456789012345ABCDEFGHIJ67890"));
-    test(S("12345678901234567890"), 20, s, s+52,
-         S("12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S());
-    test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("A"));
-    test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("ABCDEFGHIJ"));
-    test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52), S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345"), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S("12345"));
-    test(S("12345"), 1, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("1A2345"));
-    test(S("12345"), 4, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("1234ABCDEFGHIJ5"));
-    test(S("12345"), 5, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52), S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("1234567890"), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S("1234567890"));
-    test(S("1234567890"), 1, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("1A234567890"));
-    test(S("1234567890"), 10, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("1234567890ABCDEFGHIJ"));
-    test(S("1234567890"), 8, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52), S("12345678ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz90"));
-
-    test(S("12345678901234567890"), 3, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S("12345678901234567890"));
-    test(S("12345678901234567890"), 3, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("123A45678901234567890"));
-    test(S("12345678901234567890"), 15, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("123456789012345ABCDEFGHIJ67890"));
-    test(S("12345678901234567890"), 20, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-    test(S(), 0, s, s, S());
-    test(S(), 0, s, s+1, S("A"));
-    test(S(), 0, s, s+10, S("ABCDEFGHIJ"));
-    test(S(), 0, s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345"), 0, s, s, S("12345"));
-    test(S("12345"), 1, s, s+1, S("1A2345"));
-    test(S("12345"), 4, s, s+10, S("1234ABCDEFGHIJ5"));
-    test(S("12345"), 5, s, s+52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("1234567890"), 0, s, s, S("1234567890"));
-    test(S("1234567890"), 1, s, s+1, S("1A234567890"));
-    test(S("1234567890"), 10, s, s+10, S("1234567890ABCDEFGHIJ"));
-    test(S("1234567890"), 8, s, s+52, S("12345678ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz90"));
-
-    test(S("12345678901234567890"), 3, s, s, S("12345678901234567890"));
-    test(S("12345678901234567890"), 3, s, s+1, S("123A45678901234567890"));
-    test(S("12345678901234567890"), 15, s, s+10, S("123456789012345ABCDEFGHIJ67890"));
-    test(S("12345678901234567890"), 20, s, s+52,
-         S("12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S());
-    test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("A"));
-    test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("ABCDEFGHIJ"));
-    test(S(), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52), S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("12345"), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S("12345"));
-    test(S("12345"), 1, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("1A2345"));
-    test(S("12345"), 4, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("1234ABCDEFGHIJ5"));
-    test(S("12345"), 5, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52), S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-
-    test(S("1234567890"), 0, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S("1234567890"));
-    test(S("1234567890"), 1, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("1A234567890"));
-    test(S("1234567890"), 10, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("1234567890ABCDEFGHIJ"));
-    test(S("1234567890"), 8, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52), S("12345678ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz90"));
-
-    test(S("12345678901234567890"), 3, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S("12345678901234567890"));
-    test(S("12345678901234567890"), 3, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("123A45678901234567890"));
-    test(S("12345678901234567890"), 15, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), S("123456789012345ABCDEFGHIJ67890"));
-    test(S("12345678901234567890"), 20, cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
-         S("12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
+
 #ifndef TEST_HAS_NO_EXCEPTIONS
   if (!TEST_IS_CONSTANT_EVALUATED) { // test iterator operations that throw
     typedef std::string S;
@@ -230,7 +189,6 @@ TEST_CONSTEXPR_CXX20 bool test() {
     s.insert(s.begin(), MoveIt(It(std::begin(p))), MoveIt(It(std::end(p) - 1)));
     assert(s == "ABCD");
   }
-
   return true;
 }
 

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_size_char.pass.cpp
index d0eec148c0ab3..a79b53445ae03 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_size_char.pass.cpp
@@ -28,142 +28,78 @@ test(S s, typename S::
diff erence_type pos, typename S::size_type n,
     assert(s == expected);
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(""), 0, 0, '1', S(""));
+  test(S(""), 0, 5, '1', S("11111"));
+  test(S(""), 0, 10, '1', S("1111111111"));
+  test(S(""), 0, 20, '1', S("11111111111111111111"));
+  test(S("abcde"), 0, 0, '1', S("abcde"));
+  test(S("abcde"), 0, 5, '1', S("11111abcde"));
+  test(S("abcde"), 0, 10, '1', S("1111111111abcde"));
+  test(S("abcde"), 0, 20, '1', S("11111111111111111111abcde"));
+  test(S("abcde"), 1, 0, '1', S("abcde"));
+  test(S("abcde"), 1, 5, '1', S("a11111bcde"));
+  test(S("abcde"), 1, 10, '1', S("a1111111111bcde"));
+  test(S("abcde"), 1, 20, '1', S("a11111111111111111111bcde"));
+  test(S("abcde"), 2, 0, '1', S("abcde"));
+  test(S("abcde"), 2, 5, '1', S("ab11111cde"));
+  test(S("abcde"), 2, 10, '1', S("ab1111111111cde"));
+  test(S("abcde"), 2, 20, '1', S("ab11111111111111111111cde"));
+  test(S("abcde"), 4, 0, '1', S("abcde"));
+  test(S("abcde"), 4, 5, '1', S("abcd11111e"));
+  test(S("abcde"), 4, 10, '1', S("abcd1111111111e"));
+  test(S("abcde"), 4, 20, '1', S("abcd11111111111111111111e"));
+  test(S("abcde"), 5, 0, '1', S("abcde"));
+  test(S("abcde"), 5, 5, '1', S("abcde11111"));
+  test(S("abcde"), 5, 10, '1', S("abcde1111111111"));
+  test(S("abcde"), 5, 20, '1', S("abcde11111111111111111111"));
+  test(S("abcdefghij"), 0, 0, '1', S("abcdefghij"));
+  test(S("abcdefghij"), 0, 5, '1', S("11111abcdefghij"));
+  test(S("abcdefghij"), 0, 10, '1', S("1111111111abcdefghij"));
+  test(S("abcdefghij"), 0, 20, '1', S("11111111111111111111abcdefghij"));
+  test(S("abcdefghij"), 1, 0, '1', S("abcdefghij"));
+  test(S("abcdefghij"), 1, 5, '1', S("a11111bcdefghij"));
+  test(S("abcdefghij"), 1, 10, '1', S("a1111111111bcdefghij"));
+  test(S("abcdefghij"), 1, 20, '1', S("a11111111111111111111bcdefghij"));
+  test(S("abcdefghij"), 5, 0, '1', S("abcdefghij"));
+  test(S("abcdefghij"), 5, 5, '1', S("abcde11111fghij"));
+  test(S("abcdefghij"), 5, 10, '1', S("abcde1111111111fghij"));
+  test(S("abcdefghij"), 5, 20, '1', S("abcde11111111111111111111fghij"));
+  test(S("abcdefghij"), 9, 0, '1', S("abcdefghij"));
+  test(S("abcdefghij"), 9, 5, '1', S("abcdefghi11111j"));
+  test(S("abcdefghij"), 9, 10, '1', S("abcdefghi1111111111j"));
+  test(S("abcdefghij"), 9, 20, '1', S("abcdefghi11111111111111111111j"));
+  test(S("abcdefghij"), 10, 0, '1', S("abcdefghij"));
+  test(S("abcdefghij"), 10, 5, '1', S("abcdefghij11111"));
+  test(S("abcdefghij"), 10, 10, '1', S("abcdefghij1111111111"));
+  test(S("abcdefghij"), 10, 20, '1', S("abcdefghij11111111111111111111"));
+  test(S("abcdefghijklmnopqrst"), 0, 0, '1', S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, 5, '1', S("11111abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, 10, '1', S("1111111111abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, 20, '1', S("11111111111111111111abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, 0, '1', S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, 5, '1', S("a11111bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, 10, '1', S("a1111111111bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, 20, '1', S("a11111111111111111111bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, 0, '1', S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, 5, '1', S("abcdefghij11111klmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, 10, '1', S("abcdefghij1111111111klmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, 20, '1', S("abcdefghij11111111111111111111klmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 19, 0, '1', S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 19, 5, '1', S("abcdefghijklmnopqrs11111t"));
+  test(S("abcdefghijklmnopqrst"), 19, 10, '1', S("abcdefghijklmnopqrs1111111111t"));
+  test(S("abcdefghijklmnopqrst"), 19, 20, '1', S("abcdefghijklmnopqrs11111111111111111111t"));
+  test(S("abcdefghijklmnopqrst"), 20, 0, '1', S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 20, 5, '1', S("abcdefghijklmnopqrst11111"));
+  test(S("abcdefghijklmnopqrst"), 20, 10, '1', S("abcdefghijklmnopqrst1111111111"));
+  test(S("abcdefghijklmnopqrst"), 20, 20, '1', S("abcdefghijklmnopqrst11111111111111111111"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(""), 0, 0, '1', S(""));
-    test(S(""), 0, 5, '1', S("11111"));
-    test(S(""), 0, 10, '1', S("1111111111"));
-    test(S(""), 0, 20, '1', S("11111111111111111111"));
-    test(S("abcde"), 0, 0, '1', S("abcde"));
-    test(S("abcde"), 0, 5, '1', S("11111abcde"));
-    test(S("abcde"), 0, 10, '1', S("1111111111abcde"));
-    test(S("abcde"), 0, 20, '1', S("11111111111111111111abcde"));
-    test(S("abcde"), 1, 0, '1', S("abcde"));
-    test(S("abcde"), 1, 5, '1', S("a11111bcde"));
-    test(S("abcde"), 1, 10, '1', S("a1111111111bcde"));
-    test(S("abcde"), 1, 20, '1', S("a11111111111111111111bcde"));
-    test(S("abcde"), 2, 0, '1', S("abcde"));
-    test(S("abcde"), 2, 5, '1', S("ab11111cde"));
-    test(S("abcde"), 2, 10, '1', S("ab1111111111cde"));
-    test(S("abcde"), 2, 20, '1', S("ab11111111111111111111cde"));
-    test(S("abcde"), 4, 0, '1', S("abcde"));
-    test(S("abcde"), 4, 5, '1', S("abcd11111e"));
-    test(S("abcde"), 4, 10, '1', S("abcd1111111111e"));
-    test(S("abcde"), 4, 20, '1', S("abcd11111111111111111111e"));
-    test(S("abcde"), 5, 0, '1', S("abcde"));
-    test(S("abcde"), 5, 5, '1', S("abcde11111"));
-    test(S("abcde"), 5, 10, '1', S("abcde1111111111"));
-    test(S("abcde"), 5, 20, '1', S("abcde11111111111111111111"));
-    test(S("abcdefghij"), 0, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 0, 5, '1', S("11111abcdefghij"));
-    test(S("abcdefghij"), 0, 10, '1', S("1111111111abcdefghij"));
-    test(S("abcdefghij"), 0, 20, '1', S("11111111111111111111abcdefghij"));
-    test(S("abcdefghij"), 1, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 1, 5, '1', S("a11111bcdefghij"));
-    test(S("abcdefghij"), 1, 10, '1', S("a1111111111bcdefghij"));
-    test(S("abcdefghij"), 1, 20, '1', S("a11111111111111111111bcdefghij"));
-    test(S("abcdefghij"), 5, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 5, 5, '1', S("abcde11111fghij"));
-    test(S("abcdefghij"), 5, 10, '1', S("abcde1111111111fghij"));
-    test(S("abcdefghij"), 5, 20, '1', S("abcde11111111111111111111fghij"));
-    test(S("abcdefghij"), 9, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 9, 5, '1', S("abcdefghi11111j"));
-    test(S("abcdefghij"), 9, 10, '1', S("abcdefghi1111111111j"));
-    test(S("abcdefghij"), 9, 20, '1', S("abcdefghi11111111111111111111j"));
-    test(S("abcdefghij"), 10, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 10, 5, '1', S("abcdefghij11111"));
-    test(S("abcdefghij"), 10, 10, '1', S("abcdefghij1111111111"));
-    test(S("abcdefghij"), 10, 20, '1', S("abcdefghij11111111111111111111"));
-    test(S("abcdefghijklmnopqrst"), 0, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 5, '1', S("11111abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 10, '1', S("1111111111abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 20, '1', S("11111111111111111111abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 5, '1', S("a11111bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 10, '1', S("a1111111111bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 20, '1', S("a11111111111111111111bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 5, '1', S("abcdefghij11111klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 10, '1', S("abcdefghij1111111111klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 20, '1', S("abcdefghij11111111111111111111klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, 5, '1', S("abcdefghijklmnopqrs11111t"));
-    test(S("abcdefghijklmnopqrst"), 19, 10, '1', S("abcdefghijklmnopqrs1111111111t"));
-    test(S("abcdefghijklmnopqrst"), 19, 20, '1', S("abcdefghijklmnopqrs11111111111111111111t"));
-    test(S("abcdefghijklmnopqrst"), 20, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 20, 5, '1', S("abcdefghijklmnopqrst11111"));
-    test(S("abcdefghijklmnopqrst"), 20, 10, '1', S("abcdefghijklmnopqrst1111111111"));
-    test(S("abcdefghijklmnopqrst"), 20, 20, '1', S("abcdefghijklmnopqrst11111111111111111111"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(""), 0, 0, '1', S(""));
-    test(S(""), 0, 5, '1', S("11111"));
-    test(S(""), 0, 10, '1', S("1111111111"));
-    test(S(""), 0, 20, '1', S("11111111111111111111"));
-    test(S("abcde"), 0, 0, '1', S("abcde"));
-    test(S("abcde"), 0, 5, '1', S("11111abcde"));
-    test(S("abcde"), 0, 10, '1', S("1111111111abcde"));
-    test(S("abcde"), 0, 20, '1', S("11111111111111111111abcde"));
-    test(S("abcde"), 1, 0, '1', S("abcde"));
-    test(S("abcde"), 1, 5, '1', S("a11111bcde"));
-    test(S("abcde"), 1, 10, '1', S("a1111111111bcde"));
-    test(S("abcde"), 1, 20, '1', S("a11111111111111111111bcde"));
-    test(S("abcde"), 2, 0, '1', S("abcde"));
-    test(S("abcde"), 2, 5, '1', S("ab11111cde"));
-    test(S("abcde"), 2, 10, '1', S("ab1111111111cde"));
-    test(S("abcde"), 2, 20, '1', S("ab11111111111111111111cde"));
-    test(S("abcde"), 4, 0, '1', S("abcde"));
-    test(S("abcde"), 4, 5, '1', S("abcd11111e"));
-    test(S("abcde"), 4, 10, '1', S("abcd1111111111e"));
-    test(S("abcde"), 4, 20, '1', S("abcd11111111111111111111e"));
-    test(S("abcde"), 5, 0, '1', S("abcde"));
-    test(S("abcde"), 5, 5, '1', S("abcde11111"));
-    test(S("abcde"), 5, 10, '1', S("abcde1111111111"));
-    test(S("abcde"), 5, 20, '1', S("abcde11111111111111111111"));
-    test(S("abcdefghij"), 0, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 0, 5, '1', S("11111abcdefghij"));
-    test(S("abcdefghij"), 0, 10, '1', S("1111111111abcdefghij"));
-    test(S("abcdefghij"), 0, 20, '1', S("11111111111111111111abcdefghij"));
-    test(S("abcdefghij"), 1, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 1, 5, '1', S("a11111bcdefghij"));
-    test(S("abcdefghij"), 1, 10, '1', S("a1111111111bcdefghij"));
-    test(S("abcdefghij"), 1, 20, '1', S("a11111111111111111111bcdefghij"));
-    test(S("abcdefghij"), 5, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 5, 5, '1', S("abcde11111fghij"));
-    test(S("abcdefghij"), 5, 10, '1', S("abcde1111111111fghij"));
-    test(S("abcdefghij"), 5, 20, '1', S("abcde11111111111111111111fghij"));
-    test(S("abcdefghij"), 9, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 9, 5, '1', S("abcdefghi11111j"));
-    test(S("abcdefghij"), 9, 10, '1', S("abcdefghi1111111111j"));
-    test(S("abcdefghij"), 9, 20, '1', S("abcdefghi11111111111111111111j"));
-    test(S("abcdefghij"), 10, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 10, 5, '1', S("abcdefghij11111"));
-    test(S("abcdefghij"), 10, 10, '1', S("abcdefghij1111111111"));
-    test(S("abcdefghij"), 10, 20, '1', S("abcdefghij11111111111111111111"));
-    test(S("abcdefghijklmnopqrst"), 0, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 5, '1', S("11111abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 10, '1', S("1111111111abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 20, '1', S("11111111111111111111abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 5, '1', S("a11111bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 10, '1', S("a1111111111bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 20, '1', S("a11111111111111111111bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 5, '1', S("abcdefghij11111klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 10, '1', S("abcdefghij1111111111klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 20, '1', S("abcdefghij11111111111111111111klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, 5, '1', S("abcdefghijklmnopqrs11111t"));
-    test(S("abcdefghijklmnopqrst"), 19, 10, '1', S("abcdefghijklmnopqrs1111111111t"));
-    test(S("abcdefghijklmnopqrst"), 19, 20, '1', S("abcdefghijklmnopqrs11111111111111111111t"));
-    test(S("abcdefghijklmnopqrst"), 20, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 20, 5, '1', S("abcdefghijklmnopqrst11111"));
-    test(S("abcdefghijklmnopqrst"), 20, 10, '1', S("abcdefghijklmnopqrst1111111111"));
-    test(S("abcdefghijklmnopqrst"), 20, 20, '1', S("abcdefghijklmnopqrst11111111111111111111"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
index aeb432f25d226..e8a6abf530256 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
@@ -47,174 +47,94 @@ test(S s, typename S::size_type pos, const typename S::value_type* str, S expect
 #endif
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(""), 0, "", S(""));
+  test(S(""), 0, "12345", S("12345"));
+  test(S(""), 0, "1234567890", S("1234567890"));
+  test(S(""), 0, "12345678901234567890", S("12345678901234567890"));
+  test(S(""), 1, "", S("can't happen"));
+  test(S(""), 1, "12345", S("can't happen"));
+  test(S(""), 1, "1234567890", S("can't happen"));
+  test(S(""), 1, "12345678901234567890", S("can't happen"));
+  test(S("abcde"), 0, "", S("abcde"));
+  test(S("abcde"), 0, "12345", S("12345abcde"));
+  test(S("abcde"), 0, "1234567890", S("1234567890abcde"));
+  test(S("abcde"), 0, "12345678901234567890", S("12345678901234567890abcde"));
+  test(S("abcde"), 1, "", S("abcde"));
+  test(S("abcde"), 1, "12345", S("a12345bcde"));
+  test(S("abcde"), 1, "1234567890", S("a1234567890bcde"));
+  test(S("abcde"), 1, "12345678901234567890", S("a12345678901234567890bcde"));
+  test(S("abcde"), 2, "", S("abcde"));
+  test(S("abcde"), 2, "12345", S("ab12345cde"));
+  test(S("abcde"), 2, "1234567890", S("ab1234567890cde"));
+  test(S("abcde"), 2, "12345678901234567890", S("ab12345678901234567890cde"));
+  test(S("abcde"), 4, "", S("abcde"));
+  test(S("abcde"), 4, "12345", S("abcd12345e"));
+  test(S("abcde"), 4, "1234567890", S("abcd1234567890e"));
+  test(S("abcde"), 4, "12345678901234567890", S("abcd12345678901234567890e"));
+  test(S("abcde"), 5, "", S("abcde"));
+  test(S("abcde"), 5, "12345", S("abcde12345"));
+  test(S("abcde"), 5, "1234567890", S("abcde1234567890"));
+  test(S("abcde"), 5, "12345678901234567890", S("abcde12345678901234567890"));
+  test(S("abcde"), 6, "", S("can't happen"));
+  test(S("abcde"), 6, "12345", S("can't happen"));
+  test(S("abcde"), 6, "1234567890", S("can't happen"));
+  test(S("abcde"), 6, "12345678901234567890", S("can't happen"));
+  test(S("abcdefghij"), 0, "", S("abcdefghij"));
+  test(S("abcdefghij"), 0, "12345", S("12345abcdefghij"));
+  test(S("abcdefghij"), 0, "1234567890", S("1234567890abcdefghij"));
+  test(S("abcdefghij"), 0, "12345678901234567890", S("12345678901234567890abcdefghij"));
+  test(S("abcdefghij"), 1, "", S("abcdefghij"));
+  test(S("abcdefghij"), 1, "12345", S("a12345bcdefghij"));
+  test(S("abcdefghij"), 1, "1234567890", S("a1234567890bcdefghij"));
+  test(S("abcdefghij"), 1, "12345678901234567890", S("a12345678901234567890bcdefghij"));
+  test(S("abcdefghij"), 5, "", S("abcdefghij"));
+  test(S("abcdefghij"), 5, "12345", S("abcde12345fghij"));
+  test(S("abcdefghij"), 5, "1234567890", S("abcde1234567890fghij"));
+  test(S("abcdefghij"), 5, "12345678901234567890", S("abcde12345678901234567890fghij"));
+  test(S("abcdefghij"), 9, "", S("abcdefghij"));
+  test(S("abcdefghij"), 9, "12345", S("abcdefghi12345j"));
+  test(S("abcdefghij"), 9, "1234567890", S("abcdefghi1234567890j"));
+  test(S("abcdefghij"), 9, "12345678901234567890", S("abcdefghi12345678901234567890j"));
+  test(S("abcdefghij"), 10, "", S("abcdefghij"));
+  test(S("abcdefghij"), 10, "12345", S("abcdefghij12345"));
+  test(S("abcdefghij"), 10, "1234567890", S("abcdefghij1234567890"));
+  test(S("abcdefghij"), 10, "12345678901234567890", S("abcdefghij12345678901234567890"));
+  test(S("abcdefghij"), 11, "", S("can't happen"));
+  test(S("abcdefghij"), 11, "12345", S("can't happen"));
+  test(S("abcdefghij"), 11, "1234567890", S("can't happen"));
+  test(S("abcdefghij"), 11, "12345678901234567890", S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 0, "", S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, "12345", S("12345abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, "1234567890", S("1234567890abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, "12345678901234567890", S("12345678901234567890abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, "", S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, "12345", S("a12345bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, "1234567890", S("a1234567890bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, "12345678901234567890", S("a12345678901234567890bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, "", S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, "12345", S("abcdefghij12345klmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, "1234567890", S("abcdefghij1234567890klmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, "12345678901234567890", S("abcdefghij12345678901234567890klmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 19, "", S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 19, "12345", S("abcdefghijklmnopqrs12345t"));
+  test(S("abcdefghijklmnopqrst"), 19, "1234567890", S("abcdefghijklmnopqrs1234567890t"));
+  test(S("abcdefghijklmnopqrst"), 19, "12345678901234567890", S("abcdefghijklmnopqrs12345678901234567890t"));
+  test(S("abcdefghijklmnopqrst"), 20, "", S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 20, "12345", S("abcdefghijklmnopqrst12345"));
+  test(S("abcdefghijklmnopqrst"), 20, "1234567890", S("abcdefghijklmnopqrst1234567890"));
+  test(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890"));
+  test(S("abcdefghijklmnopqrst"), 21, "", S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 21, "12345", S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 21, "1234567890", S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", S("can't happen"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(""), 0, "", S(""));
-    test(S(""), 0, "12345", S("12345"));
-    test(S(""), 0, "1234567890", S("1234567890"));
-    test(S(""), 0, "12345678901234567890", S("12345678901234567890"));
-    test(S(""), 1, "", S("can't happen"));
-    test(S(""), 1, "12345", S("can't happen"));
-    test(S(""), 1, "1234567890", S("can't happen"));
-    test(S(""), 1, "12345678901234567890", S("can't happen"));
-    test(S("abcde"), 0, "", S("abcde"));
-    test(S("abcde"), 0, "12345", S("12345abcde"));
-    test(S("abcde"), 0, "1234567890", S("1234567890abcde"));
-    test(S("abcde"), 0, "12345678901234567890", S("12345678901234567890abcde"));
-    test(S("abcde"), 1, "", S("abcde"));
-    test(S("abcde"), 1, "12345", S("a12345bcde"));
-    test(S("abcde"), 1, "1234567890", S("a1234567890bcde"));
-    test(S("abcde"), 1, "12345678901234567890", S("a12345678901234567890bcde"));
-    test(S("abcde"), 2, "", S("abcde"));
-    test(S("abcde"), 2, "12345", S("ab12345cde"));
-    test(S("abcde"), 2, "1234567890", S("ab1234567890cde"));
-    test(S("abcde"), 2, "12345678901234567890", S("ab12345678901234567890cde"));
-    test(S("abcde"), 4, "", S("abcde"));
-    test(S("abcde"), 4, "12345", S("abcd12345e"));
-    test(S("abcde"), 4, "1234567890", S("abcd1234567890e"));
-    test(S("abcde"), 4, "12345678901234567890", S("abcd12345678901234567890e"));
-    test(S("abcde"), 5, "", S("abcde"));
-    test(S("abcde"), 5, "12345", S("abcde12345"));
-    test(S("abcde"), 5, "1234567890", S("abcde1234567890"));
-    test(S("abcde"), 5, "12345678901234567890", S("abcde12345678901234567890"));
-    test(S("abcde"), 6, "", S("can't happen"));
-    test(S("abcde"), 6, "12345", S("can't happen"));
-    test(S("abcde"), 6, "1234567890", S("can't happen"));
-    test(S("abcde"), 6, "12345678901234567890", S("can't happen"));
-    test(S("abcdefghij"), 0, "", S("abcdefghij"));
-    test(S("abcdefghij"), 0, "12345", S("12345abcdefghij"));
-    test(S("abcdefghij"), 0, "1234567890", S("1234567890abcdefghij"));
-    test(S("abcdefghij"), 0, "12345678901234567890", S("12345678901234567890abcdefghij"));
-    test(S("abcdefghij"), 1, "", S("abcdefghij"));
-    test(S("abcdefghij"), 1, "12345", S("a12345bcdefghij"));
-    test(S("abcdefghij"), 1, "1234567890", S("a1234567890bcdefghij"));
-    test(S("abcdefghij"), 1, "12345678901234567890", S("a12345678901234567890bcdefghij"));
-    test(S("abcdefghij"), 5, "", S("abcdefghij"));
-    test(S("abcdefghij"), 5, "12345", S("abcde12345fghij"));
-    test(S("abcdefghij"), 5, "1234567890", S("abcde1234567890fghij"));
-    test(S("abcdefghij"), 5, "12345678901234567890", S("abcde12345678901234567890fghij"));
-    test(S("abcdefghij"), 9, "", S("abcdefghij"));
-    test(S("abcdefghij"), 9, "12345", S("abcdefghi12345j"));
-    test(S("abcdefghij"), 9, "1234567890", S("abcdefghi1234567890j"));
-    test(S("abcdefghij"), 9, "12345678901234567890", S("abcdefghi12345678901234567890j"));
-    test(S("abcdefghij"), 10, "", S("abcdefghij"));
-    test(S("abcdefghij"), 10, "12345", S("abcdefghij12345"));
-    test(S("abcdefghij"), 10, "1234567890", S("abcdefghij1234567890"));
-    test(S("abcdefghij"), 10, "12345678901234567890", S("abcdefghij12345678901234567890"));
-    test(S("abcdefghij"), 11, "", S("can't happen"));
-    test(S("abcdefghij"), 11, "12345", S("can't happen"));
-    test(S("abcdefghij"), 11, "1234567890", S("can't happen"));
-    test(S("abcdefghij"), 11, "12345678901234567890", S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 0, "", S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, "12345", S("12345abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, "1234567890", S("1234567890abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, "12345678901234567890", S("12345678901234567890abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, "", S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, "12345", S("a12345bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, "1234567890", S("a1234567890bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, "12345678901234567890", S("a12345678901234567890bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, "", S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, "12345", S("abcdefghij12345klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, "1234567890", S("abcdefghij1234567890klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, "12345678901234567890", S("abcdefghij12345678901234567890klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, "", S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, "12345", S("abcdefghijklmnopqrs12345t"));
-    test(S("abcdefghijklmnopqrst"), 19, "1234567890", S("abcdefghijklmnopqrs1234567890t"));
-    test(S("abcdefghijklmnopqrst"), 19, "12345678901234567890", S("abcdefghijklmnopqrs12345678901234567890t"));
-    test(S("abcdefghijklmnopqrst"), 20, "", S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 20, "12345", S("abcdefghijklmnopqrst12345"));
-    test(S("abcdefghijklmnopqrst"), 20, "1234567890", S("abcdefghijklmnopqrst1234567890"));
-    test(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890"));
-    test(S("abcdefghijklmnopqrst"), 21, "", S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, "12345", S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, "1234567890", S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", S("can't happen"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(""), 0, "", S(""));
-    test(S(""), 0, "12345", S("12345"));
-    test(S(""), 0, "1234567890", S("1234567890"));
-    test(S(""), 0, "12345678901234567890", S("12345678901234567890"));
-    test(S(""), 1, "", S("can't happen"));
-    test(S(""), 1, "12345", S("can't happen"));
-    test(S(""), 1, "1234567890", S("can't happen"));
-    test(S(""), 1, "12345678901234567890", S("can't happen"));
-    test(S("abcde"), 0, "", S("abcde"));
-    test(S("abcde"), 0, "12345", S("12345abcde"));
-    test(S("abcde"), 0, "1234567890", S("1234567890abcde"));
-    test(S("abcde"), 0, "12345678901234567890", S("12345678901234567890abcde"));
-    test(S("abcde"), 1, "", S("abcde"));
-    test(S("abcde"), 1, "12345", S("a12345bcde"));
-    test(S("abcde"), 1, "1234567890", S("a1234567890bcde"));
-    test(S("abcde"), 1, "12345678901234567890", S("a12345678901234567890bcde"));
-    test(S("abcde"), 2, "", S("abcde"));
-    test(S("abcde"), 2, "12345", S("ab12345cde"));
-    test(S("abcde"), 2, "1234567890", S("ab1234567890cde"));
-    test(S("abcde"), 2, "12345678901234567890", S("ab12345678901234567890cde"));
-    test(S("abcde"), 4, "", S("abcde"));
-    test(S("abcde"), 4, "12345", S("abcd12345e"));
-    test(S("abcde"), 4, "1234567890", S("abcd1234567890e"));
-    test(S("abcde"), 4, "12345678901234567890", S("abcd12345678901234567890e"));
-    test(S("abcde"), 5, "", S("abcde"));
-    test(S("abcde"), 5, "12345", S("abcde12345"));
-    test(S("abcde"), 5, "1234567890", S("abcde1234567890"));
-    test(S("abcde"), 5, "12345678901234567890", S("abcde12345678901234567890"));
-    test(S("abcde"), 6, "", S("can't happen"));
-    test(S("abcde"), 6, "12345", S("can't happen"));
-    test(S("abcde"), 6, "1234567890", S("can't happen"));
-    test(S("abcde"), 6, "12345678901234567890", S("can't happen"));
-    test(S("abcdefghij"), 0, "", S("abcdefghij"));
-    test(S("abcdefghij"), 0, "12345", S("12345abcdefghij"));
-    test(S("abcdefghij"), 0, "1234567890", S("1234567890abcdefghij"));
-    test(S("abcdefghij"), 0, "12345678901234567890", S("12345678901234567890abcdefghij"));
-    test(S("abcdefghij"), 1, "", S("abcdefghij"));
-    test(S("abcdefghij"), 1, "12345", S("a12345bcdefghij"));
-    test(S("abcdefghij"), 1, "1234567890", S("a1234567890bcdefghij"));
-    test(S("abcdefghij"), 1, "12345678901234567890", S("a12345678901234567890bcdefghij"));
-    test(S("abcdefghij"), 5, "", S("abcdefghij"));
-    test(S("abcdefghij"), 5, "12345", S("abcde12345fghij"));
-    test(S("abcdefghij"), 5, "1234567890", S("abcde1234567890fghij"));
-    test(S("abcdefghij"), 5, "12345678901234567890", S("abcde12345678901234567890fghij"));
-    test(S("abcdefghij"), 9, "", S("abcdefghij"));
-    test(S("abcdefghij"), 9, "12345", S("abcdefghi12345j"));
-    test(S("abcdefghij"), 9, "1234567890", S("abcdefghi1234567890j"));
-    test(S("abcdefghij"), 9, "12345678901234567890", S("abcdefghi12345678901234567890j"));
-    test(S("abcdefghij"), 10, "", S("abcdefghij"));
-    test(S("abcdefghij"), 10, "12345", S("abcdefghij12345"));
-    test(S("abcdefghij"), 10, "1234567890", S("abcdefghij1234567890"));
-    test(S("abcdefghij"), 10, "12345678901234567890", S("abcdefghij12345678901234567890"));
-    test(S("abcdefghij"), 11, "", S("can't happen"));
-    test(S("abcdefghij"), 11, "12345", S("can't happen"));
-    test(S("abcdefghij"), 11, "1234567890", S("can't happen"));
-    test(S("abcdefghij"), 11, "12345678901234567890", S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 0, "", S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, "12345", S("12345abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, "1234567890", S("1234567890abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, "12345678901234567890", S("12345678901234567890abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, "", S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, "12345", S("a12345bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, "1234567890", S("a1234567890bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, "12345678901234567890", S("a12345678901234567890bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, "", S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, "12345", S("abcdefghij12345klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, "1234567890", S("abcdefghij1234567890klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, "12345678901234567890", S("abcdefghij12345678901234567890klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, "", S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, "12345", S("abcdefghijklmnopqrs12345t"));
-    test(S("abcdefghijklmnopqrst"), 19, "1234567890", S("abcdefghijklmnopqrs1234567890t"));
-    test(S("abcdefghijklmnopqrst"), 19, "12345678901234567890", S("abcdefghijklmnopqrs12345678901234567890t"));
-    test(S("abcdefghijklmnopqrst"), 20, "", S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 20, "12345", S("abcdefghijklmnopqrst12345"));
-    test(S("abcdefghijklmnopqrst"), 20, "1234567890", S("abcdefghijklmnopqrst1234567890"));
-    test(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890"));
-    test(S("abcdefghijklmnopqrst"), 21, "", S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, "12345", S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, "1234567890", S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", S("can't happen"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   { // test inserting into self

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
index e7429702ec07e..143fa54f42779 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
@@ -48,174 +48,94 @@ test(S s, typename S::size_type pos, typename S::size_type n,
 #endif
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(""), 0, 0, '1', S(""));
+  test(S(""), 0, 5, '1', S("11111"));
+  test(S(""), 0, 10, '1', S("1111111111"));
+  test(S(""), 0, 20, '1', S("11111111111111111111"));
+  test(S(""), 1, 0, '1', S("can't happen"));
+  test(S(""), 1, 5, '1', S("can't happen"));
+  test(S(""), 1, 10, '1', S("can't happen"));
+  test(S(""), 1, 20, '1', S("can't happen"));
+  test(S("abcde"), 0, 0, '1', S("abcde"));
+  test(S("abcde"), 0, 5, '1', S("11111abcde"));
+  test(S("abcde"), 0, 10, '1', S("1111111111abcde"));
+  test(S("abcde"), 0, 20, '1', S("11111111111111111111abcde"));
+  test(S("abcde"), 1, 0, '1', S("abcde"));
+  test(S("abcde"), 1, 5, '1', S("a11111bcde"));
+  test(S("abcde"), 1, 10, '1', S("a1111111111bcde"));
+  test(S("abcde"), 1, 20, '1', S("a11111111111111111111bcde"));
+  test(S("abcde"), 2, 0, '1', S("abcde"));
+  test(S("abcde"), 2, 5, '1', S("ab11111cde"));
+  test(S("abcde"), 2, 10, '1', S("ab1111111111cde"));
+  test(S("abcde"), 2, 20, '1', S("ab11111111111111111111cde"));
+  test(S("abcde"), 4, 0, '1', S("abcde"));
+  test(S("abcde"), 4, 5, '1', S("abcd11111e"));
+  test(S("abcde"), 4, 10, '1', S("abcd1111111111e"));
+  test(S("abcde"), 4, 20, '1', S("abcd11111111111111111111e"));
+  test(S("abcde"), 5, 0, '1', S("abcde"));
+  test(S("abcde"), 5, 5, '1', S("abcde11111"));
+  test(S("abcde"), 5, 10, '1', S("abcde1111111111"));
+  test(S("abcde"), 5, 20, '1', S("abcde11111111111111111111"));
+  test(S("abcde"), 6, 0, '1', S("can't happen"));
+  test(S("abcde"), 6, 5, '1', S("can't happen"));
+  test(S("abcde"), 6, 10, '1', S("can't happen"));
+  test(S("abcde"), 6, 20, '1', S("can't happen"));
+  test(S("abcdefghij"), 0, 0, '1', S("abcdefghij"));
+  test(S("abcdefghij"), 0, 5, '1', S("11111abcdefghij"));
+  test(S("abcdefghij"), 0, 10, '1', S("1111111111abcdefghij"));
+  test(S("abcdefghij"), 0, 20, '1', S("11111111111111111111abcdefghij"));
+  test(S("abcdefghij"), 1, 0, '1', S("abcdefghij"));
+  test(S("abcdefghij"), 1, 5, '1', S("a11111bcdefghij"));
+  test(S("abcdefghij"), 1, 10, '1', S("a1111111111bcdefghij"));
+  test(S("abcdefghij"), 1, 20, '1', S("a11111111111111111111bcdefghij"));
+  test(S("abcdefghij"), 5, 0, '1', S("abcdefghij"));
+  test(S("abcdefghij"), 5, 5, '1', S("abcde11111fghij"));
+  test(S("abcdefghij"), 5, 10, '1', S("abcde1111111111fghij"));
+  test(S("abcdefghij"), 5, 20, '1', S("abcde11111111111111111111fghij"));
+  test(S("abcdefghij"), 9, 0, '1', S("abcdefghij"));
+  test(S("abcdefghij"), 9, 5, '1', S("abcdefghi11111j"));
+  test(S("abcdefghij"), 9, 10, '1', S("abcdefghi1111111111j"));
+  test(S("abcdefghij"), 9, 20, '1', S("abcdefghi11111111111111111111j"));
+  test(S("abcdefghij"), 10, 0, '1', S("abcdefghij"));
+  test(S("abcdefghij"), 10, 5, '1', S("abcdefghij11111"));
+  test(S("abcdefghij"), 10, 10, '1', S("abcdefghij1111111111"));
+  test(S("abcdefghij"), 10, 20, '1', S("abcdefghij11111111111111111111"));
+  test(S("abcdefghij"), 11, 0, '1', S("can't happen"));
+  test(S("abcdefghij"), 11, 5, '1', S("can't happen"));
+  test(S("abcdefghij"), 11, 10, '1', S("can't happen"));
+  test(S("abcdefghij"), 11, 20, '1', S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 0, 0, '1', S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, 5, '1', S("11111abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, 10, '1', S("1111111111abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, 20, '1', S("11111111111111111111abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, 0, '1', S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, 5, '1', S("a11111bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, 10, '1', S("a1111111111bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, 20, '1', S("a11111111111111111111bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, 0, '1', S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, 5, '1', S("abcdefghij11111klmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, 10, '1', S("abcdefghij1111111111klmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, 20, '1', S("abcdefghij11111111111111111111klmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 19, 0, '1', S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 19, 5, '1', S("abcdefghijklmnopqrs11111t"));
+  test(S("abcdefghijklmnopqrst"), 19, 10, '1', S("abcdefghijklmnopqrs1111111111t"));
+  test(S("abcdefghijklmnopqrst"), 19, 20, '1', S("abcdefghijklmnopqrs11111111111111111111t"));
+  test(S("abcdefghijklmnopqrst"), 20, 0, '1', S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 20, 5, '1', S("abcdefghijklmnopqrst11111"));
+  test(S("abcdefghijklmnopqrst"), 20, 10, '1', S("abcdefghijklmnopqrst1111111111"));
+  test(S("abcdefghijklmnopqrst"), 20, 20, '1', S("abcdefghijklmnopqrst11111111111111111111"));
+  test(S("abcdefghijklmnopqrst"), 21, 0, '1', S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 21, 5, '1', S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 21, 10, '1', S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 21, 20, '1', S("can't happen"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(""), 0, 0, '1', S(""));
-    test(S(""), 0, 5, '1', S("11111"));
-    test(S(""), 0, 10, '1', S("1111111111"));
-    test(S(""), 0, 20, '1', S("11111111111111111111"));
-    test(S(""), 1, 0, '1', S("can't happen"));
-    test(S(""), 1, 5, '1', S("can't happen"));
-    test(S(""), 1, 10, '1', S("can't happen"));
-    test(S(""), 1, 20, '1', S("can't happen"));
-    test(S("abcde"), 0, 0, '1', S("abcde"));
-    test(S("abcde"), 0, 5, '1', S("11111abcde"));
-    test(S("abcde"), 0, 10, '1', S("1111111111abcde"));
-    test(S("abcde"), 0, 20, '1', S("11111111111111111111abcde"));
-    test(S("abcde"), 1, 0, '1', S("abcde"));
-    test(S("abcde"), 1, 5, '1', S("a11111bcde"));
-    test(S("abcde"), 1, 10, '1', S("a1111111111bcde"));
-    test(S("abcde"), 1, 20, '1', S("a11111111111111111111bcde"));
-    test(S("abcde"), 2, 0, '1', S("abcde"));
-    test(S("abcde"), 2, 5, '1', S("ab11111cde"));
-    test(S("abcde"), 2, 10, '1', S("ab1111111111cde"));
-    test(S("abcde"), 2, 20, '1', S("ab11111111111111111111cde"));
-    test(S("abcde"), 4, 0, '1', S("abcde"));
-    test(S("abcde"), 4, 5, '1', S("abcd11111e"));
-    test(S("abcde"), 4, 10, '1', S("abcd1111111111e"));
-    test(S("abcde"), 4, 20, '1', S("abcd11111111111111111111e"));
-    test(S("abcde"), 5, 0, '1', S("abcde"));
-    test(S("abcde"), 5, 5, '1', S("abcde11111"));
-    test(S("abcde"), 5, 10, '1', S("abcde1111111111"));
-    test(S("abcde"), 5, 20, '1', S("abcde11111111111111111111"));
-    test(S("abcde"), 6, 0, '1', S("can't happen"));
-    test(S("abcde"), 6, 5, '1', S("can't happen"));
-    test(S("abcde"), 6, 10, '1', S("can't happen"));
-    test(S("abcde"), 6, 20, '1', S("can't happen"));
-    test(S("abcdefghij"), 0, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 0, 5, '1', S("11111abcdefghij"));
-    test(S("abcdefghij"), 0, 10, '1', S("1111111111abcdefghij"));
-    test(S("abcdefghij"), 0, 20, '1', S("11111111111111111111abcdefghij"));
-    test(S("abcdefghij"), 1, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 1, 5, '1', S("a11111bcdefghij"));
-    test(S("abcdefghij"), 1, 10, '1', S("a1111111111bcdefghij"));
-    test(S("abcdefghij"), 1, 20, '1', S("a11111111111111111111bcdefghij"));
-    test(S("abcdefghij"), 5, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 5, 5, '1', S("abcde11111fghij"));
-    test(S("abcdefghij"), 5, 10, '1', S("abcde1111111111fghij"));
-    test(S("abcdefghij"), 5, 20, '1', S("abcde11111111111111111111fghij"));
-    test(S("abcdefghij"), 9, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 9, 5, '1', S("abcdefghi11111j"));
-    test(S("abcdefghij"), 9, 10, '1', S("abcdefghi1111111111j"));
-    test(S("abcdefghij"), 9, 20, '1', S("abcdefghi11111111111111111111j"));
-    test(S("abcdefghij"), 10, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 10, 5, '1', S("abcdefghij11111"));
-    test(S("abcdefghij"), 10, 10, '1', S("abcdefghij1111111111"));
-    test(S("abcdefghij"), 10, 20, '1', S("abcdefghij11111111111111111111"));
-    test(S("abcdefghij"), 11, 0, '1', S("can't happen"));
-    test(S("abcdefghij"), 11, 5, '1', S("can't happen"));
-    test(S("abcdefghij"), 11, 10, '1', S("can't happen"));
-    test(S("abcdefghij"), 11, 20, '1', S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 0, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 5, '1', S("11111abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 10, '1', S("1111111111abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 20, '1', S("11111111111111111111abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 5, '1', S("a11111bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 10, '1', S("a1111111111bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 20, '1', S("a11111111111111111111bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 5, '1', S("abcdefghij11111klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 10, '1', S("abcdefghij1111111111klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 20, '1', S("abcdefghij11111111111111111111klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, 5, '1', S("abcdefghijklmnopqrs11111t"));
-    test(S("abcdefghijklmnopqrst"), 19, 10, '1', S("abcdefghijklmnopqrs1111111111t"));
-    test(S("abcdefghijklmnopqrst"), 19, 20, '1', S("abcdefghijklmnopqrs11111111111111111111t"));
-    test(S("abcdefghijklmnopqrst"), 20, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 20, 5, '1', S("abcdefghijklmnopqrst11111"));
-    test(S("abcdefghijklmnopqrst"), 20, 10, '1', S("abcdefghijklmnopqrst1111111111"));
-    test(S("abcdefghijklmnopqrst"), 20, 20, '1', S("abcdefghijklmnopqrst11111111111111111111"));
-    test(S("abcdefghijklmnopqrst"), 21, 0, '1', S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, 5, '1', S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, 10, '1', S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, 20, '1', S("can't happen"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(""), 0, 0, '1', S(""));
-    test(S(""), 0, 5, '1', S("11111"));
-    test(S(""), 0, 10, '1', S("1111111111"));
-    test(S(""), 0, 20, '1', S("11111111111111111111"));
-    test(S(""), 1, 0, '1', S("can't happen"));
-    test(S(""), 1, 5, '1', S("can't happen"));
-    test(S(""), 1, 10, '1', S("can't happen"));
-    test(S(""), 1, 20, '1', S("can't happen"));
-    test(S("abcde"), 0, 0, '1', S("abcde"));
-    test(S("abcde"), 0, 5, '1', S("11111abcde"));
-    test(S("abcde"), 0, 10, '1', S("1111111111abcde"));
-    test(S("abcde"), 0, 20, '1', S("11111111111111111111abcde"));
-    test(S("abcde"), 1, 0, '1', S("abcde"));
-    test(S("abcde"), 1, 5, '1', S("a11111bcde"));
-    test(S("abcde"), 1, 10, '1', S("a1111111111bcde"));
-    test(S("abcde"), 1, 20, '1', S("a11111111111111111111bcde"));
-    test(S("abcde"), 2, 0, '1', S("abcde"));
-    test(S("abcde"), 2, 5, '1', S("ab11111cde"));
-    test(S("abcde"), 2, 10, '1', S("ab1111111111cde"));
-    test(S("abcde"), 2, 20, '1', S("ab11111111111111111111cde"));
-    test(S("abcde"), 4, 0, '1', S("abcde"));
-    test(S("abcde"), 4, 5, '1', S("abcd11111e"));
-    test(S("abcde"), 4, 10, '1', S("abcd1111111111e"));
-    test(S("abcde"), 4, 20, '1', S("abcd11111111111111111111e"));
-    test(S("abcde"), 5, 0, '1', S("abcde"));
-    test(S("abcde"), 5, 5, '1', S("abcde11111"));
-    test(S("abcde"), 5, 10, '1', S("abcde1111111111"));
-    test(S("abcde"), 5, 20, '1', S("abcde11111111111111111111"));
-    test(S("abcde"), 6, 0, '1', S("can't happen"));
-    test(S("abcde"), 6, 5, '1', S("can't happen"));
-    test(S("abcde"), 6, 10, '1', S("can't happen"));
-    test(S("abcde"), 6, 20, '1', S("can't happen"));
-    test(S("abcdefghij"), 0, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 0, 5, '1', S("11111abcdefghij"));
-    test(S("abcdefghij"), 0, 10, '1', S("1111111111abcdefghij"));
-    test(S("abcdefghij"), 0, 20, '1', S("11111111111111111111abcdefghij"));
-    test(S("abcdefghij"), 1, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 1, 5, '1', S("a11111bcdefghij"));
-    test(S("abcdefghij"), 1, 10, '1', S("a1111111111bcdefghij"));
-    test(S("abcdefghij"), 1, 20, '1', S("a11111111111111111111bcdefghij"));
-    test(S("abcdefghij"), 5, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 5, 5, '1', S("abcde11111fghij"));
-    test(S("abcdefghij"), 5, 10, '1', S("abcde1111111111fghij"));
-    test(S("abcdefghij"), 5, 20, '1', S("abcde11111111111111111111fghij"));
-    test(S("abcdefghij"), 9, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 9, 5, '1', S("abcdefghi11111j"));
-    test(S("abcdefghij"), 9, 10, '1', S("abcdefghi1111111111j"));
-    test(S("abcdefghij"), 9, 20, '1', S("abcdefghi11111111111111111111j"));
-    test(S("abcdefghij"), 10, 0, '1', S("abcdefghij"));
-    test(S("abcdefghij"), 10, 5, '1', S("abcdefghij11111"));
-    test(S("abcdefghij"), 10, 10, '1', S("abcdefghij1111111111"));
-    test(S("abcdefghij"), 10, 20, '1', S("abcdefghij11111111111111111111"));
-    test(S("abcdefghij"), 11, 0, '1', S("can't happen"));
-    test(S("abcdefghij"), 11, 5, '1', S("can't happen"));
-    test(S("abcdefghij"), 11, 10, '1', S("can't happen"));
-    test(S("abcdefghij"), 11, 20, '1', S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 0, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 5, '1', S("11111abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 10, '1', S("1111111111abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, 20, '1', S("11111111111111111111abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 5, '1', S("a11111bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 10, '1', S("a1111111111bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, 20, '1', S("a11111111111111111111bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 5, '1', S("abcdefghij11111klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 10, '1', S("abcdefghij1111111111klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, 20, '1', S("abcdefghij11111111111111111111klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, 5, '1', S("abcdefghijklmnopqrs11111t"));
-    test(S("abcdefghijklmnopqrst"), 19, 10, '1', S("abcdefghijklmnopqrs1111111111t"));
-    test(S("abcdefghijklmnopqrst"), 19, 20, '1', S("abcdefghijklmnopqrs11111111111111111111t"));
-    test(S("abcdefghijklmnopqrst"), 20, 0, '1', S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 20, 5, '1', S("abcdefghijklmnopqrst11111"));
-    test(S("abcdefghijklmnopqrst"), 20, 10, '1', S("abcdefghijklmnopqrst1111111111"));
-    test(S("abcdefghijklmnopqrst"), 20, 20, '1', S("abcdefghijklmnopqrst11111111111111111111"));
-    test(S("abcdefghijklmnopqrst"), 21, 0, '1', S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, 5, '1', S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, 10, '1', S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, 20, '1', S("can't happen"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
index db95d27d7aa46..e3c81856cf2db 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
@@ -47,177 +47,97 @@ test(S s, typename S::size_type pos, S str, S expected)
 #endif
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(""), 0, S(""), S(""));
+  test(S(""), 0, S("12345"), S("12345"));
+  test(S(""), 0, S("1234567890"), S("1234567890"));
+  test(S(""), 0, S("12345678901234567890"), S("12345678901234567890"));
+  test(S(""), 1, S(""), S("can't happen"));
+  test(S(""), 1, S("12345"), S("can't happen"));
+  test(S(""), 1, S("1234567890"), S("can't happen"));
+  test(S(""), 1, S("12345678901234567890"), S("can't happen"));
+  test(S("abcde"), 0, S(""), S("abcde"));
+  test(S("abcde"), 0, S("12345"), S("12345abcde"));
+  test(S("abcde"), 0, S("1234567890"), S("1234567890abcde"));
+  test(S("abcde"), 0, S("12345678901234567890"), S("12345678901234567890abcde"));
+  test(S("abcde"), 1, S(""), S("abcde"));
+  test(S("abcde"), 1, S("12345"), S("a12345bcde"));
+  test(S("abcde"), 1, S("1234567890"), S("a1234567890bcde"));
+  test(S("abcde"), 1, S("12345678901234567890"), S("a12345678901234567890bcde"));
+  test(S("abcde"), 2, S(""), S("abcde"));
+  test(S("abcde"), 2, S("12345"), S("ab12345cde"));
+  test(S("abcde"), 2, S("1234567890"), S("ab1234567890cde"));
+  test(S("abcde"), 2, S("12345678901234567890"), S("ab12345678901234567890cde"));
+  test(S("abcde"), 4, S(""), S("abcde"));
+  test(S("abcde"), 4, S("12345"), S("abcd12345e"));
+  test(S("abcde"), 4, S("1234567890"), S("abcd1234567890e"));
+  test(S("abcde"), 4, S("12345678901234567890"), S("abcd12345678901234567890e"));
+  test(S("abcde"), 5, S(""), S("abcde"));
+  test(S("abcde"), 5, S("12345"), S("abcde12345"));
+  test(S("abcde"), 5, S("1234567890"), S("abcde1234567890"));
+  test(S("abcde"), 5, S("12345678901234567890"), S("abcde12345678901234567890"));
+  test(S("abcde"), 6, S(""), S("can't happen"));
+  test(S("abcde"), 6, S("12345"), S("can't happen"));
+  test(S("abcde"), 6, S("1234567890"), S("can't happen"));
+  test(S("abcde"), 6, S("12345678901234567890"), S("can't happen"));
+  test(S("abcdefghij"), 0, S(""), S("abcdefghij"));
+  test(S("abcdefghij"), 0, S("12345"), S("12345abcdefghij"));
+  test(S("abcdefghij"), 0, S("1234567890"), S("1234567890abcdefghij"));
+  test(S("abcdefghij"), 0, S("12345678901234567890"), S("12345678901234567890abcdefghij"));
+  test(S("abcdefghij"), 1, S(""), S("abcdefghij"));
+  test(S("abcdefghij"), 1, S("12345"), S("a12345bcdefghij"));
+  test(S("abcdefghij"), 1, S("1234567890"), S("a1234567890bcdefghij"));
+  test(S("abcdefghij"), 1, S("12345678901234567890"), S("a12345678901234567890bcdefghij"));
+  test(S("abcdefghij"), 5, S(""), S("abcdefghij"));
+  test(S("abcdefghij"), 5, S("12345"), S("abcde12345fghij"));
+  test(S("abcdefghij"), 5, S("1234567890"), S("abcde1234567890fghij"));
+  test(S("abcdefghij"), 5, S("12345678901234567890"), S("abcde12345678901234567890fghij"));
+  test(S("abcdefghij"), 9, S(""), S("abcdefghij"));
+  test(S("abcdefghij"), 9, S("12345"), S("abcdefghi12345j"));
+  test(S("abcdefghij"), 9, S("1234567890"), S("abcdefghi1234567890j"));
+  test(S("abcdefghij"), 9, S("12345678901234567890"), S("abcdefghi12345678901234567890j"));
+  test(S("abcdefghij"), 10, S(""), S("abcdefghij"));
+  test(S("abcdefghij"), 10, S("12345"), S("abcdefghij12345"));
+  test(S("abcdefghij"), 10, S("1234567890"), S("abcdefghij1234567890"));
+  test(S("abcdefghij"), 10, S("12345678901234567890"), S("abcdefghij12345678901234567890"));
+  test(S("abcdefghij"), 11, S(""), S("can't happen"));
+  test(S("abcdefghij"), 11, S("12345"), S("can't happen"));
+  test(S("abcdefghij"), 11, S("1234567890"), S("can't happen"));
+  test(S("abcdefghij"), 11, S("12345678901234567890"), S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 0, S(""), S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, S("12345"), S("12345abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), S("1234567890abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), S("12345678901234567890abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, S(""), S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, S("12345"), S("a12345bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), S("a1234567890bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), S("a12345678901234567890bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, S(""), S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, S("12345"), S("abcdefghij12345klmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), S("abcdefghij1234567890klmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), S("abcdefghij12345678901234567890klmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 19, S(""), S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 19, S("12345"), S("abcdefghijklmnopqrs12345t"));
+  test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), S("abcdefghijklmnopqrs1234567890t"));
+  test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890t"));
+  test(S("abcdefghijklmnopqrst"), 20, S(""), S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 20, S("12345"), S("abcdefghijklmnopqrst12345"));
+  test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+  test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+  test(S("abcdefghijklmnopqrst"), 21, S(""), S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 21, S("12345"), S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), S("can't happen"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(""), 0, S(""), S(""));
-    test(S(""), 0, S("12345"), S("12345"));
-    test(S(""), 0, S("1234567890"), S("1234567890"));
-    test(S(""), 0, S("12345678901234567890"), S("12345678901234567890"));
-    test(S(""), 1, S(""), S("can't happen"));
-    test(S(""), 1, S("12345"), S("can't happen"));
-    test(S(""), 1, S("1234567890"), S("can't happen"));
-    test(S(""), 1, S("12345678901234567890"), S("can't happen"));
-    test(S("abcde"), 0, S(""), S("abcde"));
-    test(S("abcde"), 0, S("12345"), S("12345abcde"));
-    test(S("abcde"), 0, S("1234567890"), S("1234567890abcde"));
-    test(S("abcde"), 0, S("12345678901234567890"), S("12345678901234567890abcde"));
-    test(S("abcde"), 1, S(""), S("abcde"));
-    test(S("abcde"), 1, S("12345"), S("a12345bcde"));
-    test(S("abcde"), 1, S("1234567890"), S("a1234567890bcde"));
-    test(S("abcde"), 1, S("12345678901234567890"), S("a12345678901234567890bcde"));
-    test(S("abcde"), 2, S(""), S("abcde"));
-    test(S("abcde"), 2, S("12345"), S("ab12345cde"));
-    test(S("abcde"), 2, S("1234567890"), S("ab1234567890cde"));
-    test(S("abcde"), 2, S("12345678901234567890"), S("ab12345678901234567890cde"));
-    test(S("abcde"), 4, S(""), S("abcde"));
-    test(S("abcde"), 4, S("12345"), S("abcd12345e"));
-    test(S("abcde"), 4, S("1234567890"), S("abcd1234567890e"));
-    test(S("abcde"), 4, S("12345678901234567890"), S("abcd12345678901234567890e"));
-    test(S("abcde"), 5, S(""), S("abcde"));
-    test(S("abcde"), 5, S("12345"), S("abcde12345"));
-    test(S("abcde"), 5, S("1234567890"), S("abcde1234567890"));
-    test(S("abcde"), 5, S("12345678901234567890"), S("abcde12345678901234567890"));
-    test(S("abcde"), 6, S(""), S("can't happen"));
-    test(S("abcde"), 6, S("12345"), S("can't happen"));
-    test(S("abcde"), 6, S("1234567890"), S("can't happen"));
-    test(S("abcde"), 6, S("12345678901234567890"), S("can't happen"));
-    test(S("abcdefghij"), 0, S(""), S("abcdefghij"));
-    test(S("abcdefghij"), 0, S("12345"), S("12345abcdefghij"));
-    test(S("abcdefghij"), 0, S("1234567890"), S("1234567890abcdefghij"));
-    test(S("abcdefghij"), 0, S("12345678901234567890"), S("12345678901234567890abcdefghij"));
-    test(S("abcdefghij"), 1, S(""), S("abcdefghij"));
-    test(S("abcdefghij"), 1, S("12345"), S("a12345bcdefghij"));
-    test(S("abcdefghij"), 1, S("1234567890"), S("a1234567890bcdefghij"));
-    test(S("abcdefghij"), 1, S("12345678901234567890"), S("a12345678901234567890bcdefghij"));
-    test(S("abcdefghij"), 5, S(""), S("abcdefghij"));
-    test(S("abcdefghij"), 5, S("12345"), S("abcde12345fghij"));
-    test(S("abcdefghij"), 5, S("1234567890"), S("abcde1234567890fghij"));
-    test(S("abcdefghij"), 5, S("12345678901234567890"), S("abcde12345678901234567890fghij"));
-    test(S("abcdefghij"), 9, S(""), S("abcdefghij"));
-    test(S("abcdefghij"), 9, S("12345"), S("abcdefghi12345j"));
-    test(S("abcdefghij"), 9, S("1234567890"), S("abcdefghi1234567890j"));
-    test(S("abcdefghij"), 9, S("12345678901234567890"), S("abcdefghi12345678901234567890j"));
-    test(S("abcdefghij"), 10, S(""), S("abcdefghij"));
-    test(S("abcdefghij"), 10, S("12345"), S("abcdefghij12345"));
-    test(S("abcdefghij"), 10, S("1234567890"), S("abcdefghij1234567890"));
-    test(S("abcdefghij"), 10, S("12345678901234567890"), S("abcdefghij12345678901234567890"));
-    test(S("abcdefghij"), 11, S(""), S("can't happen"));
-    test(S("abcdefghij"), 11, S("12345"), S("can't happen"));
-    test(S("abcdefghij"), 11, S("1234567890"), S("can't happen"));
-    test(S("abcdefghij"), 11, S("12345678901234567890"), S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 0, S(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, S("12345"), S("12345abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), S("1234567890abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), S("12345678901234567890abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, S(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, S("12345"), S("a12345bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), S("a1234567890bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), S("a12345678901234567890bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, S(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, S("12345"), S("abcdefghij12345klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), S("abcdefghij1234567890klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), S("abcdefghij12345678901234567890klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, S(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, S("12345"), S("abcdefghijklmnopqrs12345t"));
-    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), S("abcdefghijklmnopqrs1234567890t"));
-    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890t"));
-    test(S("abcdefghijklmnopqrst"), 20, S(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 20, S("12345"), S("abcdefghijklmnopqrst12345"));
-    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
-    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
-    test(S("abcdefghijklmnopqrst"), 21, S(""), S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, S("12345"), S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), S("can't happen"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(""), 0, S(""), S(""));
-    test(S(""), 0, S("12345"), S("12345"));
-    test(S(""), 0, S("1234567890"), S("1234567890"));
-    test(S(""), 0, S("12345678901234567890"), S("12345678901234567890"));
-    test(S(""), 1, S(""), S("can't happen"));
-    test(S(""), 1, S("12345"), S("can't happen"));
-    test(S(""), 1, S("1234567890"), S("can't happen"));
-    test(S(""), 1, S("12345678901234567890"), S("can't happen"));
-    test(S("abcde"), 0, S(""), S("abcde"));
-    test(S("abcde"), 0, S("12345"), S("12345abcde"));
-    test(S("abcde"), 0, S("1234567890"), S("1234567890abcde"));
-    test(S("abcde"), 0, S("12345678901234567890"), S("12345678901234567890abcde"));
-    test(S("abcde"), 1, S(""), S("abcde"));
-    test(S("abcde"), 1, S("12345"), S("a12345bcde"));
-    test(S("abcde"), 1, S("1234567890"), S("a1234567890bcde"));
-    test(S("abcde"), 1, S("12345678901234567890"), S("a12345678901234567890bcde"));
-    test(S("abcde"), 2, S(""), S("abcde"));
-    test(S("abcde"), 2, S("12345"), S("ab12345cde"));
-    test(S("abcde"), 2, S("1234567890"), S("ab1234567890cde"));
-    test(S("abcde"), 2, S("12345678901234567890"), S("ab12345678901234567890cde"));
-    test(S("abcde"), 4, S(""), S("abcde"));
-    test(S("abcde"), 4, S("12345"), S("abcd12345e"));
-    test(S("abcde"), 4, S("1234567890"), S("abcd1234567890e"));
-    test(S("abcde"), 4, S("12345678901234567890"), S("abcd12345678901234567890e"));
-    test(S("abcde"), 5, S(""), S("abcde"));
-    test(S("abcde"), 5, S("12345"), S("abcde12345"));
-    test(S("abcde"), 5, S("1234567890"), S("abcde1234567890"));
-    test(S("abcde"), 5, S("12345678901234567890"), S("abcde12345678901234567890"));
-    test(S("abcde"), 6, S(""), S("can't happen"));
-    test(S("abcde"), 6, S("12345"), S("can't happen"));
-    test(S("abcde"), 6, S("1234567890"), S("can't happen"));
-    test(S("abcde"), 6, S("12345678901234567890"), S("can't happen"));
-    test(S("abcdefghij"), 0, S(""), S("abcdefghij"));
-    test(S("abcdefghij"), 0, S("12345"), S("12345abcdefghij"));
-    test(S("abcdefghij"), 0, S("1234567890"), S("1234567890abcdefghij"));
-    test(S("abcdefghij"), 0, S("12345678901234567890"), S("12345678901234567890abcdefghij"));
-    test(S("abcdefghij"), 1, S(""), S("abcdefghij"));
-    test(S("abcdefghij"), 1, S("12345"), S("a12345bcdefghij"));
-    test(S("abcdefghij"), 1, S("1234567890"), S("a1234567890bcdefghij"));
-    test(S("abcdefghij"), 1, S("12345678901234567890"), S("a12345678901234567890bcdefghij"));
-    test(S("abcdefghij"), 5, S(""), S("abcdefghij"));
-    test(S("abcdefghij"), 5, S("12345"), S("abcde12345fghij"));
-    test(S("abcdefghij"), 5, S("1234567890"), S("abcde1234567890fghij"));
-    test(S("abcdefghij"), 5, S("12345678901234567890"), S("abcde12345678901234567890fghij"));
-    test(S("abcdefghij"), 9, S(""), S("abcdefghij"));
-    test(S("abcdefghij"), 9, S("12345"), S("abcdefghi12345j"));
-    test(S("abcdefghij"), 9, S("1234567890"), S("abcdefghi1234567890j"));
-    test(S("abcdefghij"), 9, S("12345678901234567890"), S("abcdefghi12345678901234567890j"));
-    test(S("abcdefghij"), 10, S(""), S("abcdefghij"));
-    test(S("abcdefghij"), 10, S("12345"), S("abcdefghij12345"));
-    test(S("abcdefghij"), 10, S("1234567890"), S("abcdefghij1234567890"));
-    test(S("abcdefghij"), 10, S("12345678901234567890"), S("abcdefghij12345678901234567890"));
-    test(S("abcdefghij"), 11, S(""), S("can't happen"));
-    test(S("abcdefghij"), 11, S("12345"), S("can't happen"));
-    test(S("abcdefghij"), 11, S("1234567890"), S("can't happen"));
-    test(S("abcdefghij"), 11, S("12345678901234567890"), S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 0, S(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, S("12345"), S("12345abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), S("1234567890abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), S("12345678901234567890abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, S(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, S("12345"), S("a12345bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), S("a1234567890bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), S("a12345678901234567890bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, S(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, S("12345"), S("abcdefghij12345klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), S("abcdefghij1234567890klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), S("abcdefghij12345678901234567890klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, S(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, S("12345"), S("abcdefghijklmnopqrs12345t"));
-    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), S("abcdefghijklmnopqrs1234567890t"));
-    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890t"));
-    test(S("abcdefghijklmnopqrst"), 20, S(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 20, S("12345"), S("abcdefghijklmnopqrst12345"));
-    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
-    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
-    test(S("abcdefghijklmnopqrst"), 21, S(""), S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, S("12345"), S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), S("can't happen"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
-#if TEST_STD_VER > 3
+#if TEST_STD_VER >= 11
   {   // LWG 2946
     std::string s;
     s.insert(0, {"abc", 1});

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/string_view.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/string_view.pass.cpp
index 3094c7635a07a..1f26a211bd94d 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/string_view.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/string_view.pass.cpp
@@ -47,176 +47,95 @@ test(S s, typename S::size_type pos, SV sv, S expected)
 #endif
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  typedef std::string_view SV;
+  test(S(""), 0, SV(""), S(""));
+  test(S(""), 0, SV("12345"), S("12345"));
+  test(S(""), 0, SV("1234567890"), S("1234567890"));
+  test(S(""), 0, SV("12345678901234567890"), S("12345678901234567890"));
+  test(S(""), 1, SV(""), S("can't happen"));
+  test(S(""), 1, SV("12345"), S("can't happen"));
+  test(S(""), 1, SV("1234567890"), S("can't happen"));
+  test(S(""), 1, SV("12345678901234567890"), S("can't happen"));
+  test(S("abcde"), 0, SV(""), S("abcde"));
+  test(S("abcde"), 0, SV("12345"), S("12345abcde"));
+  test(S("abcde"), 0, SV("1234567890"), S("1234567890abcde"));
+  test(S("abcde"), 0, SV("12345678901234567890"), S("12345678901234567890abcde"));
+  test(S("abcde"), 1, SV(""), S("abcde"));
+  test(S("abcde"), 1, SV("12345"), S("a12345bcde"));
+  test(S("abcde"), 1, SV("1234567890"), S("a1234567890bcde"));
+  test(S("abcde"), 1, SV("12345678901234567890"), S("a12345678901234567890bcde"));
+  test(S("abcde"), 2, SV(""), S("abcde"));
+  test(S("abcde"), 2, SV("12345"), S("ab12345cde"));
+  test(S("abcde"), 2, SV("1234567890"), S("ab1234567890cde"));
+  test(S("abcde"), 2, SV("12345678901234567890"), S("ab12345678901234567890cde"));
+  test(S("abcde"), 4, SV(""), S("abcde"));
+  test(S("abcde"), 4, SV("12345"), S("abcd12345e"));
+  test(S("abcde"), 4, SV("1234567890"), S("abcd1234567890e"));
+  test(S("abcde"), 4, SV("12345678901234567890"), S("abcd12345678901234567890e"));
+  test(S("abcde"), 5, SV(""), S("abcde"));
+  test(S("abcde"), 5, SV("12345"), S("abcde12345"));
+  test(S("abcde"), 5, SV("1234567890"), S("abcde1234567890"));
+  test(S("abcde"), 5, SV("12345678901234567890"), S("abcde12345678901234567890"));
+  test(S("abcde"), 6, SV(""), S("can't happen"));
+  test(S("abcde"), 6, SV("12345"), S("can't happen"));
+  test(S("abcde"), 6, SV("1234567890"), S("can't happen"));
+  test(S("abcde"), 6, SV("12345678901234567890"), S("can't happen"));
+  test(S("abcdefghij"), 0, SV(""), S("abcdefghij"));
+  test(S("abcdefghij"), 0, SV("12345"), S("12345abcdefghij"));
+  test(S("abcdefghij"), 0, SV("1234567890"), S("1234567890abcdefghij"));
+  test(S("abcdefghij"), 0, SV("12345678901234567890"), S("12345678901234567890abcdefghij"));
+  test(S("abcdefghij"), 1, SV(""), S("abcdefghij"));
+  test(S("abcdefghij"), 1, SV("12345"), S("a12345bcdefghij"));
+  test(S("abcdefghij"), 1, SV("1234567890"), S("a1234567890bcdefghij"));
+  test(S("abcdefghij"), 1, SV("12345678901234567890"), S("a12345678901234567890bcdefghij"));
+  test(S("abcdefghij"), 5, SV(""), S("abcdefghij"));
+  test(S("abcdefghij"), 5, SV("12345"), S("abcde12345fghij"));
+  test(S("abcdefghij"), 5, SV("1234567890"), S("abcde1234567890fghij"));
+  test(S("abcdefghij"), 5, SV("12345678901234567890"), S("abcde12345678901234567890fghij"));
+  test(S("abcdefghij"), 9, SV(""), S("abcdefghij"));
+  test(S("abcdefghij"), 9, SV("12345"), S("abcdefghi12345j"));
+  test(S("abcdefghij"), 9, SV("1234567890"), S("abcdefghi1234567890j"));
+  test(S("abcdefghij"), 9, SV("12345678901234567890"), S("abcdefghi12345678901234567890j"));
+  test(S("abcdefghij"), 10, SV(""), S("abcdefghij"));
+  test(S("abcdefghij"), 10, SV("12345"), S("abcdefghij12345"));
+  test(S("abcdefghij"), 10, SV("1234567890"), S("abcdefghij1234567890"));
+  test(S("abcdefghij"), 10, SV("12345678901234567890"), S("abcdefghij12345678901234567890"));
+  test(S("abcdefghij"), 11, SV(""), S("can't happen"));
+  test(S("abcdefghij"), 11, SV("12345"), S("can't happen"));
+  test(S("abcdefghij"), 11, SV("1234567890"), S("can't happen"));
+  test(S("abcdefghij"), 11, SV("12345678901234567890"), S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 0, SV(""), S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, SV("12345"), S("12345abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, SV("1234567890"), S("1234567890abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 0, SV("12345678901234567890"), S("12345678901234567890abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, SV(""), S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, SV("12345"), S("a12345bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, SV("1234567890"), S("a1234567890bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 1, SV("12345678901234567890"), S("a12345678901234567890bcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, SV(""), S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, SV("12345"), S("abcdefghij12345klmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, SV("1234567890"), S("abcdefghij1234567890klmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 10, SV("12345678901234567890"), S("abcdefghij12345678901234567890klmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 19, SV(""), S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 19, SV("12345"), S("abcdefghijklmnopqrs12345t"));
+  test(S("abcdefghijklmnopqrst"), 19, SV("1234567890"), S("abcdefghijklmnopqrs1234567890t"));
+  test(S("abcdefghijklmnopqrst"), 19, SV("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890t"));
+  test(S("abcdefghijklmnopqrst"), 20, SV(""), S("abcdefghijklmnopqrst"));
+  test(S("abcdefghijklmnopqrst"), 20, SV("12345"), S("abcdefghijklmnopqrst12345"));
+  test(S("abcdefghijklmnopqrst"), 20, SV("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+  test(S("abcdefghijklmnopqrst"), 20, SV("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+  test(S("abcdefghijklmnopqrst"), 21, SV(""), S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 21, SV("12345"), S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 21, SV("1234567890"), S("can't happen"));
+  test(S("abcdefghijklmnopqrst"), 21, SV("12345678901234567890"), S("can't happen"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    typedef std::string_view SV;
-    test(S(""), 0, SV(""), S(""));
-    test(S(""), 0, SV("12345"), S("12345"));
-    test(S(""), 0, SV("1234567890"), S("1234567890"));
-    test(S(""), 0, SV("12345678901234567890"), S("12345678901234567890"));
-    test(S(""), 1, SV(""), S("can't happen"));
-    test(S(""), 1, SV("12345"), S("can't happen"));
-    test(S(""), 1, SV("1234567890"), S("can't happen"));
-    test(S(""), 1, SV("12345678901234567890"), S("can't happen"));
-    test(S("abcde"), 0, SV(""), S("abcde"));
-    test(S("abcde"), 0, SV("12345"), S("12345abcde"));
-    test(S("abcde"), 0, SV("1234567890"), S("1234567890abcde"));
-    test(S("abcde"), 0, SV("12345678901234567890"), S("12345678901234567890abcde"));
-    test(S("abcde"), 1, SV(""), S("abcde"));
-    test(S("abcde"), 1, SV("12345"), S("a12345bcde"));
-    test(S("abcde"), 1, SV("1234567890"), S("a1234567890bcde"));
-    test(S("abcde"), 1, SV("12345678901234567890"), S("a12345678901234567890bcde"));
-    test(S("abcde"), 2, SV(""), S("abcde"));
-    test(S("abcde"), 2, SV("12345"), S("ab12345cde"));
-    test(S("abcde"), 2, SV("1234567890"), S("ab1234567890cde"));
-    test(S("abcde"), 2, SV("12345678901234567890"), S("ab12345678901234567890cde"));
-    test(S("abcde"), 4, SV(""), S("abcde"));
-    test(S("abcde"), 4, SV("12345"), S("abcd12345e"));
-    test(S("abcde"), 4, SV("1234567890"), S("abcd1234567890e"));
-    test(S("abcde"), 4, SV("12345678901234567890"), S("abcd12345678901234567890e"));
-    test(S("abcde"), 5, SV(""), S("abcde"));
-    test(S("abcde"), 5, SV("12345"), S("abcde12345"));
-    test(S("abcde"), 5, SV("1234567890"), S("abcde1234567890"));
-    test(S("abcde"), 5, SV("12345678901234567890"), S("abcde12345678901234567890"));
-    test(S("abcde"), 6, SV(""), S("can't happen"));
-    test(S("abcde"), 6, SV("12345"), S("can't happen"));
-    test(S("abcde"), 6, SV("1234567890"), S("can't happen"));
-    test(S("abcde"), 6, SV("12345678901234567890"), S("can't happen"));
-    test(S("abcdefghij"), 0, SV(""), S("abcdefghij"));
-    test(S("abcdefghij"), 0, SV("12345"), S("12345abcdefghij"));
-    test(S("abcdefghij"), 0, SV("1234567890"), S("1234567890abcdefghij"));
-    test(S("abcdefghij"), 0, SV("12345678901234567890"), S("12345678901234567890abcdefghij"));
-    test(S("abcdefghij"), 1, SV(""), S("abcdefghij"));
-    test(S("abcdefghij"), 1, SV("12345"), S("a12345bcdefghij"));
-    test(S("abcdefghij"), 1, SV("1234567890"), S("a1234567890bcdefghij"));
-    test(S("abcdefghij"), 1, SV("12345678901234567890"), S("a12345678901234567890bcdefghij"));
-    test(S("abcdefghij"), 5, SV(""), S("abcdefghij"));
-    test(S("abcdefghij"), 5, SV("12345"), S("abcde12345fghij"));
-    test(S("abcdefghij"), 5, SV("1234567890"), S("abcde1234567890fghij"));
-    test(S("abcdefghij"), 5, SV("12345678901234567890"), S("abcde12345678901234567890fghij"));
-    test(S("abcdefghij"), 9, SV(""), S("abcdefghij"));
-    test(S("abcdefghij"), 9, SV("12345"), S("abcdefghi12345j"));
-    test(S("abcdefghij"), 9, SV("1234567890"), S("abcdefghi1234567890j"));
-    test(S("abcdefghij"), 9, SV("12345678901234567890"), S("abcdefghi12345678901234567890j"));
-    test(S("abcdefghij"), 10, SV(""), S("abcdefghij"));
-    test(S("abcdefghij"), 10, SV("12345"), S("abcdefghij12345"));
-    test(S("abcdefghij"), 10, SV("1234567890"), S("abcdefghij1234567890"));
-    test(S("abcdefghij"), 10, SV("12345678901234567890"), S("abcdefghij12345678901234567890"));
-    test(S("abcdefghij"), 11, SV(""), S("can't happen"));
-    test(S("abcdefghij"), 11, SV("12345"), S("can't happen"));
-    test(S("abcdefghij"), 11, SV("1234567890"), S("can't happen"));
-    test(S("abcdefghij"), 11, SV("12345678901234567890"), S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 0, SV(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, SV("12345"), S("12345abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, SV("1234567890"), S("1234567890abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, SV("12345678901234567890"), S("12345678901234567890abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, SV(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, SV("12345"), S("a12345bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, SV("1234567890"), S("a1234567890bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, SV("12345678901234567890"), S("a12345678901234567890bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, SV(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, SV("12345"), S("abcdefghij12345klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, SV("1234567890"), S("abcdefghij1234567890klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, SV("12345678901234567890"), S("abcdefghij12345678901234567890klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, SV(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, SV("12345"), S("abcdefghijklmnopqrs12345t"));
-    test(S("abcdefghijklmnopqrst"), 19, SV("1234567890"), S("abcdefghijklmnopqrs1234567890t"));
-    test(S("abcdefghijklmnopqrst"), 19, SV("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890t"));
-    test(S("abcdefghijklmnopqrst"), 20, SV(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 20, SV("12345"), S("abcdefghijklmnopqrst12345"));
-    test(S("abcdefghijklmnopqrst"), 20, SV("1234567890"), S("abcdefghijklmnopqrst1234567890"));
-    test(S("abcdefghijklmnopqrst"), 20, SV("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
-    test(S("abcdefghijklmnopqrst"), 21, SV(""), S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, SV("12345"), S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, SV("1234567890"), S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, SV("12345678901234567890"), S("can't happen"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    typedef std::string_view SV;
-    test(S(""), 0, SV(""), S(""));
-    test(S(""), 0, SV("12345"), S("12345"));
-    test(S(""), 0, SV("1234567890"), S("1234567890"));
-    test(S(""), 0, SV("12345678901234567890"), S("12345678901234567890"));
-    test(S(""), 1, SV(""), S("can't happen"));
-    test(S(""), 1, SV("12345"), S("can't happen"));
-    test(S(""), 1, SV("1234567890"), S("can't happen"));
-    test(S(""), 1, SV("12345678901234567890"), S("can't happen"));
-    test(S("abcde"), 0, SV(""), S("abcde"));
-    test(S("abcde"), 0, SV("12345"), S("12345abcde"));
-    test(S("abcde"), 0, SV("1234567890"), S("1234567890abcde"));
-    test(S("abcde"), 0, SV("12345678901234567890"), S("12345678901234567890abcde"));
-    test(S("abcde"), 1, SV(""), S("abcde"));
-    test(S("abcde"), 1, SV("12345"), S("a12345bcde"));
-    test(S("abcde"), 1, SV("1234567890"), S("a1234567890bcde"));
-    test(S("abcde"), 1, SV("12345678901234567890"), S("a12345678901234567890bcde"));
-    test(S("abcde"), 2, SV(""), S("abcde"));
-    test(S("abcde"), 2, SV("12345"), S("ab12345cde"));
-    test(S("abcde"), 2, SV("1234567890"), S("ab1234567890cde"));
-    test(S("abcde"), 2, SV("12345678901234567890"), S("ab12345678901234567890cde"));
-    test(S("abcde"), 4, SV(""), S("abcde"));
-    test(S("abcde"), 4, SV("12345"), S("abcd12345e"));
-    test(S("abcde"), 4, SV("1234567890"), S("abcd1234567890e"));
-    test(S("abcde"), 4, SV("12345678901234567890"), S("abcd12345678901234567890e"));
-    test(S("abcde"), 5, SV(""), S("abcde"));
-    test(S("abcde"), 5, SV("12345"), S("abcde12345"));
-    test(S("abcde"), 5, SV("1234567890"), S("abcde1234567890"));
-    test(S("abcde"), 5, SV("12345678901234567890"), S("abcde12345678901234567890"));
-    test(S("abcde"), 6, SV(""), S("can't happen"));
-    test(S("abcde"), 6, SV("12345"), S("can't happen"));
-    test(S("abcde"), 6, SV("1234567890"), S("can't happen"));
-    test(S("abcde"), 6, SV("12345678901234567890"), S("can't happen"));
-    test(S("abcdefghij"), 0, SV(""), S("abcdefghij"));
-    test(S("abcdefghij"), 0, SV("12345"), S("12345abcdefghij"));
-    test(S("abcdefghij"), 0, SV("1234567890"), S("1234567890abcdefghij"));
-    test(S("abcdefghij"), 0, SV("12345678901234567890"), S("12345678901234567890abcdefghij"));
-    test(S("abcdefghij"), 1, SV(""), S("abcdefghij"));
-    test(S("abcdefghij"), 1, SV("12345"), S("a12345bcdefghij"));
-    test(S("abcdefghij"), 1, SV("1234567890"), S("a1234567890bcdefghij"));
-    test(S("abcdefghij"), 1, SV("12345678901234567890"), S("a12345678901234567890bcdefghij"));
-    test(S("abcdefghij"), 5, SV(""), S("abcdefghij"));
-    test(S("abcdefghij"), 5, SV("12345"), S("abcde12345fghij"));
-    test(S("abcdefghij"), 5, SV("1234567890"), S("abcde1234567890fghij"));
-    test(S("abcdefghij"), 5, SV("12345678901234567890"), S("abcde12345678901234567890fghij"));
-    test(S("abcdefghij"), 9, SV(""), S("abcdefghij"));
-    test(S("abcdefghij"), 9, SV("12345"), S("abcdefghi12345j"));
-    test(S("abcdefghij"), 9, SV("1234567890"), S("abcdefghi1234567890j"));
-    test(S("abcdefghij"), 9, SV("12345678901234567890"), S("abcdefghi12345678901234567890j"));
-    test(S("abcdefghij"), 10, SV(""), S("abcdefghij"));
-    test(S("abcdefghij"), 10, SV("12345"), S("abcdefghij12345"));
-    test(S("abcdefghij"), 10, SV("1234567890"), S("abcdefghij1234567890"));
-    test(S("abcdefghij"), 10, SV("12345678901234567890"), S("abcdefghij12345678901234567890"));
-    test(S("abcdefghij"), 11, SV(""), S("can't happen"));
-    test(S("abcdefghij"), 11, SV("12345"), S("can't happen"));
-    test(S("abcdefghij"), 11, SV("1234567890"), S("can't happen"));
-    test(S("abcdefghij"), 11, SV("12345678901234567890"), S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 0, SV(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, SV("12345"), S("12345abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, SV("1234567890"), S("1234567890abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 0, SV("12345678901234567890"), S("12345678901234567890abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, SV(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, SV("12345"), S("a12345bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, SV("1234567890"), S("a1234567890bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 1, SV("12345678901234567890"), S("a12345678901234567890bcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, SV(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, SV("12345"), S("abcdefghij12345klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, SV("1234567890"), S("abcdefghij1234567890klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 10, SV("12345678901234567890"), S("abcdefghij12345678901234567890klmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, SV(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 19, SV("12345"), S("abcdefghijklmnopqrs12345t"));
-    test(S("abcdefghijklmnopqrst"), 19, SV("1234567890"), S("abcdefghijklmnopqrs1234567890t"));
-    test(S("abcdefghijklmnopqrst"), 19, SV("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890t"));
-    test(S("abcdefghijklmnopqrst"), 20, SV(""), S("abcdefghijklmnopqrst"));
-    test(S("abcdefghijklmnopqrst"), 20, SV("12345"), S("abcdefghijklmnopqrst12345"));
-    test(S("abcdefghijklmnopqrst"), 20, SV("1234567890"), S("abcdefghijklmnopqrst1234567890"));
-    test(S("abcdefghijklmnopqrst"), 20, SV("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
-    test(S("abcdefghijklmnopqrst"), 21, SV(""), S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, SV("12345"), S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, SV("1234567890"), S("can't happen"));
-    test(S("abcdefghijklmnopqrst"), 21, SV("12345678901234567890"), S("can't happen"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   { // test inserting into self

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp
index 07ba259ba378f..645a5822f521d 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp
@@ -25,54 +25,34 @@ test(S s, const typename S::value_type* str, S expected)
     assert(s == expected);
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), "", S());
-    test(S(), "12345", S("12345"));
-    test(S(), "1234567890", S("1234567890"));
-    test(S(), "12345678901234567890", S("12345678901234567890"));
-
-    test(S("12345"), "", S("12345"));
-    test(S("12345"), "12345", S("1234512345"));
-    test(S("12345"), "1234567890", S("123451234567890"));
-    test(S("12345"), "12345678901234567890", S("1234512345678901234567890"));
-
-    test(S("1234567890"), "", S("1234567890"));
-    test(S("1234567890"), "12345", S("123456789012345"));
-    test(S("1234567890"), "1234567890", S("12345678901234567890"));
-    test(S("1234567890"), "12345678901234567890", S("123456789012345678901234567890"));
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), "", S());
+  test(S(), "12345", S("12345"));
+  test(S(), "1234567890", S("1234567890"));
+  test(S(), "12345678901234567890", S("12345678901234567890"));
 
-    test(S("12345678901234567890"), "", S("12345678901234567890"));
-    test(S("12345678901234567890"), "12345", S("1234567890123456789012345"));
-    test(S("12345678901234567890"), "1234567890", S("123456789012345678901234567890"));
-    test(S("12345678901234567890"), "12345678901234567890",
-         S("1234567890123456789012345678901234567890"));
-  }
-#if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), "", S());
-    test(S(), "12345", S("12345"));
-    test(S(), "1234567890", S("1234567890"));
-    test(S(), "12345678901234567890", S("12345678901234567890"));
+  test(S("12345"), "", S("12345"));
+  test(S("12345"), "12345", S("1234512345"));
+  test(S("12345"), "1234567890", S("123451234567890"));
+  test(S("12345"), "12345678901234567890", S("1234512345678901234567890"));
 
-    test(S("12345"), "", S("12345"));
-    test(S("12345"), "12345", S("1234512345"));
-    test(S("12345"), "1234567890", S("123451234567890"));
-    test(S("12345"), "12345678901234567890", S("1234512345678901234567890"));
+  test(S("1234567890"), "", S("1234567890"));
+  test(S("1234567890"), "12345", S("123456789012345"));
+  test(S("1234567890"), "1234567890", S("12345678901234567890"));
+  test(S("1234567890"), "12345678901234567890", S("123456789012345678901234567890"));
 
-    test(S("1234567890"), "", S("1234567890"));
-    test(S("1234567890"), "12345", S("123456789012345"));
-    test(S("1234567890"), "1234567890", S("12345678901234567890"));
-    test(S("1234567890"), "12345678901234567890", S("123456789012345678901234567890"));
+  test(S("12345678901234567890"), "", S("12345678901234567890"));
+  test(S("12345678901234567890"), "12345", S("1234567890123456789012345"));
+  test(S("12345678901234567890"), "1234567890", S("123456789012345678901234567890"));
+  test(S("12345678901234567890"), "12345678901234567890",
+        S("1234567890123456789012345678901234567890"));
+}
 
-    test(S("12345678901234567890"), "", S("12345678901234567890"));
-    test(S("12345678901234567890"), "12345", S("1234567890123456789012345"));
-    test(S("12345678901234567890"), "1234567890", S("123456789012345678901234567890"));
-    test(S("12345678901234567890"), "12345678901234567890",
-         S("1234567890123456789012345678901234567890"));
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
+#if TEST_STD_VER >= 11
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp
index 8ad98d48f03dd..c7ee062764c89 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp
@@ -26,57 +26,37 @@ test(S s, S str, S expected)
     assert(s == expected);
 }
 
-TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(), S(), S());
-    test(S(), S("12345"), S("12345"));
-    test(S(), S("1234567890"), S("1234567890"));
-    test(S(), S("12345678901234567890"), S("12345678901234567890"));
-
-    test(S("12345"), S(), S("12345"));
-    test(S("12345"), S("12345"), S("1234512345"));
-    test(S("12345"), S("1234567890"), S("123451234567890"));
-    test(S("12345"), S("12345678901234567890"), S("1234512345678901234567890"));
-
-    test(S("1234567890"), S(), S("1234567890"));
-    test(S("1234567890"), S("12345"), S("123456789012345"));
-    test(S("1234567890"), S("1234567890"), S("12345678901234567890"));
-    test(S("1234567890"), S("12345678901234567890"), S("123456789012345678901234567890"));
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(), S(), S());
+  test(S(), S("12345"), S("12345"));
+  test(S(), S("1234567890"), S("1234567890"));
+  test(S(), S("12345678901234567890"), S("12345678901234567890"));
+
+  test(S("12345"), S(), S("12345"));
+  test(S("12345"), S("12345"), S("1234512345"));
+  test(S("12345"), S("1234567890"), S("123451234567890"));
+  test(S("12345"), S("12345678901234567890"), S("1234512345678901234567890"));
+
+  test(S("1234567890"), S(), S("1234567890"));
+  test(S("1234567890"), S("12345"), S("123456789012345"));
+  test(S("1234567890"), S("1234567890"), S("12345678901234567890"));
+  test(S("1234567890"), S("12345678901234567890"), S("123456789012345678901234567890"));
+
+  test(S("12345678901234567890"), S(), S("12345678901234567890"));
+  test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
+  test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
+  test(S("12345678901234567890"), S("12345678901234567890"),
+        S("1234567890123456789012345678901234567890"));
+}
 
-    test(S("12345678901234567890"), S(), S("12345678901234567890"));
-    test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
-    test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
-    test(S("12345678901234567890"), S("12345678901234567890"),
-         S("1234567890123456789012345678901234567890"));
-  }
+TEST_CONSTEXPR_CXX20 bool test() {
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(), S(), S());
-    test(S(), S("12345"), S("12345"));
-    test(S(), S("1234567890"), S("1234567890"));
-    test(S(), S("12345678901234567890"), S("12345678901234567890"));
-
-    test(S("12345"), S(), S("12345"));
-    test(S("12345"), S("12345"), S("1234512345"));
-    test(S("12345"), S("1234567890"), S("123451234567890"));
-    test(S("12345"), S("12345678901234567890"), S("1234512345678901234567890"));
-
-    test(S("1234567890"), S(), S("1234567890"));
-    test(S("1234567890"), S("12345"), S("123456789012345"));
-    test(S("1234567890"), S("1234567890"), S("12345678901234567890"));
-    test(S("1234567890"), S("12345678901234567890"), S("123456789012345678901234567890"));
-
-    test(S("12345678901234567890"), S(), S("12345678901234567890"));
-    test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
-    test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
-    test(S("12345678901234567890"), S("12345678901234567890"),
-         S("1234567890123456789012345678901234567890"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
-#if TEST_STD_VER > 3
+#if TEST_STD_VER >= 11
   { // LWG 2946
     std::string s;
     s += {"abc", 1};

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string.pass.cpp
index 6c1afe64c7137..3cf5dbcc5d51f 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string.pass.cpp
@@ -283,7 +283,7 @@ void test() {
 #endif
   }
 
-#if TEST_STD_VER > 3
+#if TEST_STD_VER >= 11
   { // LWG 2946
     std::string s = "  ";
     s.replace(s.cbegin(), s.cend(), {"abc", 1});

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
index 0fd6c56ab8f8b..3e98052e14c44 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
@@ -381,7 +381,7 @@ void test() {
 #endif
   }
 
-#if TEST_STD_VER > 3
+#if TEST_STD_VER >= 11
   { // LWG 2946
     std::string s = " ";
     s.replace(0, 1, {"abc", 1});

diff  --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.pass.cpp
index c1fb5b6d17fd4..f11b7a09718ae 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_swap/swap.pass.cpp
@@ -31,46 +31,30 @@ test(S s1, S s2)
     assert(s2 == s1_);
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(""), S(""));
+  test(S(""), S("12345"));
+  test(S(""), S("1234567890"));
+  test(S(""), S("12345678901234567890"));
+  test(S("abcde"), S(""));
+  test(S("abcde"), S("12345"));
+  test(S("abcde"), S("1234567890"));
+  test(S("abcde"), S("12345678901234567890"));
+  test(S("abcdefghij"), S(""));
+  test(S("abcdefghij"), S("12345"));
+  test(S("abcdefghij"), S("1234567890"));
+  test(S("abcdefghij"), S("12345678901234567890"));
+  test(S("abcdefghijklmnopqrst"), S(""));
+  test(S("abcdefghijklmnopqrst"), S("12345"));
+  test(S("abcdefghijklmnopqrst"), S("1234567890"));
+  test(S("abcdefghijklmnopqrst"), S("12345678901234567890"));
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(""), S(""));
-    test(S(""), S("12345"));
-    test(S(""), S("1234567890"));
-    test(S(""), S("12345678901234567890"));
-    test(S("abcde"), S(""));
-    test(S("abcde"), S("12345"));
-    test(S("abcde"), S("1234567890"));
-    test(S("abcde"), S("12345678901234567890"));
-    test(S("abcdefghij"), S(""));
-    test(S("abcdefghij"), S("12345"));
-    test(S("abcdefghij"), S("1234567890"));
-    test(S("abcdefghij"), S("12345678901234567890"));
-    test(S("abcdefghijklmnopqrst"), S(""));
-    test(S("abcdefghijklmnopqrst"), S("12345"));
-    test(S("abcdefghijklmnopqrst"), S("1234567890"));
-    test(S("abcdefghijklmnopqrst"), S("12345678901234567890"));
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(""), S(""));
-    test(S(""), S("12345"));
-    test(S(""), S("1234567890"));
-    test(S(""), S("12345678901234567890"));
-    test(S("abcde"), S(""));
-    test(S("abcde"), S("12345"));
-    test(S("abcde"), S("1234567890"));
-    test(S("abcde"), S("12345678901234567890"));
-    test(S("abcdefghij"), S(""));
-    test(S("abcdefghij"), S("12345"));
-    test(S("abcdefghij"), S("1234567890"));
-    test(S("abcdefghij"), S("12345678901234567890"));
-    test(S("abcdefghijklmnopqrst"), S(""));
-    test(S("abcdefghijklmnopqrst"), S("12345"));
-    test(S("abcdefghijklmnopqrst"), S("1234567890"));
-    test(S("abcdefghijklmnopqrst"), S("12345678901234567890"));
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/pointer_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/pointer_string.pass.cpp
index edc218c9915de..bb1580d4f10f6 100644
--- a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/pointer_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/pointer_string.pass.cpp
@@ -24,46 +24,30 @@ test(const typename S::value_type* lhs, const S& rhs, bool x)
     assert((lhs != rhs) == x);
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test("", S(""), false);
+  test("", S("abcde"), true);
+  test("", S("abcdefghij"), true);
+  test("", S("abcdefghijklmnopqrst"), true);
+  test("abcde", S(""), true);
+  test("abcde", S("abcde"), false);
+  test("abcde", S("abcdefghij"), true);
+  test("abcde", S("abcdefghijklmnopqrst"), true);
+  test("abcdefghij", S(""), true);
+  test("abcdefghij", S("abcde"), true);
+  test("abcdefghij", S("abcdefghij"), false);
+  test("abcdefghij", S("abcdefghijklmnopqrst"), true);
+  test("abcdefghijklmnopqrst", S(""), true);
+  test("abcdefghijklmnopqrst", S("abcde"), true);
+  test("abcdefghijklmnopqrst", S("abcdefghij"), true);
+  test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), false);
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test("", S(""), false);
-    test("", S("abcde"), true);
-    test("", S("abcdefghij"), true);
-    test("", S("abcdefghijklmnopqrst"), true);
-    test("abcde", S(""), true);
-    test("abcde", S("abcde"), false);
-    test("abcde", S("abcdefghij"), true);
-    test("abcde", S("abcdefghijklmnopqrst"), true);
-    test("abcdefghij", S(""), true);
-    test("abcdefghij", S("abcde"), true);
-    test("abcdefghij", S("abcdefghij"), false);
-    test("abcdefghij", S("abcdefghijklmnopqrst"), true);
-    test("abcdefghijklmnopqrst", S(""), true);
-    test("abcdefghijklmnopqrst", S("abcde"), true);
-    test("abcdefghijklmnopqrst", S("abcdefghij"), true);
-    test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), false);
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test("", S(""), false);
-    test("", S("abcde"), true);
-    test("", S("abcdefghij"), true);
-    test("", S("abcdefghijklmnopqrst"), true);
-    test("abcde", S(""), true);
-    test("abcde", S("abcde"), false);
-    test("abcde", S("abcdefghij"), true);
-    test("abcde", S("abcdefghijklmnopqrst"), true);
-    test("abcdefghij", S(""), true);
-    test("abcdefghij", S("abcde"), true);
-    test("abcdefghij", S("abcdefghij"), false);
-    test("abcdefghij", S("abcdefghijklmnopqrst"), true);
-    test("abcdefghijklmnopqrst", S(""), true);
-    test("abcdefghijklmnopqrst", S("abcde"), true);
-    test("abcdefghijklmnopqrst", S("abcdefghij"), true);
-    test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), false);
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_pointer.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_pointer.pass.cpp
index a7d7b7a5d77f3..f2f51e2518187 100644
--- a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_pointer.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_pointer.pass.cpp
@@ -24,46 +24,30 @@ test(const S& lhs, const typename S::value_type* rhs, bool x)
     assert((lhs != rhs) == x);
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(""), "", false);
+  test(S(""), "abcde", true);
+  test(S(""), "abcdefghij", true);
+  test(S(""), "abcdefghijklmnopqrst", true);
+  test(S("abcde"), "", true);
+  test(S("abcde"), "abcde", false);
+  test(S("abcde"), "abcdefghij", true);
+  test(S("abcde"), "abcdefghijklmnopqrst", true);
+  test(S("abcdefghij"), "", true);
+  test(S("abcdefghij"), "abcde", true);
+  test(S("abcdefghij"), "abcdefghij", false);
+  test(S("abcdefghij"), "abcdefghijklmnopqrst", true);
+  test(S("abcdefghijklmnopqrst"), "", true);
+  test(S("abcdefghijklmnopqrst"), "abcde", true);
+  test(S("abcdefghijklmnopqrst"), "abcdefghij", true);
+  test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", false);
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(""), "", false);
-    test(S(""), "abcde", true);
-    test(S(""), "abcdefghij", true);
-    test(S(""), "abcdefghijklmnopqrst", true);
-    test(S("abcde"), "", true);
-    test(S("abcde"), "abcde", false);
-    test(S("abcde"), "abcdefghij", true);
-    test(S("abcde"), "abcdefghijklmnopqrst", true);
-    test(S("abcdefghij"), "", true);
-    test(S("abcdefghij"), "abcde", true);
-    test(S("abcdefghij"), "abcdefghij", false);
-    test(S("abcdefghij"), "abcdefghijklmnopqrst", true);
-    test(S("abcdefghijklmnopqrst"), "", true);
-    test(S("abcdefghijklmnopqrst"), "abcde", true);
-    test(S("abcdefghijklmnopqrst"), "abcdefghij", true);
-    test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", false);
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(""), "", false);
-    test(S(""), "abcde", true);
-    test(S(""), "abcdefghij", true);
-    test(S(""), "abcdefghijklmnopqrst", true);
-    test(S("abcde"), "", true);
-    test(S("abcde"), "abcde", false);
-    test(S("abcde"), "abcdefghij", true);
-    test(S("abcde"), "abcdefghijklmnopqrst", true);
-    test(S("abcdefghij"), "", true);
-    test(S("abcdefghij"), "abcde", true);
-    test(S("abcdefghij"), "abcdefghij", false);
-    test(S("abcdefghij"), "abcdefghijklmnopqrst", true);
-    test(S("abcdefghijklmnopqrst"), "", true);
-    test(S("abcdefghijklmnopqrst"), "abcde", true);
-    test(S("abcdefghijklmnopqrst"), "abcdefghij", true);
-    test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", false);
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_string.pass.cpp
index b359133c4e3e1..2f74920ee3b78 100644
--- a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_string.pass.cpp
@@ -25,46 +25,30 @@ test(const S& lhs, const S& rhs, bool x)
     assert((lhs != rhs) == x);
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  test(S(""), S(""), false);
+  test(S(""), S("abcde"), true);
+  test(S(""), S("abcdefghij"), true);
+  test(S(""), S("abcdefghijklmnopqrst"), true);
+  test(S("abcde"), S(""), true);
+  test(S("abcde"), S("abcde"), false);
+  test(S("abcde"), S("abcdefghij"), true);
+  test(S("abcde"), S("abcdefghijklmnopqrst"), true);
+  test(S("abcdefghij"), S(""), true);
+  test(S("abcdefghij"), S("abcde"), true);
+  test(S("abcdefghij"), S("abcdefghij"), false);
+  test(S("abcdefghij"), S("abcdefghijklmnopqrst"), true);
+  test(S("abcdefghijklmnopqrst"), S(""), true);
+  test(S("abcdefghijklmnopqrst"), S("abcde"), true);
+  test(S("abcdefghijklmnopqrst"), S("abcdefghij"), true);
+  test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false);
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    test(S(""), S(""), false);
-    test(S(""), S("abcde"), true);
-    test(S(""), S("abcdefghij"), true);
-    test(S(""), S("abcdefghijklmnopqrst"), true);
-    test(S("abcde"), S(""), true);
-    test(S("abcde"), S("abcde"), false);
-    test(S("abcde"), S("abcdefghij"), true);
-    test(S("abcde"), S("abcdefghijklmnopqrst"), true);
-    test(S("abcdefghij"), S(""), true);
-    test(S("abcdefghij"), S("abcde"), true);
-    test(S("abcdefghij"), S("abcdefghij"), false);
-    test(S("abcdefghij"), S("abcdefghijklmnopqrst"), true);
-    test(S("abcdefghijklmnopqrst"), S(""), true);
-    test(S("abcdefghijklmnopqrst"), S("abcde"), true);
-    test(S("abcdefghijklmnopqrst"), S("abcdefghij"), true);
-    test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false);
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    test(S(""), S(""), false);
-    test(S(""), S("abcde"), true);
-    test(S(""), S("abcdefghij"), true);
-    test(S(""), S("abcdefghijklmnopqrst"), true);
-    test(S("abcde"), S(""), true);
-    test(S("abcde"), S("abcde"), false);
-    test(S("abcde"), S("abcdefghij"), true);
-    test(S("abcde"), S("abcdefghijklmnopqrst"), true);
-    test(S("abcdefghij"), S(""), true);
-    test(S("abcdefghij"), S("abcde"), true);
-    test(S("abcdefghij"), S("abcdefghij"), false);
-    test(S("abcdefghij"), S("abcdefghijklmnopqrst"), true);
-    test(S("abcdefghijklmnopqrst"), S(""), true);
-    test(S("abcdefghijklmnopqrst"), S("abcde"), true);
-    test(S("abcdefghijklmnopqrst"), S("abcdefghij"), true);
-    test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false);
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_string_view.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_string_view.pass.cpp
index 2f94c4a301839..744c883e34e0e 100644
--- a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_string_view.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_string_view.pass.cpp
@@ -23,48 +23,31 @@ test(const S& lhs, SV rhs, bool x)
     assert((lhs != rhs) == x);
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  typedef std::string_view SV;
+  test(S(""), SV(""), false);
+  test(S(""), SV("abcde"), true);
+  test(S(""), SV("abcdefghij"), true);
+  test(S(""), SV("abcdefghijklmnopqrst"), true);
+  test(S("abcde"), SV(""), true);
+  test(S("abcde"), SV("abcde"), false);
+  test(S("abcde"), SV("abcdefghij"), true);
+  test(S("abcde"), SV("abcdefghijklmnopqrst"), true);
+  test(S("abcdefghij"), SV(""), true);
+  test(S("abcdefghij"), SV("abcde"), true);
+  test(S("abcdefghij"), SV("abcdefghij"), false);
+  test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), true);
+  test(S("abcdefghijklmnopqrst"), SV(""), true);
+  test(S("abcdefghijklmnopqrst"), SV("abcde"), true);
+  test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), true);
+  test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), false);
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    typedef std::string SV;
-    test(S(""), SV(""), false);
-    test(S(""), SV("abcde"), true);
-    test(S(""), SV("abcdefghij"), true);
-    test(S(""), SV("abcdefghijklmnopqrst"), true);
-    test(S("abcde"), SV(""), true);
-    test(S("abcde"), SV("abcde"), false);
-    test(S("abcde"), SV("abcdefghij"), true);
-    test(S("abcde"), SV("abcdefghijklmnopqrst"), true);
-    test(S("abcdefghij"), SV(""), true);
-    test(S("abcdefghij"), SV("abcde"), true);
-    test(S("abcdefghij"), SV("abcdefghij"), false);
-    test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), true);
-    test(S("abcdefghijklmnopqrst"), SV(""), true);
-    test(S("abcdefghijklmnopqrst"), SV("abcde"), true);
-    test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), true);
-    test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), false);
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    typedef std::basic_string_view<char, std::char_traits<char>> SV;
-    test(S(""), SV(""), false);
-    test(S(""), SV("abcde"), true);
-    test(S(""), SV("abcdefghij"), true);
-    test(S(""), SV("abcdefghijklmnopqrst"), true);
-    test(S("abcde"), SV(""), true);
-    test(S("abcde"), SV("abcde"), false);
-    test(S("abcde"), SV("abcdefghij"), true);
-    test(S("abcde"), SV("abcdefghijklmnopqrst"), true);
-    test(S("abcdefghij"), SV(""), true);
-    test(S("abcdefghij"), SV("abcde"), true);
-    test(S("abcdefghij"), SV("abcdefghij"), false);
-    test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), true);
-    test(S("abcdefghijklmnopqrst"), SV(""), true);
-    test(S("abcdefghijklmnopqrst"), SV("abcde"), true);
-    test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), true);
-    test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), false);
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_view_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_view_string.pass.cpp
index 3877f66e9835b..7f5bb20cc6389 100644
--- a/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_view_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_view_string.pass.cpp
@@ -23,48 +23,31 @@ test(SV lhs, const S& rhs, bool x)
     assert((lhs != rhs) == x);
 }
 
+template <class S>
+TEST_CONSTEXPR_CXX20 void test_string() {
+  typedef std::string_view SV;
+  test(SV(""), S(""), false);
+  test(SV(""), S("abcde"), true);
+  test(SV(""), S("abcdefghij"), true);
+  test(SV(""), S("abcdefghijklmnopqrst"), true);
+  test(SV("abcde"), S(""), true);
+  test(SV("abcde"), S("abcde"), false);
+  test(SV("abcde"), S("abcdefghij"), true);
+  test(SV("abcde"), S("abcdefghijklmnopqrst"), true);
+  test(SV("abcdefghij"), S(""), true);
+  test(SV("abcdefghij"), S("abcde"), true);
+  test(SV("abcdefghij"), S("abcdefghij"), false);
+  test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), true);
+  test(SV("abcdefghijklmnopqrst"), S(""), true);
+  test(SV("abcdefghijklmnopqrst"), S("abcde"), true);
+  test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), true);
+  test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false);
+}
+
 TEST_CONSTEXPR_CXX20 bool test() {
-  {
-    typedef std::string S;
-    typedef std::string_view SV;
-    test(SV(""), S(""), false);
-    test(SV(""), S("abcde"), true);
-    test(SV(""), S("abcdefghij"), true);
-    test(SV(""), S("abcdefghijklmnopqrst"), true);
-    test(SV("abcde"), S(""), true);
-    test(SV("abcde"), S("abcde"), false);
-    test(SV("abcde"), S("abcdefghij"), true);
-    test(SV("abcde"), S("abcdefghijklmnopqrst"), true);
-    test(SV("abcdefghij"), S(""), true);
-    test(SV("abcdefghij"), S("abcde"), true);
-    test(SV("abcdefghij"), S("abcdefghij"), false);
-    test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), true);
-    test(SV("abcdefghijklmnopqrst"), S(""), true);
-    test(SV("abcdefghijklmnopqrst"), S("abcde"), true);
-    test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), true);
-    test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false);
-  }
+  test_string<std::string>();
 #if TEST_STD_VER >= 11
-  {
-    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
-    typedef std::basic_string_view<char, std::char_traits<char>> SV;
-    test(SV(""), S(""), false);
-    test(SV(""), S("abcde"), true);
-    test(SV(""), S("abcdefghij"), true);
-    test(SV(""), S("abcdefghijklmnopqrst"), true);
-    test(SV("abcde"), S(""), true);
-    test(SV("abcde"), S("abcde"), false);
-    test(SV("abcde"), S("abcdefghij"), true);
-    test(SV("abcde"), S("abcdefghijklmnopqrst"), true);
-    test(SV("abcdefghij"), S(""), true);
-    test(SV("abcdefghij"), S("abcde"), true);
-    test(SV("abcdefghij"), S("abcdefghij"), false);
-    test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), true);
-    test(SV("abcdefghijklmnopqrst"), S(""), true);
-    test(SV("abcdefghijklmnopqrst"), S("abcde"), true);
-    test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), true);
-    test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false);
-  }
+  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
 #endif
 
   return true;

diff  --git a/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
index 34ff149baa4d1..e3b5756b4e974 100644
--- a/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
@@ -376,7 +376,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
   }
 #endif
 
-#if TEST_STD_VER > 3
+#if TEST_STD_VER >= 11
   { // LWG 2946
     std::string s = " !";
     assert(s.compare(0, 1, {"abc", 1}) < 0);

diff  --git a/libcxx/test/std/strings/basic.string/string.ops/string_compare/string.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_compare/string.pass.cpp
index d5f75d3c74cd6..e81946e215bee 100644
--- a/libcxx/test/std/strings/basic.string/string.ops/string_compare/string.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.ops/string_compare/string.pass.cpp
@@ -75,7 +75,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
   }
 #endif
 
-#if TEST_STD_VER > 3
+#if TEST_STD_VER >= 11
   { // LWG 2946
     std::string s = " !";
     assert(s.compare({"abc", 1}) < 0);

diff  --git a/libcxx/test/std/strings/basic.string/string.ops/string_find.first.not.of/string_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_find.first.not.of/string_size.pass.cpp
index 65179f6f448ae..df0273d594335 100644
--- a/libcxx/test/std/strings/basic.string/string.ops/string_find.first.not.of/string_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.ops/string_find.first.not.of/string_size.pass.cpp
@@ -156,7 +156,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
   }
 #endif
 
-#if TEST_STD_VER > 3
+#if TEST_STD_VER >= 11
   { // LWG 2946
     std::string s = " !";
     assert(s.find_first_not_of({"abc", 1}) == 0);

diff  --git a/libcxx/test/std/strings/basic.string/string.ops/string_find.first.of/string_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_find.first.of/string_size.pass.cpp
index 3c5511ba85957..68b5afc06a40d 100644
--- a/libcxx/test/std/strings/basic.string/string.ops/string_find.first.of/string_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.ops/string_find.first.of/string_size.pass.cpp
@@ -156,7 +156,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
   }
 #endif
 
-#if TEST_STD_VER > 3
+#if TEST_STD_VER >= 11
   { // LWG 2946
     std::string s = " !";
     assert(s.find_first_of({"abc", 1}) == std::string::npos);

diff  --git a/libcxx/test/std/strings/basic.string/string.ops/string_find.last.not.of/string_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_find.last.not.of/string_size.pass.cpp
index 015f4036c6182..b228baa791b5e 100644
--- a/libcxx/test/std/strings/basic.string/string.ops/string_find.last.not.of/string_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.ops/string_find.last.not.of/string_size.pass.cpp
@@ -156,7 +156,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
   }
 #endif
 
-#if TEST_STD_VER > 3
+#if TEST_STD_VER >= 11
   { // LWG 2946
     std::string s = " !";
     assert(s.find_last_not_of({"abc", 1}) == s.size() - 1);

diff  --git a/libcxx/test/std/strings/basic.string/string.ops/string_find.last.of/string_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_find.last.of/string_size.pass.cpp
index 848b796125b21..5d0d63091a28a 100644
--- a/libcxx/test/std/strings/basic.string/string.ops/string_find.last.of/string_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.ops/string_find.last.of/string_size.pass.cpp
@@ -156,7 +156,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
   }
 #endif
 
-#if TEST_STD_VER > 3
+#if TEST_STD_VER >= 11
   { // LWG 2946
     std::string s = " !";
     assert(s.find_last_of({"abc", 1}) == std::string::npos);

diff  --git a/libcxx/test/std/strings/basic.string/string.ops/string_find/string_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_find/string_size.pass.cpp
index 5dd223ce4219d..af0fdd3340cec 100644
--- a/libcxx/test/std/strings/basic.string/string.ops/string_find/string_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.ops/string_find/string_size.pass.cpp
@@ -156,7 +156,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
   }
 #endif
 
-#if TEST_STD_VER > 3
+#if TEST_STD_VER >= 11
   { // LWG 2946
     std::string s = " !";
     assert(s.find({"abc", 1}) == std::string::npos);

diff  --git a/libcxx/test/std/strings/basic.string/string.ops/string_rfind/string_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_rfind/string_size.pass.cpp
index 8337ebe82e621..45d8a24b97388 100644
--- a/libcxx/test/std/strings/basic.string/string.ops/string_rfind/string_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.ops/string_rfind/string_size.pass.cpp
@@ -156,7 +156,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
   }
 #endif
 
-#if TEST_STD_VER > 3
+#if TEST_STD_VER >= 11
   { // LWG 2946
     std::string s = " !";
     assert(s.rfind({"abc", 1}) == std::string::npos);


        


More information about the libcxx-commits mailing list