[libcxx-commits] [libcxx] [libc++] Assert preconditions of operator= of containers (PR #129625)

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 10 21:40:36 PDT 2025


================
@@ -294,6 +295,9 @@ class _LIBCPP_TEMPLATE_VIS vector {
   vector(vector&& __x, const __type_identity_t<allocator_type>& __a);
   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector& operator=(vector&& __x)
       _NOEXCEPT_(__noexcept_move_assign_container<_Allocator, __alloc_traits>::value) {
+    static_assert(
+        __alloc_traits::propagate_on_container_move_assignment::value || is_move_assignable<value_type>::value,
+        "T must be Cpp17MoveAssignable");
----------------
halbi2 wrote:

I thought it as inappropriate to have `_` in a message going out to the user. It's possible to replace `T` with `value_type`, as the standard does say `value_type`. That is not technically correct because `map<int, int>::value_type` can be `pair<const int, int>` which is not move assignable. I will change the message if you feel strongly either way.

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


More information about the libcxx-commits mailing list