[libcxx-commits] [libcxx] [libc++] Move a bunch of tests from libcxx/test/libcxx to libcxx/test/std (PR #150199)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 23 02:45:00 PDT 2025


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/150199

These tests test standard behaviour, so they shouldn't be in the libc++-specific tests.


>From d0343c6848de18cf94ed5c9f9a50cd1a7014549c Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Wed, 23 Jul 2025 11:44:11 +0200
Subject: [PATCH] [libc++] Move a bunch of tests from libcxx/test/libcxx to
 libcxx/test/std

---
 .../forwardlist/bool-conversion.pass.cpp      | 37 ------------
 .../vector.cons/construct_iter_iter.pass.cpp  | 56 ------------------
 .../construct_iter_iter_alloc.pass.cpp        | 59 -------------------
 .../map/find.modules.compile.pass.mm          |  0
 .../forwardlist.erasure/erase.pass.cpp        | 18 ++++++
 .../vector/erase.modules.compile.pass.mm      |  0
 .../vector.cons/construct_iter_iter.pass.cpp  | 31 +++++++++-
 .../construct_iter_iter_alloc.pass.cpp        | 33 ++++++++++-
 8 files changed, 80 insertions(+), 154 deletions(-)
 delete mode 100644 libcxx/test/libcxx/containers/sequences/forwardlist/bool-conversion.pass.cpp
 delete mode 100644 libcxx/test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
 delete mode 100644 libcxx/test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
 rename libcxx/test/{libcxx => std}/containers/associative/map/find.modules.compile.pass.mm (100%)
 rename libcxx/test/{libcxx => std}/containers/sequences/vector/erase.modules.compile.pass.mm (100%)

diff --git a/libcxx/test/libcxx/containers/sequences/forwardlist/bool-conversion.pass.cpp b/libcxx/test/libcxx/containers/sequences/forwardlist/bool-conversion.pass.cpp
deleted file mode 100644
index 237b0f155c7be..0000000000000
--- a/libcxx/test/libcxx/containers/sequences/forwardlist/bool-conversion.pass.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// REQUIRES: std-at-least-c++20
-
-// <forward_list>
-
-// This test shows the effect of implementing `LWG4135`, before it this code
-// was ill-formed, as the predicate is not bool. `LWG4135` suggests that
-// std::erase explicitly specifying the lambda's return type as bool.
-
-#include <forward_list>
-
-struct Bool {
-  Bool()            = default;
-  Bool(const Bool&) = delete;
-  operator bool() const { return true; }
-};
-
-struct Int {
-  Bool& operator==(Int) const {
-    static Bool b;
-    return b;
-  }
-};
-
-int main(int, char**) {
-  std::forward_list<Int> l;
-  std::erase(l, Int{});
-
-  return 0;
-}
diff --git a/libcxx/test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp b/libcxx/test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
deleted file mode 100644
index 9e3fb886e6075..0000000000000
--- a/libcxx/test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <vector>
-
-// template <class InputIter> vector(InputIter first, InputIter last);
-
-#include <vector>
-#include <cassert>
-
-#include "test_macros.h"
-#include "min_allocator.h"
-
-void test_ctor_under_alloc() {
-  int arr1[] = {42};
-  int arr2[] = {1, 101, 42};
-  {
-    typedef std::vector<int, cpp03_allocator<int> > C;
-    typedef C::allocator_type Alloc;
-    {
-      Alloc::construct_called = false;
-      C v(arr1, arr1 + 1);
-      assert(Alloc::construct_called);
-    }
-    {
-      Alloc::construct_called = false;
-      C v(arr2, arr2 + 3);
-      assert(Alloc::construct_called);
-    }
-  }
-  {
-    typedef std::vector<int, cpp03_overload_allocator<int> > C;
-    typedef C::allocator_type Alloc;
-    {
-      Alloc::construct_called = false;
-      C v(arr1, arr1 + 1);
-      assert(Alloc::construct_called);
-    }
-    {
-      Alloc::construct_called = false;
-      C v(arr2, arr2 + 3);
-      assert(Alloc::construct_called);
-    }
-  }
-}
-
-int main(int, char**) {
-  test_ctor_under_alloc();
-
-  return 0;
-}
diff --git a/libcxx/test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp b/libcxx/test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
deleted file mode 100644
index fa1bd2d4fda32..0000000000000
--- a/libcxx/test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <vector>
-
-// template <class InputIter> vector(InputIter first, InputIter last,
-//                                   const allocator_type& a);
-
-#include <vector>
-#include <cassert>
-
-#include "test_macros.h"
-#include "min_allocator.h"
-
-void test_ctor_under_alloc() {
-  int arr1[] = {42};
-  int arr2[] = {1, 101, 42};
-  {
-    typedef std::vector<int, cpp03_allocator<int> > C;
-    typedef C::allocator_type Alloc;
-    Alloc a;
-    {
-      Alloc::construct_called = false;
-      C v(arr1, arr1 + 1, a);
-      assert(Alloc::construct_called);
-    }
-    {
-      Alloc::construct_called = false;
-      C v(arr2, arr2 + 3, a);
-      assert(Alloc::construct_called);
-    }
-  }
-  {
-    typedef std::vector<int, cpp03_overload_allocator<int> > C;
-    typedef C::allocator_type Alloc;
-    Alloc a;
-    {
-      Alloc::construct_called = false;
-      C v(arr1, arr1 + 1, a);
-      assert(Alloc::construct_called);
-    }
-    {
-      Alloc::construct_called = false;
-      C v(arr2, arr2 + 3, a);
-      assert(Alloc::construct_called);
-    }
-  }
-}
-
-int main(int, char**) {
-  test_ctor_under_alloc();
-
-  return 0;
-}
diff --git a/libcxx/test/libcxx/containers/associative/map/find.modules.compile.pass.mm b/libcxx/test/std/containers/associative/map/find.modules.compile.pass.mm
similarity index 100%
rename from libcxx/test/libcxx/containers/associative/map/find.modules.compile.pass.mm
rename to libcxx/test/std/containers/associative/map/find.modules.compile.pass.mm
diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.erasure/erase.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.erasure/erase.pass.cpp
index 86d7769fe16ee..630e01a0f36cc 100644
--- a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.erasure/erase.pass.cpp
+++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.erasure/erase.pass.cpp
@@ -69,6 +69,24 @@ TEST_CONSTEXPR_CXX26 bool test() {
   test<std::forward_list<long>>();
   test<std::forward_list<double>>();
 
+  { // Ensure that the result of operator== is converted to bool
+    struct Bool {
+      Bool()            = default;
+      Bool(const Bool&) = delete;
+      operator bool() const { return true; }
+    };
+
+    struct Int {
+      Bool& operator==(Int) const {
+        static Bool b;
+        return b;
+      }
+    };
+
+    std::forward_list<Int> l;
+    std::erase(l, Int{});
+  }
+
   return true;
 }
 
diff --git a/libcxx/test/libcxx/containers/sequences/vector/erase.modules.compile.pass.mm b/libcxx/test/std/containers/sequences/vector/erase.modules.compile.pass.mm
similarity index 100%
rename from libcxx/test/libcxx/containers/sequences/vector/erase.modules.compile.pass.mm
rename to libcxx/test/std/containers/sequences/vector/erase.modules.compile.pass.mm
diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
index bac2ea2b4ca1e..6549735f7b511 100644
--- a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
@@ -127,9 +127,9 @@ TEST_CONSTEXPR_CXX20 void emplaceable_concept_tests() {
 }
 
 void test_ctor_under_alloc() {
-#if TEST_STD_VER >= 11
   int arr1[] = {42};
   int arr2[] = {1, 101, 42};
+#if TEST_STD_VER >= 11
   {
     using C  = TCT::vector<>;
     using It = forward_iterator<int*>;
@@ -155,6 +155,35 @@ void test_ctor_under_alloc() {
     }
   }
 #endif
+  // FIXME: This is mostly the same test as above, just worse. They should be merged.
+  {
+    typedef std::vector<int, cpp03_allocator<int> > C;
+    typedef C::allocator_type Alloc;
+    {
+      Alloc::construct_called = false;
+      C v(arr1, arr1 + 1);
+      assert(Alloc::construct_called);
+    }
+    {
+      Alloc::construct_called = false;
+      C v(arr2, arr2 + 3);
+      assert(Alloc::construct_called);
+    }
+  }
+  {
+    typedef std::vector<int, cpp03_overload_allocator<int> > C;
+    typedef C::allocator_type Alloc;
+    {
+      Alloc::construct_called = false;
+      C v(arr1, arr1 + 1);
+      assert(Alloc::construct_called);
+    }
+    {
+      Alloc::construct_called = false;
+      C v(arr2, arr2 + 3);
+      assert(Alloc::construct_called);
+    }
+  }
 }
 
 // In C++03, you can't instantiate a template with a local type.
diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
index de325040f4a19..019f427c006a1 100644
--- a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
@@ -141,9 +141,9 @@ TEST_CONSTEXPR_CXX20 void emplaceable_concept_tests() {
 }
 
 void test_ctor_under_alloc() {
-#if TEST_STD_VER >= 11
   int arr1[] = {42};
   int arr2[] = {1, 101, 42};
+#if TEST_STD_VER >= 11
   {
     using C     = TCT::vector<>;
     using It    = forward_iterator<int*>;
@@ -173,6 +173,37 @@ void test_ctor_under_alloc() {
     }
   }
 #endif
+  // FIXME: This is mostly the same test as above, just worse. They should be merged.
+  {
+    typedef std::vector<int, cpp03_allocator<int> > C;
+    typedef C::allocator_type Alloc;
+    Alloc a;
+    {
+      Alloc::construct_called = false;
+      C v(arr1, arr1 + 1, a);
+      assert(Alloc::construct_called);
+    }
+    {
+      Alloc::construct_called = false;
+      C v(arr2, arr2 + 3, a);
+      assert(Alloc::construct_called);
+    }
+  }
+  {
+    typedef std::vector<int, cpp03_overload_allocator<int> > C;
+    typedef C::allocator_type Alloc;
+    Alloc a;
+    {
+      Alloc::construct_called = false;
+      C v(arr1, arr1 + 1, a);
+      assert(Alloc::construct_called);
+    }
+    {
+      Alloc::construct_called = false;
+      C v(arr2, arr2 + 3, a);
+      assert(Alloc::construct_called);
+    }
+  }
 }
 
 TEST_CONSTEXPR_CXX20 bool test() {



More information about the libcxx-commits mailing list