[libcxx-commits] [libcxx] [libc++] Make std::pair trivially copyable if its members are (PR #89652)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 23 12:11:20 PDT 2024


ldionne wrote:

> > I'm not sure why a `pair` with a `const` member is not trivially copyable anymore though. An explicitly defaulted special member should just be implicitly deleted.
> 
> Right? I'm banging my head against that one too.

@philnik777 Here's something strange:

```cpp
  _LIBCPP_HIDE_FROM_ABI constexpr pair& operator=(const pair&)
    requires (__has_defaulted_members::value && is_copy_assignable<first_type>::value && is_copy_assignable<second_type>::value)
  = default;

  _LIBCPP_HIDE_FROM_ABI constexpr pair& operator=(const pair&)
    requires (__has_defaulted_members::value && !(is_copy_assignable<first_type>::value && is_copy_assignable<second_type>::value))
  = delete;

  _LIBCPP_HIDE_FROM_ABI constexpr pair& operator=(pair&&)
    requires (__has_defaulted_members::value && is_move_assignable<first_type>::value && is_move_assignable<second_type>::value)
  = default;

//   _LIBCPP_HIDE_FROM_ABI constexpr pair& operator=(pair&&)
//     requires (__has_defaulted_members::value && !(is_move_assignable<first_type>::value && is_move_assignable<second_type>::value))
//   = delete;
```

Using this set of defaulted operators fixes @nico 's example in C++20 and C++23 (see https://godbolt.org/z/8M9xKEMdP). But uncommenting the `operator=(pair&&) = delete` one breaks it in both standard modes (see https://godbolt.org/z/9oWKxe4fh). I don't understand this.

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


More information about the libcxx-commits mailing list