[libcxx-commits] [libcxx] 08daaa8 - [libc++] Update container adaptors' type verification tests (#224810)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Sep 19 23:53:23 PDT 2026
Author: Hristo Hristov
Date: 2026-09-20T09:53:17+03:00
New Revision: 08daaa8e376a5dcd9be7894dbd071920a7de154a
URL: https://github.com/llvm/llvm-project/commit/08daaa8e376a5dcd9be7894dbd071920a7de154a
DIFF: https://github.com/llvm/llvm-project/commit/08daaa8e376a5dcd9be7894dbd071920a7de154a.diff
LOG: [libc++] Update container adaptors' type verification tests (#224810)
1. Improves the error message for LWG2566.
2. Converts related compile.fail.cpp tests to verify.cpp tests.
3. Updates all related tests.
4. Removes some redundant tests (e.g. `[[nodiscard]]` is tested
elsewhere).
References:
- https://wg21.link/lwg2566
- https://wg21.link/container.adaptors
- https://wg21.link/flat.map.overview#7
- https://wg21.link/flat.map.overview#8
- https://wg21.link/flat.multimap.overview#7
- https://wg21.link/flat.multimap.overview#8
- https://wg21.link/flat.multiset.overview#7
- https://wg21.link/flat.multiset.overview#8
- https://wg21.link/flat.set.overview#7
- https://wg21.link/flat.set.overview#8
---------
Co-authored-by: Hristo Hristov <zingam at outlook.com>
Co-authored-by: A. Jiang <de34 at live.cn>
Added:
libcxx/test/std/containers/container.adaptors/flat.map/types.verify.cpp
libcxx/test/std/containers/container.adaptors/flat.multimap/types.verify.cpp
libcxx/test/std/containers/container.adaptors/flat.multiset/types.verify.cpp
libcxx/test/std/containers/container.adaptors/flat.set/types.verify.cpp
libcxx/test/std/containers/container.adaptors/priority.queue/types.verify.cpp
libcxx/test/std/containers/container.adaptors/queue/queue.defn/types.verify.cpp
libcxx/test/std/containers/container.adaptors/stack/stack.defn/types.verify.cpp
Modified:
libcxx/include/__flat_map/flat_map.h
libcxx/include/__flat_map/flat_multimap.h
libcxx/include/__flat_set/flat_multiset.h
libcxx/include/__flat_set/flat_set.h
libcxx/include/queue
libcxx/include/stack
Removed:
libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/empty.verify.cpp
libcxx/test/std/containers/container.adaptors/priority.queue/types.compile.fail.cpp
libcxx/test/std/containers/container.adaptors/queue/queue.defn/empty.verify.cpp
libcxx/test/std/containers/container.adaptors/queue/queue.defn/types.compile.fail.cpp
libcxx/test/std/containers/container.adaptors/stack/stack.defn/empty.verify.cpp
libcxx/test/std/containers/container.adaptors/stack/stack.defn/types.compile.fail.cpp
################################################################################
diff --git a/libcxx/include/__flat_map/flat_map.h b/libcxx/include/__flat_map/flat_map.h
index 50487cada24c0..27964aa421d21 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 key container's value_type.");
+ static_assert(is_same_v<_Tp, typename _MappedContainer::value_type>,
+ "The stored elements' mapped type must match the underlying mapped container's 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..9acaedf0772a0 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 key container's value_type.");
+ static_assert(is_same_v<_Tp, typename _MappedContainer::value_type>,
+ "The stored elements' mapped type must match the underlying mapped container's 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..74c0427eae928 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 key container's 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..988ffbe1b4a70 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 key container's 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..3e02678f09623
--- /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 key container's 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 mapped container's 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..ad6f701f9034c
--- /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() {
+ // expected-error-re@*:* {{static assertion failed{{.*}}The stored elements' key type must match the underlying key container's 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 mapped container's 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..b70d193841e06
--- /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() {
+ // expected-error-re@*:* {{static assertion failed{{.*}}The stored elements' key type must match the underlying key container's 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..78621182a45f3
--- /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() {
+ // expected-error-re@*:* {{static assertion failed{{.*}}The stored elements' key type must match the underlying key container's 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 74%
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..ffca78965fc26 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 62%
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..9c149d6329e0b 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 62%
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..a1a8ff15b40a7 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