[libcxx-commits] [libcxx] [libcxx] makes `pair` conditionally trivially copyable for C++20 (PR #84811)
Christopher Di Bella via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Mar 11 13:29:26 PDT 2024
cjdb 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? If it is, is there a reason folks compiling different parts of their binary aren't able to disable this particular feature?
@jyknight might have more insight into this from a practical perspective.
> 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.
```cpp
// 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&) { ... }
```
https://github.com/llvm/llvm-project/pull/84811
More information about the libcxx-commits
mailing list