[libcxx-commits] [libcxx] [libcxx] makes `pair` conditionally trivially copyable for C++20 (PR #84811)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Mar 11 13:45:09 PDT 2024
philnik777 wrote:
> > Isn't this an ODR violation when compiling pre-C++20 code and C++20 code in the unstable ABI?
>
> Technically, yes, but I wonder if it's in the same vein as the ABI break we talked about. Is this a concern for our unstable ABI users?
I think it's fine. I just wanted to call it out so we're all on the same page about this.
> > Why didn't the return type SFINAE not work out?
>
> SFINAE only works in dependent contexts, and I don't think SMFs can ever be dependent.
>
> ```c++
> // Not SFINAE
> auto operator=(pair const&)
> -> enable_if<is_trivially_copy_assignable_v<T> && is_trivially_copy_assignable_v<U>> = default;
>
> // Not a copy assignment operator; can't be defaulted
> pair& operator=(__conditional_t<is_trivially_copy_assignable_v<X> && is_trivially_copy_assignable_v<Y>,
> pair,
> __nat> const&) = default;
>
> // Not a copy assignment operator; can't be defaulted
> template<class X = T, class Y = U>
> auto operator=(pair const&)
> -> enable_if<is_trivially_copy_assignable_v<X> && is_trivially_copy_assignable_v<Y>> = default;
>
> // defaulted constructors seem to preclude this approach
> pair& operator=(__conditional_t<is_trivially_copy_assignable_v<X> && is_trivially_copy_assignable_v<Y>,
> __nat,
> pair> const&) = delete;
>
> template<bool = true>
> pair& operator=(__conditional_t<!(is_trivially_copy_assignable_v<X> && is_trivially_copy_assignable_v<Y>),
> pair,
> __nat> const&) { ... }
> ```
Urgh, right. Maybe we could handle it through a base class that is templated on whether we can default the assignment?
https://github.com/llvm/llvm-project/pull/84811
More information about the libcxx-commits
mailing list