[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:31 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);
----------------
ldionne wrote:

This is technically UB since we're assigning to an object that was created as `const`. I know this is a pre-existing condition in the code, but this needs a comment.

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


More information about the libcxx-commits mailing list