[libcxx-commits] [libcxx] [libc++][test] Avoid narrowing operations in `pair`' constructors for test files for `flat_(multi)map` whenever feasible. (PR #131284)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Mar 13 23:28:02 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: A. Jiang (frederick-vs-ja)

<details>
<summary>Changes</summary>

Drive-by: Add `[[maybe_unused]]` to variables that are only used in `LIBCPP_ASSERT`.

When testing MSVC STL, MSVC warns about such narrowing in `pair`'s constructors, even though the narrowing happens within direct-non-list-initialization.

---

Patch is 60.66 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/131284.diff


27 Files Affected:

- (modified) libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_assign.pass.cpp (+6-2) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct.pass.cpp (+35-9) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct_pmr.pass.cpp (+10-2) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/initializer_list.pass.cpp (+44-7) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp (+12-3) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign.pass.cpp (+10-5) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/pmr.pass.cpp (+24-6) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp (+12-3) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_container.pass.cpp (+20-5) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_initializer_list.pass.cpp (+15-4) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_iter_iter.pass.cpp (+10-3) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.map/flat.map.erasure/erase_if_exceptions.pass.cpp (+2-1) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_key.pass.cpp (+1-1) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/containers.pass.cpp (+30-3) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/copy_assign.pass.cpp (+6-2) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct.pass.cpp (+45-9) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct_pmr.pass.cpp (+16-2) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/initializer_list.pass.cpp (+49-7) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/iter_iter.pass.cpp (+21-3) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_assign.pass.cpp (+14-5) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/pmr.pass.cpp (+42-6) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/range.pass.cpp (+21-3) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_container.pass.cpp (+16-4) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_initializer_list.pass.cpp (+15-4) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_iter_iter.pass.cpp (+9-4) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.erasure/erase_if_exceptions.pass.cpp (+2-1) 
- (modified) libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.modifiers/erase_key.pass.cpp (+1-1) 


