@@ -1348,10 +1348,24 @@ private:
13481348 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static void __assign_value (__get_node_value_type_t <value_type>& __lhs, _From&& __rhs) {
13491349 using __key_type = typename _NodeTypes::key_type;
13501350
1351- // This is technically UB, since the object was constructed as `const`.
1352- // Clang doesn't optimize on this currently though.
1353- const_cast <__key_type&>(__lhs.first ) = const_cast <__copy_cvref_t <_From, __key_type>&&>(__rhs.first );
1354- __lhs.second = std::forward<_From>(__rhs).second ;
1351+ if (std::is_constant_evaluated ()){
1352+ __get_node_value_type_t <value_type> tmp {__rhs.first , __rhs.second };
1353+ // tmp.first = const_cast<__copy_cvref_t<_From, __key_type>&&>(__rhs.first);
1354+ // tmp.second = std::forward<_From>(__rhs).second;
1355+ // __lhs = pair<const int, double>
1356+ // TODO: use a better name
1357+ using foo_type = __get_node_value_type_t <value_type>;
1358+ // const_cast is not allowed at constexpr time.
1359+ // we get around this by deleting and creating a new node value
1360+ __lhs.~foo_type ();
1361+ new (&__lhs)(foo_type) (tmp);
1362+ // __lhs = std::move(tmp);
1363+ } else {
1364+ // This is technically UB, since the object was constructed as `const`.
1365+ // Clang doesn't optimize on this currently though.
1366+ const_cast <__key_type&>(__lhs.first ) = const_cast <__copy_cvref_t <_From, __key_type>&&>(__rhs.first );
1367+ __lhs.second = std::forward<_From>(__rhs).second ;
1368+ }
13551369 }
13561370
13571371 template <class _To , class _From , class _ValueT = _Tp, __enable_if_t <!__is_tree_value_type<_ValueT>::value, int > = 0 >
0 commit comments