[gcc r17-2716] libstdc++: Robustify flat_map::insert_range move counter test
Patrick Palka
ppalka@gcc.gnu.org
Sun Jul 26 13:59:26 GMT 2026
https://gcc.gnu.org/g:b71686db1fdc589da34f80460f054407c1f54990
commit r17-2716-gb71686db1fdc589da34f80460f054407c1f54990
Author: Patrick Palka <ppalka@redhat.com>
Date: Sun Jul 26 09:58:58 2026 -0400
libstdc++: Robustify flat_map::insert_range move counter test
Testing r17-2704-gf678da4a9930c8 on the 16 branch, which doesn't
implement P0401 std::allocate_at_least, revealed that the added test
isn't robust to std::vector initial capacity. The test needs to reserve
sufficient capacity upfront so that reallocation doesn't happen during
insert_range which would skew the move counter.
libstdc++-v3/ChangeLog:
* testsuite/23_containers/flat_map/1.cc (test14): Reserve
sufficient capacity for the underlying containers before
calling insert_range.
Diff:
---
libstdc++-v3/testsuite/23_containers/flat_map/1.cc | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/libstdc++-v3/testsuite/23_containers/flat_map/1.cc b/libstdc++-v3/testsuite/23_containers/flat_map/1.cc
index d53e56a1b717..c3ad2883e65f 100644
--- a/libstdc++-v3/testsuite/23_containers/flat_map/1.cc
+++ b/libstdc++-v3/testsuite/23_containers/flat_map/1.cc
@@ -433,6 +433,12 @@ test14()
{counter(2), counter(20)},
{counter(3), counter(30)},
};
+
+ auto [keys,values] = std::move(m).extract();
+ keys.reserve(std::size(r));
+ values.reserve(std::size(r));
+ m.replace(std::move(keys), std::move(values));
+
moves = 0;
m.insert_range(std::sorted_unique, std::views::as_rvalue(r));
VERIFY( moves == 6 );
More information about the Libstdc++-cvs
mailing list