[libcxx-commits] [libcxx] [libc++] Update container adaptor tests (PR #224810)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Sep 18 23:08:55 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Hristo Hristov (H-G-Hristov)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/224810.diff
16 Files Affected:
- (modified) libcxx/include/__flat_map/flat_map.h (+4-2)
- (modified) libcxx/include/__flat_map/flat_multimap.h (+4-2)
- (modified) libcxx/include/__flat_set/flat_multiset.h (+2-1)
- (modified) libcxx/include/__flat_set/flat_set.h (+2-1)
- (modified) libcxx/include/queue (+2-2)
- (modified) libcxx/include/stack (+1-1)
- (added) libcxx/test/std/containers/container.adaptors/flat.map/types.verify.cpp (+32)
- (added) libcxx/test/std/containers/container.adaptors/flat.multimap/types.verify.cpp (+32)
- (added) libcxx/test/std/containers/container.adaptors/flat.multiset/types.verify.cpp (+25)
- (added) libcxx/test/std/containers/container.adaptors/flat.set/types.verify.cpp (+25)
- (removed) libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/empty.verify.cpp (-22)
- (renamed) libcxx/test/std/containers/container.adaptors/priority.queue/types.verify.cpp (+2-4)
- (removed) libcxx/test/std/containers/container.adaptors/queue/queue.defn/types.compile.fail.cpp (-20)
- (renamed) libcxx/test/std/containers/container.adaptors/queue/queue.defn/types.verify.cpp (+5-7)
- (removed) libcxx/test/std/containers/container.adaptors/stack/stack.defn/types.compile.fail.cpp (-35)
- (renamed) libcxx/test/std/containers/container.adaptors/stack/stack.defn/types.verify.cpp (+4-7)
``````````diff
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..18964b04d3a61 100644
--- a/libcxx/include/queue
+++ b/libcxx/include/queue
@@ -306,7 +306,7 @@ 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 +524,7 @@ 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..55d030c28506c 100644
--- a/libcxx/include/stack
+++ b/libcxx/include/stack
@@ -160,7 +160,7 @@ 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..a90ff396d6aa0
--- /dev/null
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/types.verify.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <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..9336eb6fb31b4
--- /dev/null
+++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/types.verify.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <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..39495792a1c3b
--- /dev/null
+++ b/libcxx/test/std/containers/container.adaptors/flat.multiset/types.verify.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <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..443e33fa2f668
--- /dev/null
+++ b/libcxx/test/std/containers/container.adaptors/flat.set/types.verify.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <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..717e262665eb3 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,13 @@
// <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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/224810
More information about the libcxx-commits
mailing list