PR libstdc++/125374
libstdc++-v3/ChangeLog:
* include/std/flat_map (_Flat_map_impl::_M_try_emplace): Forward
instead of unconditionally moving __k when inserting it.
* testsuite/23_containers/flat_map/1.cc (test10): New test.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
return {iterator{this, __key_it}, false};
auto __guard = _M_make_clear_guard();
- __key_it = _M_cont.keys.insert(__key_it, std::move(__k));
+ __key_it = _M_cont.keys.insert(__key_it, std::forward<_Key2>(__k));
__value_it = _M_cont.values.begin() + (__key_it - _M_cont.keys.begin());
_M_cont.values.emplace(__value_it, std::forward<_Args>(__args)...);
__guard._M_disable();
#include <testsuite_allocator.h>
#include <testsuite_hooks.h>
#include <testsuite_iterators.h>
+#include <string>
#include <tuple>
struct Gt {
using value_type = std::pair<int, int>;
}
+constexpr
+void
+test10()
+{
+ // PR libstdc++/125374 - flat_map unconditionally moves from lvalue keys in
+ // _M_try_emplace
+ std::flat_map<std::string, int, std::less<>> m;
+ std::string k = "hello";
+ m[k] = 1;
+ VERIFY (k == "hello");
+ k = "world";
+ m.try_emplace(k, 2);
+ VERIFY (k == "world");
+}
+
void
test()
{
test07();
test08();
test09();
+ test10();
}
constexpr
test07();
test08();
test09();
+ test10();
return true;
}