[libcxx-commits] [libcxx] [libc++] Update container adaptors' tests (PR #224810)

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Sat Sep 19 00:43:06 PDT 2026


https://github.com/H-G-Hristov updated https://github.com/llvm/llvm-project/pull/224810

>From 4ff1360e9ef7031fe6ce8f01716f7ddbbf12af13 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Fri, 18 Sep 2026 10:18:31 +0300
Subject: [PATCH] [libc++] Update container adaptor tests

1. Improves the error message for LWG2566.
2. Converts compile.fail.cpp tests to verify.cpp tests.
3. Updates tests.
4. Removes redundant tests.

References:
- https://wg21.link/lwg2566
- https://wg21.link/containers.adaptors
---
 libcxx/include/__flat_map/flat_map.h          |  6 ++--
 libcxx/include/__flat_map/flat_multimap.h     |  6 ++--
 libcxx/include/__flat_set/flat_multiset.h     |  3 +-
 libcxx/include/__flat_set/flat_set.h          |  3 +-
 libcxx/include/queue                          |  6 ++--
 libcxx/include/stack                          |  3 +-
 .../flat.map/types.verify.cpp                 | 33 +++++++++++++++++
 .../flat.multimap/types.verify.cpp            | 33 +++++++++++++++++
 .../flat.multiset/types.verify.cpp            | 26 ++++++++++++++
 .../flat.set/types.verify.cpp                 | 26 ++++++++++++++
 .../priqueue.members/empty.verify.cpp         | 22 ------------
 ...ypes.compile.fail.cpp => types.verify.cpp} |  6 ++--
 .../queue/queue.defn/types.compile.fail.cpp   | 20 -----------
 .../{empty.verify.cpp => types.verify.cpp}    | 11 +++---
 .../stack/stack.defn/types.compile.fail.cpp   | 35 -------------------
 .../{empty.verify.cpp => types.verify.cpp}    | 11 +++---
 16 files changed, 146 insertions(+), 104 deletions(-)
 create mode 100644 libcxx/test/std/containers/container.adaptors/flat.map/types.verify.cpp
 create mode 100644 libcxx/test/std/containers/container.adaptors/flat.multimap/types.verify.cpp
 create mode 100644 libcxx/test/std/containers/container.adaptors/flat.multiset/types.verify.cpp
 create mode 100644 libcxx/test/std/containers/container.adaptors/flat.set/types.verify.cpp
 delete mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/empty.verify.cpp
 rename libcxx/test/std/containers/container.adaptors/priority.queue/{types.compile.fail.cpp => types.verify.cpp} (75%)
 delete mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.defn/types.compile.fail.cpp
 rename libcxx/test/std/containers/container.adaptors/queue/queue.defn/{empty.verify.cpp => types.verify.cpp} (63%)
 delete mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.defn/types.compile.fail.cpp
 rename libcxx/test/std/containers/container.adaptors/stack/stack.defn/{empty.verify.cpp => types.verify.cpp} (63%)

