Skip to content

Commit 29c841c

Browse files
Revert "[llvm] Remove llvm::is_trivially_{copy/move}_constructible (NFC)"
This reverts commit 01ffe31. A build breakage with GCC 7.3 has been reported: https://reviews.llvm.org/D132311#3797053 FWIW, GCC 7.5 is OK according to Pavel Chupin. I also personally tested GCC 8.4.0.
1 parent 6cf11f4 commit 29c841c

File tree

5 files changed

+52
-13
lines changed

5 files changed

+52
-13
lines changed

llvm/include/llvm/ADT/FunctionExtras.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace detail {
5959

6060
template <typename T>
6161
using EnableIfTrivial =
62-
std::enable_if_t<std::is_trivially_move_constructible<T>::value &&
62+
std::enable_if_t<llvm::is_trivially_move_constructible<T>::value &&
6363
std::is_trivially_destructible<T>::value>;
6464
template <typename CallableT, typename ThisT>
6565
using EnableUnlessSameType =
@@ -100,8 +100,8 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
100100
static_assert(!std::is_reference<T>::value,
101101
"references should be handled by template specialization");
102102
using type = typename std::conditional<
103-
std::is_trivially_copy_constructible<T>::value &&
104-
std::is_trivially_move_constructible<T>::value &&
103+
llvm::is_trivially_copy_constructible<T>::value &&
104+
llvm::is_trivially_move_constructible<T>::value &&
105105
IsSizeLessThanThresholdT<T>::value,
106106
T, T &>::type;
107107
};

llvm/include/llvm/ADT/Optional.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ namespace optional_detail {
5050
//
5151
// The move constructible / assignable conditions emulate the remaining behavior
5252
// of std::is_trivially_copyable.
53-
template <typename T, bool = (std::is_trivially_copy_constructible<T>::value &&
54-
std::is_trivially_copy_assignable<T>::value &&
55-
(std::is_trivially_move_constructible<T>::value ||
56-
!std::is_move_constructible<T>::value) &&
57-
(std::is_trivially_move_assignable<T>::value ||
58-
!std::is_move_assignable<T>::value))>
53+
template <typename T,
54+
bool = (llvm::is_trivially_copy_constructible<T>::value &&
55+
std::is_trivially_copy_assignable<T>::value &&
56+
(llvm::is_trivially_move_constructible<T>::value ||
57+
!std::is_move_constructible<T>::value) &&
58+
(std::is_trivially_move_assignable<T>::value ||
59+
!std::is_move_assignable<T>::value))>
5960
class OptionalStorage {
6061
union {
6162
char empty;

llvm/include/llvm/ADT/SmallVector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ class SmallVectorTemplateCommon
312312
/// copy these types with memcpy, there is no way for the type to observe this.
313313
/// This catches the important case of std::pair<POD, POD>, which is not
314314
/// trivially assignable.
315-
template <typename T, bool = (std::is_trivially_copy_constructible<T>::value) &&
316-
(std::is_trivially_move_constructible<T>::value) &&
315+
template <typename T, bool = (is_trivially_copy_constructible<T>::value) &&
316+
(is_trivially_move_constructible<T>::value) &&
317317
std::is_trivially_destructible<T>::value>
318318
class SmallVectorTemplateBase : public SmallVectorTemplateCommon<T> {
319319
friend class SmallVectorTemplateCommon<T>;

llvm/include/llvm/Support/type_traits.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,51 @@ struct const_pointer_or_const_ref<T,
7070
};
7171

7272
namespace detail {
73+
/// Internal utility to detect trivial copy construction.
74+
template<typename T> union copy_construction_triviality_helper {
75+
T t;
76+
copy_construction_triviality_helper() = default;
77+
copy_construction_triviality_helper(const copy_construction_triviality_helper&) = default;
78+
~copy_construction_triviality_helper() = default;
79+
};
80+
/// Internal utility to detect trivial move construction.
81+
template<typename T> union move_construction_triviality_helper {
82+
T t;
83+
move_construction_triviality_helper() = default;
84+
move_construction_triviality_helper(move_construction_triviality_helper&&) = default;
85+
~move_construction_triviality_helper() = default;
86+
};
87+
7388
template<class T>
7489
union trivial_helper {
7590
T t;
7691
};
7792

7893
} // end namespace detail
7994

95+
/// An implementation of `std::is_trivially_copy_constructible` since we have
96+
/// users with STLs that don't yet include it.
97+
template <typename T>
98+
struct is_trivially_copy_constructible
99+
: std::is_copy_constructible<
100+
::llvm::detail::copy_construction_triviality_helper<T>> {};
101+
template <typename T>
102+
struct is_trivially_copy_constructible<T &> : std::true_type {};
103+
template <typename T>
104+
struct is_trivially_copy_constructible<T &&> : std::false_type {};
105+
106+
/// An implementation of `std::is_trivially_move_constructible` since we have
107+
/// users with STLs that don't yet include it.
108+
template <typename T>
109+
struct is_trivially_move_constructible
110+
: std::is_move_constructible<
111+
::llvm::detail::move_construction_triviality_helper<T>> {};
112+
template <typename T>
113+
struct is_trivially_move_constructible<T &> : std::true_type {};
114+
template <typename T>
115+
struct is_trivially_move_constructible<T &&> : std::true_type {};
116+
117+
80118
template <typename T>
81119
struct is_copy_assignable {
82120
template<class F>

llvm/unittests/Support/TypeTraitsTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ namespace triviality {
2626
template <typename T, bool IsTriviallyCopyConstructible,
2727
bool IsTriviallyMoveConstructible>
2828
void TrivialityTester() {
29-
static_assert(std::is_trivially_copy_constructible<T>::value ==
29+
static_assert(llvm::is_trivially_copy_constructible<T>::value ==
3030
IsTriviallyCopyConstructible,
3131
"Mismatch in expected trivial copy construction!");
32-
static_assert(std::is_trivially_move_constructible<T>::value ==
32+
static_assert(llvm::is_trivially_move_constructible<T>::value ==
3333
IsTriviallyMoveConstructible,
3434
"Mismatch in expected trivial move construction!");
3535

0 commit comments

Comments
 (0)