[committed] libstdc++: Robustify flat_map::insert_range move counter test
Patrick Palka
ppalka@redhat.com
Sun Jul 26 13:57:41 GMT 2026
Tested on x86_64-pc-linux-gnu, pushed to trunk as obvious.
-- >8 --
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.
---
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 );
--
2.55.0.378.g9a0c4701dc
More information about the Libstdc++
mailing list