]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Inconsistent const in flat_map's value_type [PR122921]
authorPatrick Palka <ppalka@redhat.com>
Mon, 1 Dec 2025 22:08:01 +0000 (17:08 -0500)
committerPatrick Palka <ppalka@redhat.com>
Mon, 1 Dec 2025 22:08:01 +0000 (17:08 -0500)
flat_map's value_type is pair<key_type, mapped_type>, 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 <jwakely@redhat.com>
libstdc++-v3/include/std/flat_map
libstdc++-v3/testsuite/23_containers/flat_map/1.cc
libstdc++-v3/testsuite/23_containers/flat_multimap/1.cc

index de006ad1c5330238fcab914c18e01033cecb2a13..e48c3eae07fdb0b131a8ed4b0b79815218b695e6 100644 (file)
@@ -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<const key_type, mapped_type>;
+      using value_type        = pair<key_type, mapped_type>;
       using reference         = pair<const key_type&,
                                     ranges::__maybe_const_t<_Const, mapped_type>&>;
       using difference_type   = ptrdiff_t;
index 01278d7dc33c0e8f401b02f1d1451548f3db891c..5bcda3464f1f4979c451baa5f63194ed9f58a741 100644 (file)
@@ -263,6 +263,17 @@ test08()
   m[k] = 0;
 }
 
+void
+test09()
+{
+  // PR libstdc++/122921 - The value_type of flat_map's iterator should be
+  // pair<Key, T> instead of pair<const Key, T>
+  using type = std::flat_map<int, int>;
+  using value_type = std::ranges::range_value_t<type>;
+  using value_type = type::value_type;
+  using value_type = std::pair<int, int>;
+}
+
 int
 main()
 {
@@ -277,4 +288,5 @@ main()
   test06();
   test07();
   test08();
+  test09();
 }
index d746614401dea73ce06aad2cabae833d3073457e..f143f3acd1b59742a02a6e85cd55f41e6f9b0b75 100644 (file)
@@ -232,6 +232,17 @@ test07()
   VERIFY( std::ranges::equal(m, (std::pair<int,int>[]){{3,4},{3,3}}) );
 }
 
+void
+test09()
+{
+  // PR libstdc++/122921 - The value_type of flat_map's iterator should be
+  // pair<Key, T> instead of pair<const Key, T>
+  using type = std::flat_multimap<int, int>;
+  using value_type = std::ranges::range_value_t<type>;
+  using value_type = type::value_type;
+  using value_type = std::pair<int, int>;
+}
+
 int
 main()
 {
@@ -245,4 +256,5 @@ main()
   test05();
   test06();
   test07();
+  test09();
 }