diff --git a/libcxx/include/__flat_map/flat_map.h b/libcxx/include/__flat_map/flat_map.h
index 50487cada24c0..6934a1e10c421 100644
--- a/libcxx/include/__flat_map/flat_map.h
+++ b/libcxx/include/__flat_map/flat_map.h
@@ -85,8 +85,10 @@ class flat_map {
   template <class, class, class, class, class>
   friend class flat_map;
 
-  static_assert(is_same_v<_Key, typename _KeyContainer::value_type>);
-  static_assert(is_same_v<_Tp, typename _MappedContainer::value_type>);
+  static_assert(is_same_v<_Key, typename _KeyContainer::value_type>,
+                "The stored elements key type must match the underlying container's key value_type.");
+  static_assert(is_same_v<_Tp, typename _MappedContainer::value_type>,
+                "The stored elements mapped type must match the underlying container's mapped value_type.");
   static_assert(!is_same_v<_KeyContainer, std::vector<bool>>, "vector<bool> is not a sequence container");
   static_assert(!is_same_v<_MappedContainer, std::vector<bool>>, "vector<bool> is not a sequence container");
 
diff --git a/libcxx/include/__flat_map/flat_multimap.h b/libcxx/include/__flat_map/flat_multimap.h
index bd3ec81b98b7f..6b0afb6ce5727 100644
--- a/libcxx/include/__flat_map/flat_multimap.h
+++ b/libcxx/include/__flat_map/flat_multimap.h
@@ -82,8 +82,10 @@ class flat_multimap {
   template <class, class, class, class, class>
   friend class flat_multimap;
 
-  static_assert(is_same_v<_Key, typename _KeyContainer::value_type>);
-  static_assert(is_same_v<_Tp, typename _MappedContainer::value_type>);
+  static_assert(is_same_v<_Key, typename _KeyContainer::value_type>,
+                "The stored elements key type must match the underlying container's key value_type.");
+  static_assert(is_same_v<_Tp, typename _MappedContainer::value_type>,
+                "The stored elements mapped type must match the underlying container's mapped value_type.");
   static_assert(!is_same_v<_KeyContainer, std::vector<bool>>, "vector<bool> is not a sequence container");
   static_assert(!is_same_v<_MappedContainer, std::vector<bool>>, "vector<bool> is not a sequence container");
 
diff --git a/libcxx/include/__flat_set/flat_multiset.h b/libcxx/include/__flat_set/flat_multiset.h
index 4324645fb8445..27e37313e5301 100644
--- a/libcxx/include/__flat_set/flat_multiset.h
+++ b/libcxx/include/__flat_set/flat_multiset.h
@@ -74,7 +74,8 @@ class flat_multiset {
 
   friend __flat_set_utils;
 
-  static_assert(is_same_v<_Key, typename _KeyContainer::value_type>);
+  static_assert(is_same_v<_Key, typename _KeyContainer::value_type>,
+                "The stored elements key type must match the underlying container's key value_type.");
   static_assert(!is_same_v<_KeyContainer, std::vector<bool>>, "vector<bool> is not a sequence container");
 
 public:
diff --git a/libcxx/include/__flat_set/flat_set.h b/libcxx/include/__flat_set/flat_set.h
index 57c3926e33b68..0f448b6eea7d1 100644
--- a/libcxx/include/__flat_set/flat_set.h
+++ b/libcxx/include/__flat_set/flat_set.h
@@ -76,7 +76,8 @@ class flat_set {
 
   friend __flat_set_utils;
 
-  static_assert(is_same_v<_Key, typename _KeyContainer::value_type>);
+  static_assert(is_same_v<_Key, typename _KeyContainer::value_type>,
+                "The stored elements key type must match the underlying container's key value_type.");
   static_assert(!is_same_v<_KeyContainer, std::vector<bool>>, "vector<bool> is not a sequence container");
 
   using __key_iterator _LIBCPP_NODEBUG = typename _KeyContainer::const_iterator;
diff --git a/libcxx/include/queue b/libcxx/include/queue
index 1e46cd4e8cbb4..cd14423b407ab 100644
--- a/libcxx/include/queue
+++ b/libcxx/include/queue
@@ -306,7 +306,8 @@ public:
   typedef typename container_type::reference reference;
   typedef typename container_type::const_reference const_reference;
   typedef typename container_type::size_type size_type;
-  static_assert(is_same<_Tp, value_type>::value, "");
+  static_assert(is_same<_Tp, value_type>::value,
+                "The stored elements type must match the underlying container's value_type.");
 
 protected:
   container_type c;
@@ -524,7 +525,8 @@ public:
   typedef typename container_type::reference reference;
   typedef typename container_type::const_reference const_reference;
   typedef typename container_type::size_type size_type;
-  static_assert(is_same<_Tp, value_type>::value, "");
+  static_assert(is_same<_Tp, value_type>::value,
+                "The stored elements type must match the underlying container's value_type.");
 
 protected:
   container_type c;
diff --git a/libcxx/include/stack b/libcxx/include/stack
index 7b3fcf17bf624..51e2cee85ac2a 100644
--- a/libcxx/include/stack
+++ b/libcxx/include/stack
@@ -160,7 +160,8 @@ public:
   typedef typename container_type::reference reference;
   typedef typename container_type::const_reference const_reference;
   typedef typename container_type::size_type size_type;
-  static_assert(is_same<_Tp, value_type>::value, "");
+  static_assert(is_same<_Tp, value_type>::value,
+                "The stored elements type must match the underlying container's value_type.");
 
 protected:
   container_type c;
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/types.verify.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/types.verify.cpp
new file mode 100644
index 0000000000000..4227fe5f635a1
--- /dev/null
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/types.verify.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// 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++23
+
+// <flat_map>
+
+//  template<class Key, class T, class Compare = less<Key>,
+//           class KeyContainer = vector<Key>, class MappedContainer = vector<T>>
+//    class flat_map;
+
+#include <flat_map>
+#include <functional>
+#include <vector>
+
+void test() {
+  // expected-error-re@*:* {{static assertion failed{{.*}}The stored elements key type must match the underlying container's key value_type.}}
+  std::flat_map<double, int, std::less<double>, std::vector<char>> fm1;
+
+  // expected-error-re@*:* {{static assertion failed{{.*}}The stored elements mapped type must match the underlying container's mapped value_type.}}
+  std::flat_map<int, double, std::less<int>, std::vector<int>, std::vector<char>> fm2;
+
+  // expected-error-re@*:* {{static assertion failed{{.*}}vector<bool> is not a sequence container}}
+  std::flat_map<bool, int, std::less<bool>, std::vector<bool>> fm3;
+
+  // expected-error-re@*:* {{static assertion failed{{.*}}vector<bool> is not a sequence container}}
+  std::flat_map<int, bool, std::less<int>, std::vector<int>, std::vector<bool>> fm4;
+}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/types.verify.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/types.verify.cpp
new file mode 100644
index 0000000000000..a3b73fff331b6
--- /dev/null
+++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/types.verify.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// 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++23
+
+// <flat_map>
+
+//  template<class Key, class T, class Compare = less<Key>,
+//           class KeyContainer = vector<Key>, class MappedContainer = vector<T>>
+//    class flat_multimap;
+
+#include <flat_map>
+#include <functional>
+#include <vector>
+
+void test_flat_multimap() {
+  // expected-error-re@*:* {{static assertion failed{{.*}}The stored elements key type must match the underlying container's key value_type.}}
+  std::flat_multimap<double, int, std::less<double>, std::vector<char>> fmm1;
+
+  // expected-error-re@*:* {{static assertion failed{{.*}}The stored elements mapped type must match the underlying container's mapped value_type.}}
+  std::flat_multimap<int, double, std::less<int>, std::vector<int>, std::vector<char>> fmm2;
+
+  // expected-error-re@*:* {{static assertion failed{{.*}}vector<bool> is not a sequence container}}
+  std::flat_multimap<bool, int, std::less<bool>, std::vector<bool>> fmm3;
+
+  // expected-error-re@*:* {{static assertion failed{{.*}}vector<bool> is not a sequence container}}
+  std::flat_multimap<int, bool, std::less<int>, std::vector<int>, std::vector<bool>> fmm4;
+}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.multiset/types.verify.cpp b/libcxx/test/std/containers/container.adaptors/flat.multiset/types.verify.cpp
new file mode 100644
index 0000000000000..d837af3abae24
--- /dev/null
+++ b/libcxx/test/std/containers/container.adaptors/flat.multiset/types.verify.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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++23
+
+// <flat_set>
+
+//  template<class Key, class Compare = less<Key>, class KeyContainer = vector<Key>>
+//    class flat_multiset;
+
+#include <flat_set>
+#include <functional>
+#include <vector>
+
+void test_flat_multiset() {
+  // expected-error-re@*:* {{static assertion failed{{.*}}The stored elements key type must match the underlying container's key value_type.}}
+  std::flat_multiset<double, std::less<double>, std::vector<int>> fms1;
+
+  // expected-error-re@*:* {{static assertion failed{{.*}}vector<bool> is not a sequence container}}
+  std::flat_multiset<bool, std::less<bool>, std::vector<bool>> fms2;
+}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.set/types.verify.cpp b/libcxx/test/std/containers/container.adaptors/flat.set/types.verify.cpp
new file mode 100644
index 0000000000000..c8a58360db1ad
--- /dev/null
+++ b/libcxx/test/std/containers/container.adaptors/flat.set/types.verify.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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++23
+
+// <flat_set>
+
+//  template<class Key, class Compare = less<Key>, class KeyContainer = vector<Key>>
+//    class flat_set;
+
+#include <flat_set>
+#include <functional>
+#include <vector>
+
+void test_flat_set() {
+  // expected-error-re@*:* {{static assertion failed{{.*}}The stored elements key type must match the underlying container's key value_type.}}
+  std::flat_set<double, std::less<double>, std::vector<int>> fs1;
+
+  // expected-error-re@*:* {{static assertion failed{{.*}}vector<bool> is not a sequence container}}
+  std::flat_set<bool, std::less<bool>, std::vector<bool>> fs2;
+}
diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/empty.verify.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/empty.verify.cpp
deleted file mode 100644
index 5202710846e8b..0000000000000
--- a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/empty.verify.cpp
+++ /dev/null
@@ -1,22 +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
-//
-//===----------------------------------------------------------------------===//
-
-// <queue>
-
-// class priority_queue
-
-// bool empty() const noexcept;
-
-// UNSUPPORTED: c++03, c++11, c++14, c++17
-
-#include <queue>
-
-void f() {
-  std::priority_queue<int> c;
-  c.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-}
diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/types.compile.fail.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/types.verify.cpp
similarity index 75%
rename from libcxx/test/std/containers/container.adaptors/priority.queue/types.compile.fail.cpp
rename to libcxx/test/std/containers/container.adaptors/priority.queue/types.verify.cpp
index 3dce083537318..cfa5522623f11 100644
--- a/libcxx/test/std/containers/container.adaptors/priority.queue/types.compile.fail.cpp
+++ b/libcxx/test/std/containers/container.adaptors/priority.queue/types.verify.cpp
@@ -13,10 +13,8 @@
 // class priority_queue
 
 #include <queue>
-#include <cassert>
-#include <type_traits>
 
 void test() {
-  //  LWG#2566 says that the first template param must match the second one's value type
-  std::priority_queue<double, std::deque<int>> t;
+  // expected-error-re@*:* {{static assertion failed{{.*}}The stored elements type must match the underlying container's value_type.}}
+  std::priority_queue<double, std::deque<int>> pq;
 }
diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/types.compile.fail.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/types.compile.fail.cpp
deleted file mode 100644
index daec08ef62bc6..0000000000000
--- a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/types.compile.fail.cpp
+++ /dev/null
@@ -1,20 +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
-//
-//===----------------------------------------------------------------------===//
-
-// <queue>
-
-#include <queue>
-#include <cassert>
-#include <type_traits>
-
-int main(int, char**) {
-  //  LWG#2566 says that the first template param must match the second one's value type
-  std::queue<double, std::deque<int>> t;
-
-  return 0;
-}
diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/empty.verify.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/types.verify.cpp
similarity index 63%
rename from libcxx/test/std/containers/container.adaptors/queue/queue.defn/empty.verify.cpp
rename to libcxx/test/std/containers/container.adaptors/queue/queue.defn/types.verify.cpp
index 27c99b0f379e9..66779deb71cce 100644
--- a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/empty.verify.cpp
+++ b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/types.verify.cpp
@@ -8,15 +8,12 @@
 
 // <queue>
 
+// template <class T, class Container = deque<T>>
 // class queue
 
-// bool empty() const noexcept;
-
-// UNSUPPORTED: c++03, c++11, c++14, c++17
-
 #include <queue>
 
-void f() {
-  std::queue<int> c;
-  c.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+void test() {
+  // expected-error-re@*:* {{static assertion failed{{.*}}The stored elements type must match the underlying container's value_type.}}
+  std::queue<double, std::deque<int>> qu;
 }
diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.defn/types.compile.fail.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/types.compile.fail.cpp
deleted file mode 100644
index ddccbe090afe2..0000000000000
--- a/libcxx/test/std/containers/container.adaptors/stack/stack.defn/types.compile.fail.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <queue>
-
-// template <class T, class Container = vector<T>,
-//           class Compare = less<typename Container::value_type>>
-// class priority_queue
-// {
-// public:
-//     typedef Container                                container_type;
-//     typedef typename container_type::value_type      value_type;
-//     typedef typename container_type::reference       reference;
-//     typedef typename container_type::const_reference const_reference;
-//     typedef typename container_type::size_type       size_type;
-//
-// protected:
-//     container_type c;
-//     Compare comp;
-
-#include <stack>
-#include <cassert>
-#include <type_traits>
-
-int main(int, char**) {
-  //  LWG#2566 says that the first template param must match the second one's value type
-  std::stack<double, std::deque<int>> t;
-
-  return 0;
-}
diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.defn/empty.verify.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/types.verify.cpp
similarity index 63%
rename from libcxx/test/std/containers/container.adaptors/stack/stack.defn/empty.verify.cpp
rename to libcxx/test/std/containers/container.adaptors/stack/stack.defn/types.verify.cpp
index 9100bc2a03e06..9526cdbaf7103 100644
--- a/libcxx/test/std/containers/container.adaptors/stack/stack.defn/empty.verify.cpp
+++ b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/types.verify.cpp
@@ -8,15 +8,12 @@
 
 // <stack>
 
+// template <class T, class Container = deque<T>>
 // class stack
 
-// bool empty() const noexcept;
-
-// UNSUPPORTED: c++03, c++11, c++14, c++17
-
 #include <stack>
 
-void f() {
-  std::stack<int> c;
-  c.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+void test() {
+  // expected-error-re@*:* {{static assertion failed{{.*}}The stored elements type must match the underlying container's value_type.}}
+  std::stack<double, std::deque<int>> st;
 }



More information about the libcxx-commits mailing list