From: Patrick Palka Date: Mon, 1 Dec 2025 22:08:01 +0000 (-0500) Subject: libstdc++: Inconsistent const in flat_map's value_type [PR122921] X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3e02f86cd13c787331281ab098901f8a67381945;p=thirdparty%2Fgcc.git libstdc++: Inconsistent const in flat_map's value_type [PR122921] flat_map's value_type is pair, which we correctly define within the container but incorrectly within the iterator. PR libstdc++/122921 libstdc++-v3/ChangeLog: * include/std/flat_map (_Flat_map_impl::_Iterator::value_type): Remove const from key_type to make consistent with the container's value_type. * testsuite/23_containers/flat_map/1.cc (test09): New test. * testsuite/23_containers/flat_multimap/1.cc (test09): New test. Reported-by: Vincent X Reviewed-by: Jonathan Wakely --- diff --git a/libstdc++-v3/include/std/flat_map b/libstdc++-v3/include/std/flat_map index de006ad1c53..e48c3eae07f 100644 --- a/libstdc++-v3/include/std/flat_map +++ b/libstdc++-v3/include/std/flat_map @@ -953,7 +953,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION public: using iterator_category = input_iterator_tag; using iterator_concept = random_access_iterator_tag; - using value_type = pair; + using value_type = pair; using reference = pair&>; using difference_type = ptrdiff_t; diff --git a/libstdc++-v3/testsuite/23_containers/flat_map/1.cc b/libstdc++-v3/testsuite/23_containers/flat_map/1.cc index 01278d7dc33..5bcda3464f1 100644 --- a/libstdc++-v3/testsuite/23_containers/flat_map/1.cc +++ b/libstdc++-v3/testsuite/23_containers/flat_map/1.cc @@ -263,6 +263,17 @@ test08() m[k] = 0; } +void +test09() +{ + // PR libstdc++/122921 - The value_type of flat_map's iterator should be + // pair instead of pair + using type = std::flat_map; + using value_type = std::ranges::range_value_t; + using value_type = type::value_type; + using value_type = std::pair; +} + int main() { @@ -277,4 +288,5 @@ main() test06(); test07(); test08(); + test09(); } diff --git a/libstdc++-v3/testsuite/23_containers/flat_multimap/1.cc b/libstdc++-v3/testsuite/23_containers/flat_multimap/1.cc index d746614401d..f143f3acd1b 100644 --- a/libstdc++-v3/testsuite/23_containers/flat_multimap/1.cc +++ b/libstdc++-v3/testsuite/23_containers/flat_multimap/1.cc @@ -232,6 +232,17 @@ test07() VERIFY( std::ranges::equal(m, (std::pair[]){{3,4},{3,3}}) ); } +void +test09() +{ + // PR libstdc++/122921 - The value_type of flat_map's iterator should be + // pair instead of pair + using type = std::flat_multimap; + using value_type = std::ranges::range_value_t; + using value_type = type::value_type; + using value_type = std::pair; +} + int main() { @@ -245,4 +256,5 @@ main() test05(); test06(); test07(); + test09(); }