``````````diff
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_assign.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_assign.pass.cpp
index 4f9797d5bf810..cc80de8950738 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_assign.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_assign.pass.cpp
@@ -29,7 +29,9 @@ int main(int, char**) {
     std::vector<char, test_allocator<char>> vs({2, 2, 1}, test_allocator<char>(7));
     using M = std::flat_map<int, char, C, decltype(ks), decltype(vs)>;
     auto mo = M(ks, vs, C(5));
-    auto m  = M({{3, 3}, {4, 4}, {5, 5}}, C(3), test_allocator<int>(2));
+    auto m  = M({{3, static_cast<char>(3)}, {4, static_cast<char>(4)}, {5, static_cast<char>(5)}},
+               C(3),
+               test_allocator<int>(2));
     m       = mo;
 
     assert(m.key_comp() == C(5));
@@ -54,7 +56,9 @@ int main(int, char**) {
     auto vs  = Vs({2, 2, 1}, other_allocator<char>(7));
     using M  = std::flat_map<int, char, C, Ks, Vs>;
     auto mo  = M(Ks(ks, other_allocator<int>(6)), Vs(vs, other_allocator<int>(7)), C(5));
-    auto m   = M({{3, 3}, {4, 4}, {5, 5}}, C(3), other_allocator<int>(2));
+    auto m   = M({{3, static_cast<char>(3)}, {4, static_cast<char>(4)}, {5, static_cast<char>(5)}},
+               C(3),
+               other_allocator<int>(2));
     m        = mo;
 
     assert(m.key_comp() == C(5));
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct.pass.cpp
index 009392feb3862..3ca7aa1363856 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct.pass.cpp
@@ -31,19 +31,19 @@ using PC = std::pair<const int, long>;
 
 void test_copy() {
   {
-    std::flat_map<long, short> source = {{1, 2}, {2, 3}};
+    std::flat_map<long, short> source = {{1, static_cast<short>(2)}, {2, static_cast<short>(3)}};
     std::flat_map s(source);
     ASSERT_SAME_TYPE(decltype(s), decltype(source));
     assert(s == source);
   }
   {
-    std::flat_map<long, short, std::greater<long>> source = {{1, 2}, {2, 3}};
+    std::flat_map<long, short, std::greater<long>> source = {{1, static_cast<short>(2)}, {2, static_cast<short>(3)}};
     std::flat_map s{source}; // braces instead of parens
     ASSERT_SAME_TYPE(decltype(s), decltype(source));
     assert(s == source);
   }
   {
-    std::flat_map<long, short, std::greater<long>> source = {{1, 2}, {2, 3}};
+    std::flat_map<long, short, std::greater<long>> source = {{1, static_cast<short>(2)}, {2, static_cast<short>(3)}};
     std::flat_map s(source, std::allocator<int>());
     ASSERT_SAME_TYPE(decltype(s), decltype(source));
     assert(s == source);
@@ -55,7 +55,11 @@ void test_containers() {
   std::deque<short, test_allocator<short>> vs({1, 2, 1, 4, 5}, test_allocator<int>(0, 43));
   std::deque<int, test_allocator<int>> sorted_ks({1, 2, 3, INT_MAX}, test_allocator<int>(0, 42));
   std::deque<short, test_allocator<short>> sorted_vs({1, 2, 5, 4}, test_allocator<int>(0, 43));
-  const std::pair<int, short> expected[] = {{1, 1}, {2, 2}, {3, 5}, {INT_MAX, 4}};
+  const std::pair<int, short> expected[] = {
+      {1, static_cast<short>(1)},
+      {2, static_cast<short>(2)},
+      {3, static_cast<short>(5)},
+      {INT_MAX, static_cast<short>(4)}};
   {
     std::flat_map s(ks, vs);
 
@@ -95,7 +99,11 @@ void test_containers_compare() {
   std::deque<short, test_allocator<short>> vs({1, 2, 1, 4, 5}, test_allocator<int>(0, 43));
   std::deque<int, test_allocator<int>> sorted_ks({INT_MAX, 3, 2, 1}, test_allocator<int>(0, 42));
   std::deque<short, test_allocator<short>> sorted_vs({4, 5, 2, 1}, test_allocator<int>(0, 43));
-  const std::pair<int, short> expected[] = {{INT_MAX, 4}, {3, 5}, {2, 2}, {1, 1}};
+  const std::pair<int, short> expected[] = {
+      {INT_MAX, static_cast<short>(4)},
+      {3, static_cast<short>(5)},
+      {2, static_cast<short>(2)},
+      {1, static_cast<short>(1)}};
   {
     std::flat_map s(ks, vs, std::greater<int>());
 
@@ -278,8 +286,17 @@ void test_initializer_list_compare() {
 }
 
 void test_from_range() {
-  std::list<std::pair<int, short>> r     = {{1, 1}, {2, 2}, {1, 1}, {INT_MAX, 4}, {3, 5}};
-  const std::pair<int, short> expected[] = {{1, 1}, {2, 2}, {3, 5}, {INT_MAX, 4}};
+  std::list<std::pair<int, short>> r = {
+      {1, static_cast<short>(1)},
+      {2, static_cast<short>(2)},
+      {1, static_cast<short>(1)},
+      {INT_MAX, static_cast<short>(4)},
+      {3, static_cast<short>(5)}};
+  const std::pair<int, short> expected[] = {
+      {1, static_cast<short>(1)},
+      {2, static_cast<short>(2)},
+      {3, static_cast<short>(5)},
+      {INT_MAX, static_cast<short>(4)}};
   {
     std::flat_map s(std::from_range, r);
     ASSERT_SAME_TYPE(decltype(s), std::flat_map<int, short, std::less<int>>);
@@ -301,8 +318,17 @@ void test_from_range() {
 }
 
 void test_from_range_compare() {
-  std::list<std::pair<int, short>> r     = {{1, 1}, {2, 2}, {1, 1}, {INT_MAX, 4}, {3, 5}};
-  const std::pair<int, short> expected[] = {{INT_MAX, 4}, {3, 5}, {2, 2}, {1, 1}};
+  std::list<std::pair<int, short>> r = {
+      {1, static_cast<short>(1)},
+      {2, static_cast<short>(2)},
+      {1, static_cast<short>(1)},
+      {INT_MAX, static_cast<short>(4)},
+      {3, static_cast<short>(5)}};
+  const std::pair<int, short> expected[] = {
+      {INT_MAX, static_cast<short>(4)},
+      {3, static_cast<short>(5)},
+      {2, static_cast<short>(2)},
+      {1, static_cast<short>(1)}};
   {
     std::flat_map s(std::from_range, r, std::greater<int>());
     ASSERT_SAME_TYPE(decltype(s), std::flat_map<int, short, std::greater<int>>);
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct_pmr.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct_pmr.pass.cpp
index 11c18ac13c76a..e62b9049859aa 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct_pmr.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct_pmr.pass.cpp
@@ -35,7 +35,11 @@ void test_containers() {
   std::deque<short, test_allocator<short>> vs({1, 2, 1, 4, 5}, test_allocator<int>(0, 43));
   std::deque<int, test_allocator<int>> sorted_ks({1, 2, 3, INT_MAX}, test_allocator<int>(0, 42));
   std::deque<short, test_allocator<short>> sorted_vs({1, 2, 5, 4}, test_allocator<int>(0, 43));
-  const std::pair<int, short> expected[] = {{1, 1}, {2, 2}, {3, 5}, {INT_MAX, 4}};
+  const std::pair<int, short> expected[] = {
+      {1, static_cast<short>(1)},
+      {2, static_cast<short>(2)},
+      {3, static_cast<short>(5)},
+      {INT_MAX, static_cast<short>(4)}};
   {
     std::pmr::monotonic_buffer_resource mr;
     std::pmr::monotonic_buffer_resource mr2;
@@ -69,7 +73,11 @@ void test_containers_compare() {
   std::deque<short, test_allocator<short>> vs({1, 2, 1, 4, 5}, test_allocator<int>(0, 43));
   std::deque<int, test_allocator<int>> sorted_ks({INT_MAX, 3, 2, 1}, test_allocator<int>(0, 42));
   std::deque<short, test_allocator<short>> sorted_vs({4, 5, 2, 1}, test_allocator<int>(0, 43));
-  const std::pair<int, short> expected[] = {{INT_MAX, 4}, {3, 5}, {2, 2}, {1, 1}};
+  const std::pair<int, short> expected[] = {
+      {INT_MAX, static_cast<short>(4)},
+      {3, static_cast<short>(5)},
+      {2, static_cast<short>(2)},
+      {1, static_cast<short>(1)}};
   {
     std::pmr::monotonic_buffer_resource mr;
     std::pmr::monotonic_buffer_resource mr2;
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/initializer_list.pass.cpp
index 7a22746845d00..5fa8b040a31e8 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/initializer_list.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/initializer_list.pass.cpp
@@ -82,11 +82,18 @@ int main(int, char**) {
         !std::is_constructible_v<M, std::initializer_list<std::pair<const int, const short>>, std::allocator<int>>);
   }
 
-  std::pair<int, short> expected[] = {{1, 1}, {2, 2}, {3, 3}, {5, 2}};
+  std::pair<int, short> expected[] = {
+      {1, static_cast<short>(1)}, {2, static_cast<short>(2)}, {3, static_cast<short>(3)}, {5, static_cast<short>(2)}};
   {
     // flat_map(initializer_list<value_type>);
     using M                                         = std::flat_map<int, short>;
-    std::initializer_list<std::pair<int, short>> il = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
+    std::initializer_list<std::pair<int, short>> il = {
+        {5, static_cast<short>(2)},
+        {2, static_cast<short>(2)},
+        {2, static_cast<short>(2)},
+        {3, static_cast<short>(3)},
+        {1, static_cast<short>(1)},
+        {3, static_cast<short>(3)}};
     M m(il);
     assert(std::equal(m.begin(), m.end(), expected, expected + 4));
   }
@@ -94,13 +101,23 @@ int main(int, char**) {
     // flat_map(initializer_list<value_type>);
     // explicit(false)
     using M = std::flat_map<int, short>;
-    M m     = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
+    M m     = {{5, static_cast<short>(2)},
+               {2, static_cast<short>(2)},
+               {2, static_cast<short>(2)},
+               {3, static_cast<short>(3)},
+               {1, static_cast<short>(1)},
+               {3, static_cast<short>(3)}};
     assert(std::equal(m.begin(), m.end(), expected, expected + 4));
   }
   {
     // flat_map(initializer_list<value_type>);
     using M = std::flat_map<int, short, std::greater<int>, std::deque<int, min_allocator<int>>>;
-    M m     = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
+    M m     = {{5, static_cast<short>(2)},
+               {2, static_cast<short>(2)},
+               {2, static_cast<short>(2)},
+               {3, static_cast<short>(3)},
+               {1, static_cast<short>(1)},
+               {3, static_cast<short>(3)}};
     assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
   }
   {
@@ -127,12 +144,25 @@ int main(int, char**) {
     // flat_map(initializer_list<value_type>, const key_compare&);
     using C = test_less<int>;
     using M = std::flat_map<int, short, C>;
-    auto m  = M({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, C(10));
+    auto m =
+        M({{5, static_cast<short>(2)},
+           {2, static_cast<short>(2)},
+           {2, static_cast<short>(2)},
+           {3, static_cast<short>(3)},
+           {1, static_cast<short>(1)},
+           {3, static_cast<short>(3)}},
+          C(10));
     assert(std::equal(m.begin(), m.end(), expected, expected + 4));
     assert(m.key_comp() == C(10));
 
     // explicit(false)
-    M m2 = {{{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, C(10)};
+    M m2 = {{{5, static_cast<short>(2)},
+             {2, static_cast<short>(2)},
+             {2, static_cast<short>(2)},
+             {3, static_cast<short>(3)},
+             {1, static_cast<short>(1)},
+             {3, static_cast<short>(3)}},
+            C(10)};
     assert(m2 == m);
     assert(m2.key_comp() == C(10));
   }
@@ -140,7 +170,14 @@ int main(int, char**) {
     // flat_map(initializer_list<value_type>, const key_compare&);
     // Sorting uses the comparator that was passed in
     using M = std::flat_map<int, short, std::function<bool(int, int)>, std::deque<int, min_allocator<int>>>;
-    auto m  = M({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, std::greater<int>());
+    auto m =
+        M({{5, static_cast<short>(2)},
+           {2, static_cast<short>(2)},
+           {2, static_cast<short>(2)},
+           {3, static_cast<short>(3)},
+           {1, static_cast<short>(1)},
+           {3, static_cast<short>(3)}},
+          std::greater<int>());
     assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
     assert(m.key_comp()(2, 1) == true);
   }
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp
index 7c0c487969943..6fb6eef67bb03 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp
@@ -57,9 +57,18 @@ int main(int, char**) {
     static_assert(!std::is_constructible_v<M3, Iter3, Iter3, const C&, const A2&>);
   }
 
-  using P      = std::pair<int, short>;
-  P ar[]       = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
-  P expected[] = {{1, 1}, {2, 4}, {3, 6}};
+  using P = std::pair<int, short>;
+  P ar[]  = {
+      {1, static_cast<short>(1)},
+      {1, static_cast<short>(2)},
+      {1, static_cast<short>(3)},
+      {2, static_cast<short>(4)},
+      {2, static_cast<short>(5)},
+      {3, static_cast<short>(6)},
+      {2, static_cast<short>(7)},
+      {3, static_cast<short>(8)},
+      {3, static_cast<short>(9)}};
+  P expected[] = {{1, static_cast<short>(1)}, {2, static_cast<short>(4)}, {3, static_cast<short>(6)}};
   {
     // flat_map(InputIterator , InputIterator)
     // cpp17_input_iterator
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign.pass.cpp
index a94c442c695dd..ad305ae41cdf2 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign.pass.cpp
@@ -32,10 +32,10 @@ int main(int, char**) {
     using A1 = test_allocator<int>;
     using A2 = test_allocator<char>;
     using M  = std::flat_map<int, char, C, std::vector<int, A1>, std::vector<char, A2>>;
-    M mo     = M({{1, 1}, {2, 3}, {3, 2}}, C(5), A1(7));
+    M mo     = M({{1, static_cast<char>(1)}, {2, static_cast<char>(3)}, {3, static_cast<char>(2)}}, C(5), A1(7));
     M m      = M({}, C(3), A1(7));
     m        = std::move(mo);
-    assert((m == M{{1, 1}, {2, 3}, {3, 2}}));
+    assert((m == M{{1, static_cast<char>(1)}, {2, static_cast<char>(3)}, {3, static_cast<char>(2)}}));
     assert(m.key_comp() == C(5));
     auto [ks, vs] = std::move(m).extract();
     assert(ks.get_allocator() == A1(7));
@@ -47,10 +47,15 @@ int main(int, char**) {
     using A1 = other_allocator<int>;
     using A2 = other_allocator<char>;
     using M  = std::flat_map<int, char, C, std::deque<int, A1>, std::deque<char, A2>>;
-    M mo     = M({{4, 5}, {5, 4}}, C(5), A1(7));
-    M m      = M({{1, 1}, {2, 2}, {3, 3}, {4, 4}}, C(3), A1(7));
+    M mo     = M({{4, static_cast<char>(5)}, {5, static_cast<char>(4)}}, C(5), A1(7));
+    M m      = M({{1, static_cast<char>(1)}, //
+                  {2, static_cast<char>(2)},
+                  {3, static_cast<char>(3)},
+                  {4, static_cast<char>(4)}},
+            C(3),
+            A1(7));
     m        = std::move(mo);
-    assert((m == M{{4, 5}, {5, 4}}));
+    assert((m == M{{4, static_cast<char>(5)}, {5, static_cast<char>(4)}}));
     assert(m.key_comp() == C(5));
     auto [ks, vs] = std::move(m).extract();
     assert(ks.get_allocator() == A1(7));
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/pmr.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/pmr.pass.cpp
index 154af11bb9b4d..d1c86bb077ed5 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/pmr.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/pmr.pass.cpp
@@ -166,9 +166,18 @@ int main(int, char**) {
   }
   {
     // flat_map(InputIterator first, InputIterator last, const Allocator& a);
-    using P      = std::pair<int, short>;
-    P ar[]       = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
-    P expected[] = {{1, 1}, {2, 4}, {3, 6}};
+    using P = std::pair<int, short>;
+    P ar[]  = {
+        {1, static_cast<short>(1)},
+        {1, static_cast<short>(2)},
+        {1, static_cast<short>(3)},
+        {2, static_cast<short>(4)},
+        {2, static_cast<short>(5)},
+        {3, static_cast<short>(6)},
+        {2, static_cast<short>(7)},
+        {3, static_cast<short>(8)},
+        {3, static_cast<short>(9)}};
+    P expected[] = {{1, static_cast<short>(1)}, {2, static_cast<short>(4)}, {3, static_cast<short>(6)}};
     {
       //  cpp17 iterator
       using M = std::flat_map<int, short, std::less<int>, std::pmr::vector<int>, std::pmr::vector<short>>;
@@ -242,9 +251,18 @@ int main(int, char**) {
   }
   {
     //  flat_map(from_range_t, R&&, const Alloc&);
-    using P      = std::pair<int, short>;
-    P ar[]       = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
-    P expected[] = {{1, 1}, {2, 4}, {3, 6}};
+    using P = std::pair<int, short>;
+    P ar[]  = {
+        {1, static_cast<short>(1)},
+        {1, static_cast<short>(2)},
+        {1, static_cast<short>(3)},
+        {2, static_cast<short>(4)},
+        {2, static_cast<short>(5)},
+        {3, static_cast<short>(6)},
+        {2, static_cast<short>(7)},
+        {3, static_cast<short>(8)},
+        {3, static_cast<short>(9)}};
+    P expected[] = {{1, static_cast<short>(1)}, {2, static_cast<short>(4)}, {3, static_cast<short>(6)}};
     {
       // input_range
       using M    = std::flat_map<int, short, std::less<int>, std::pmr::vector<int>, std::pmr::vector<short>>;
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp
index 282cc71f31994..c34109a1801ba 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp
@@ -117,9 +117,18 @@ int main(int, char**) {
     static_assert(!std::is_constructible_v<M, std::from_range_t, std::vector<NonPairLike>&, const C&, const A1&>);
   }
 
-  using P      = std::pair<int, short>;
-  P ar[]       = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
-  P expected[] = {{1, 1}, {2, 4}, {3, 6}};
+  using P = std::pair<int, short>;
+  P ar[]  = {
+      {1, static_cast<short>(1)},
+      {1, static_cast<short>(2)},
+      {1, static_cast<short>(3)},
+      {2, static_cast<short>(4)},
+      {2, static_cast<short>(5)},
+      {3, static_cast<short>(6)},
+      {2, static_cast<short>(7)},
+      {3, static_cast<short>(8)},
+      {3, static_cast<short>(9)}};
+  P expected[] = {{1, static_cast<short>(1)}, {2, static_cast<short>(4)}, {3, static_cast<short>(6)}};
   {
     // flat_map(from_range_t, R&&)
     // input_range && !common
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_container.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_container.pass.cpp
index 3c8868f2ff424..bde86ea2ddbe4 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_container.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_container.pass.cpp
@@ -66,11 +66,17 @@ int main(int, char**) {
     auto vs2             = vs;
 
     auto m = M(std::sorted_unique, ks, vs);
-    assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
+    assert((m == M{{1, static_cast<char>(4)},
+                   {2, static_cast<char>(3)},
+                   {4, static_cast<char>(2)},
+                   {10, static_cast<char>(1)}}));
     m = M(std::sorted_unique, std::move(ks), std::move(vs));
     assert(ks.empty()); // it was moved-from
     assert(vs.empty()); // it was moved-from
-    assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
+    assert((m == M{{1, static_cast<char>(4)},
+                   {2, static_cast<char>(3)},
+                   {4, static_cast<char>(2)},
+                   {10, static_cast<char>(1)}}));
 
     // explicit(false)
     M m2 = {std::sorted_unique, std::move(ks2), std::move(vs2)};
@@ -85,11 +91,17 @@ int main(int, char**) {
     Ks ks    = {10, 4,...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/131284


More information about the libcxx-commits mailing list