[libcxx-commits] [libcxx] [libc++] Avoid type-punning between __value_type and pair (PR #134819)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 7 08:53:32 PDT 2025


================
@@ -1510,17 +1446,18 @@ map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
     : __tree_(std::move(__m.__tree_), typename __base::allocator_type(__a)) {
   if (__a != __m.get_allocator()) {
     const_iterator __e = cend();
-    while (!__m.empty())
-      __tree_.__insert_unique(__e.__i_, __m.__tree_.remove(__m.begin().__i_)->__value_.__move());
+    while (!__m.empty()) {
+      __tree_.__insert_unique(
+          __e.__i_, reinterpret_cast<pair<_Key, _Tp>&&>(__m.__tree_.remove(__m.begin().__i_)->__value_));
----------------
ldionne wrote:

This is scary. Do we really need a `reinterpret_cast` here? If so, that would make me question that the approach we're taking is the right one.

https://github.com/llvm/llvm-project/pull/134819


More information about the libcxx-commits mailing list