]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix flat_map::operator[] for const lvalue keys [PR120432]
authorPatrick Palka <ppalka@redhat.com>
Fri, 6 Jun 2025 13:34:17 +0000 (09:34 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 6 Jun 2025 13:35:11 +0000 (09:35 -0400)
commite75e42f315e1e8bb4befee8ed242bd241c182091
treef49bdd8de85ec639f6d0ab34b71f0463e0798cf3
parentb2338ebf3e698589c69a521b4b4a7908dd959751
libstdc++: Fix flat_map::operator[] for const lvalue keys [PR120432]

The const lvalue operator[] overload wasn't properly forwarding the key
type to the generic overload, causing a hard error for const keys.

Rather than correcting the forwarded type this patch just makes the
non-template overloads call try_emplace directly instead.  That way we
can remove the non-standard same_as constraint on the generic overload
and match the spec more closely.

PR libstdc++/120432

libstdc++-v3/ChangeLog:

* include/std/flat_map (flat_map::operator[]): Make the
non-template overloads call try_emplace directly.  Remove
non-standard same_as constraint on the template overload.
* testsuite/23_containers/flat_map/1.cc (test08): New test.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
(cherry picked from commit 91ed3248ce26aaaee4d7471aa4edbc07b3f1a90e)
libstdc++-v3/include/std/flat_map
libstdc++-v3/testsuite/23_containers/flat_map/1.cc