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

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Apr 14 12:20:19 PDT 2025


================
@@ -1276,6 +1278,19 @@ private:
   }
   _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__tree&, false_type) _NOEXCEPT {}
 
+  template <class _From, __enable_if_t<__is_pair_v<__remove_cvref_t<_From> >, int> = 0>
+  _LIBCPP_HIDE_FROM_ABI static void __assign_value(__get_node_value_type_t<value_type>& __lhs, _From&& __rhs) {
+    using __key_type = typename _NodeTypes::key_type;
+
+    const_cast<__key_type&>(__lhs.first) = const_cast<__copy_cvref_t<_From, __key_type>&&>(__rhs.first);
----------------
EricWF wrote:

Shouldn't the assignment only occur in the case where the key compares equal?



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


More information about the libcxx-commits mailing list