Skip to content

Commit 4f79ef4

Browse files
authored
[libc++] Revert "Make std::pair trivially copyable if its members are (#89652)" (#100184)
This reverts commit f9dd885. We're not certain yet whether the patch has issues, so we are reverting until we've had time to investigate.
1 parent 52ebd8d commit 4f79ef4

File tree

5 files changed

+6
-72
lines changed

5 files changed

+6
-72
lines changed

libcxx/include/__configuration/abi.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@
9898
// and WCHAR_MAX. This ABI setting determines whether we should instead track whether the fill
9999
// value has been initialized using a separate boolean, which changes the ABI.
100100
# define _LIBCPP_ABI_IOS_ALLOW_ARBITRARY_FILL_VALUE
101-
// Make a std::pair of trivially copyable types trivially copyable.
102-
// While this technically doesn't change the layout of pair itself, other types may decide to programatically change
103-
// their representation based on whether something is trivially copyable.
104-
# define _LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR
105101
#elif _LIBCPP_ABI_VERSION == 1
106102
# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
107103
// Enable compiling copies of now inline methods into the dylib to support

libcxx/include/__type_traits/datasizeof.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ struct _FirstPaddingByte<_Tp, true> {
5454
// the use as an extension.
5555
_LIBCPP_DIAGNOSTIC_PUSH
5656
_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-offsetof")
57-
_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Winvalid-offsetof")
5857
template <class _Tp>
5958
inline const size_t __datasizeof_v = offsetof(_FirstPaddingByte<_Tp>, __first_padding_byte_);
6059
_LIBCPP_DIAGNOSTIC_POP

libcxx/include/__utility/pair.h

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <__type_traits/is_implicitly_default_constructible.h>
3333
#include <__type_traits/is_nothrow_assignable.h>
3434
#include <__type_traits/is_nothrow_constructible.h>
35-
#include <__type_traits/is_reference.h>
3635
#include <__type_traits/is_same.h>
3736
#include <__type_traits/is_swappable.h>
3837
#include <__type_traits/is_trivially_relocatable.h>
@@ -81,38 +80,6 @@ struct _LIBCPP_TEMPLATE_VIS pair
8180
_LIBCPP_HIDE_FROM_ABI pair(pair const&) = default;
8281
_LIBCPP_HIDE_FROM_ABI pair(pair&&) = default;
8382

84-
// When we are requested for pair to be trivially copyable by the ABI macro, we use defaulted members
85-
// if it is both legal to do it (i.e. no references) and we have a way to actually implement it, which requires
86-
// the __enable_if__ attribute before C++20.
87-
#ifdef _LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR
88-
// FIXME: This should really just be a static constexpr variable. It's in a struct to avoid gdb printing the value
89-
// when printing a pair
90-
struct __has_defaulted_members {
91-
static const bool value = !is_reference<first_type>::value && !is_reference<second_type>::value;
92-
};
93-
# if _LIBCPP_STD_VER >= 20
94-
_LIBCPP_HIDE_FROM_ABI constexpr pair& operator=(const pair&)
95-
requires __has_defaulted_members::value
96-
= default;
97-
98-
_LIBCPP_HIDE_FROM_ABI constexpr pair& operator=(pair&&)
99-
requires __has_defaulted_members::value
100-
= default;
101-
# elif __has_attribute(__enable_if__)
102-
_LIBCPP_HIDE_FROM_ABI pair& operator=(const pair&)
103-
__attribute__((__enable_if__(__has_defaulted_members::value, ""))) = default;
104-
105-
_LIBCPP_HIDE_FROM_ABI pair& operator=(pair&&)
106-
__attribute__((__enable_if__(__has_defaulted_members::value, ""))) = default;
107-
# else
108-
# error "_LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR isn't supported with this compiler"
109-
# endif
110-
#else
111-
struct __has_defaulted_members {
112-
static const bool value = false;
113-
};
114-
#endif // defined(_LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR) && __has_attribute(__enable_if__)
115-
11683
#ifdef _LIBCPP_CXX03_LANG
11784
_LIBCPP_HIDE_FROM_ABI pair() : first(), second() {}
11885

@@ -258,8 +225,7 @@ struct _LIBCPP_TEMPLATE_VIS pair
258225
typename __make_tuple_indices<sizeof...(_Args2) >::type()) {}
259226

260227
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair&
261-
operator=(__conditional_t<!__has_defaulted_members::value && is_copy_assignable<first_type>::value &&
262-
is_copy_assignable<second_type>::value,
228+
operator=(__conditional_t<is_copy_assignable<first_type>::value && is_copy_assignable<second_type>::value,
263229
pair,
264230
__nat> const& __p) noexcept(is_nothrow_copy_assignable<first_type>::value &&
265231
is_nothrow_copy_assignable<second_type>::value) {
@@ -268,12 +234,10 @@ struct _LIBCPP_TEMPLATE_VIS pair
268234
return *this;
269235
}
270236

271-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair&
272-
operator=(__conditional_t<!__has_defaulted_members::value && is_move_assignable<first_type>::value &&
273-
is_move_assignable<second_type>::value,
274-
pair,
275-
__nat>&& __p) noexcept(is_nothrow_move_assignable<first_type>::value &&
276-
is_nothrow_move_assignable<second_type>::value) {
237+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& operator=(
238+
__conditional_t<is_move_assignable<first_type>::value && is_move_assignable<second_type>::value, pair, __nat>&&
239+
__p) noexcept(is_nothrow_move_assignable<first_type>::value &&
240+
is_nothrow_move_assignable<second_type>::value) {
277241
first = std::forward<first_type>(__p.first);
278242
second = std::forward<second_type>(__p.second);
279243
return *this;

libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/abi.trivial_copy_move.pass.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,8 @@ void test_trivial()
162162
static_assert(!std::is_trivially_copy_constructible<P>::value, "");
163163
static_assert(!std::is_trivially_move_constructible<P>::value, "");
164164
#endif // TEST_STD_VER >= 11
165-
#ifndef _LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR
166165
static_assert(!std::is_trivially_copy_assignable<P>::value, "");
167166
static_assert(!std::is_trivially_move_assignable<P>::value, "");
168-
#else
169-
static_assert(std::is_trivially_copy_assignable<P>::value, "");
170-
static_assert(std::is_trivially_move_assignable<P>::value, "");
171-
#endif
172167
static_assert(std::is_trivially_destructible<P>::value, "");
173168
}
174169
}

libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/abi.trivially_copyable.compile.pass.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,42 +47,22 @@ static_assert(!std::is_trivially_copyable<std::pair<int&, int> >::value, "");
4747
static_assert(!std::is_trivially_copyable<std::pair<int, int&> >::value, "");
4848
static_assert(!std::is_trivially_copyable<std::pair<int&, int&> >::value, "");
4949

50-
#ifdef _LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR
51-
static_assert(std::is_trivially_copyable<std::pair<int, int> >::value, "");
52-
static_assert(std::is_trivially_copyable<std::pair<int, char> >::value, "");
53-
static_assert(std::is_trivially_copyable<std::pair<char, int> >::value, "");
54-
static_assert(std::is_trivially_copyable<std::pair<std::pair<char, char>, int> >::value, "");
55-
static_assert(std::is_trivially_copyable<std::pair<trivially_copyable, int> >::value, "");
56-
#else
5750
static_assert(!std::is_trivially_copyable<std::pair<int, int> >::value, "");
5851
static_assert(!std::is_trivially_copyable<std::pair<int, char> >::value, "");
5952
static_assert(!std::is_trivially_copyable<std::pair<char, int> >::value, "");
6053
static_assert(!std::is_trivially_copyable<std::pair<std::pair<char, char>, int> >::value, "");
6154
static_assert(!std::is_trivially_copyable<std::pair<trivially_copyable, int> >::value, "");
62-
#endif // _LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR
63-
6455
#if TEST_STD_VER == 03 // Known ABI difference
6556
static_assert(!std::is_trivially_copyable<std::pair<trivially_copyable_no_copy_assignment, int> >::value, "");
6657
static_assert(!std::is_trivially_copyable<std::pair<trivially_copyable_no_move_assignment, int> >::value, "");
6758
#else
6859
static_assert(std::is_trivially_copyable<std::pair<trivially_copyable_no_copy_assignment, int> >::value, "");
6960
static_assert(std::is_trivially_copyable<std::pair<trivially_copyable_no_move_assignment, int> >::value, "");
7061
#endif
71-
72-
#ifdef _LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR
73-
static_assert(std::is_trivially_copyable<std::pair<trivially_copyable_no_construction, int> >::value, "");
74-
#else
7562
static_assert(!std::is_trivially_copyable<std::pair<trivially_copyable_no_construction, int> >::value, "");
76-
#endif
7763

7864
static_assert(std::is_trivially_copy_constructible<std::pair<int, int> >::value, "");
7965
static_assert(std::is_trivially_move_constructible<std::pair<int, int> >::value, "");
80-
static_assert(std::is_trivially_destructible<std::pair<int, int> >::value, "");
81-
82-
#ifdef _LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR
83-
static_assert(std::is_trivially_copy_assignable<std::pair<int, int> >::value, "");
84-
static_assert(std::is_trivially_move_assignable<std::pair<int, int> >::value, "");
85-
#else
8666
static_assert(!std::is_trivially_copy_assignable<std::pair<int, int> >::value, "");
8767
static_assert(!std::is_trivially_move_assignable<std::pair<int, int> >::value, "");
88-
#endif // _LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR
68+
static_assert(std::is_trivially_destructible<std::pair<int, int> >::value, "");

0 commit comments

Comments
 (0)