Revert "[llvm] Remove llvm::is_trivially_{copy/move}_constructible (NFC)"

This reverts commit 01ffe31cbb.

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.
This commit is contained in:
Kazu Hirata 2022-09-16 18:26:19 -07:00
parent 6cf11f4462
commit 29c841ce93
5 changed files with 52 additions and 13 deletions

View File

@ -59,7 +59,7 @@ namespace detail {
template <typename T>
using EnableIfTrivial =
std::enable_if_t<std::is_trivially_move_constructible<T>::value &&
std::enable_if_t<llvm::is_trivially_move_constructible<T>::value &&
std::is_trivially_destructible<T>::value>;
template <typename CallableT, typename ThisT>
using EnableUnlessSameType =
@ -100,8 +100,8 @@ protected:
static_assert(!std::is_reference<T>::value,
"references should be handled by template specialization");
using type = typename std::conditional<
std::is_trivially_copy_constructible<T>::value &&
std::is_trivially_move_constructible<T>::value &&
llvm::is_trivially_copy_constructible<T>::value &&
llvm::is_trivially_move_constructible<T>::value &&
IsSizeLessThanThresholdT<T>::value,
T, T &>::type;
};

View File

@ -50,12 +50,13 @@ namespace optional_detail {
//
// The move constructible / assignable conditions emulate the remaining behavior
// of std::is_trivially_copyable.
template <typename T, bool = (std::is_trivially_copy_constructible<T>::value &&
std::is_trivially_copy_assignable<T>::value &&
(std::is_trivially_move_constructible<T>::value ||
!std::is_move_constructible<T>::value) &&
(std::is_trivially_move_assignable<T>::value ||
!std::is_move_assignable<T>::value))>
template <typename T,
bool = (llvm::is_trivially_copy_constructible<T>::value &&
std::is_trivially_copy_assignable<T>::value &&
(llvm::is_trivially_move_constructible<T>::value ||
!std::is_move_constructible<T>::value) &&
(std::is_trivially_move_assignable<T>::value ||
!std::is_move_assignable<T>::value))>
class OptionalStorage {
union {
char empty;

View File

@ -312,8 +312,8 @@ public:
/// copy these types with memcpy, there is no way for the type to observe this.
/// This catches the important case of std::pair<POD, POD>, which is not
/// trivially assignable.
template <typename T, bool = (std::is_trivially_copy_constructible<T>::value) &&
(std::is_trivially_move_constructible<T>::value) &&
template <typename T, bool = (is_trivially_copy_constructible<T>::value) &&
(is_trivially_move_constructible<T>::value) &&
std::is_trivially_destructible<T>::value>
class SmallVectorTemplateBase : public SmallVectorTemplateCommon<T> {
friend class SmallVectorTemplateCommon<T>;

View File

@ -70,6 +70,21 @@ struct const_pointer_or_const_ref<T,
};
namespace detail {
/// Internal utility to detect trivial copy construction.
template<typename T> union copy_construction_triviality_helper {
T t;
copy_construction_triviality_helper() = default;
copy_construction_triviality_helper(const copy_construction_triviality_helper&) = default;
~copy_construction_triviality_helper() = default;
};
/// Internal utility to detect trivial move construction.
template<typename T> union move_construction_triviality_helper {
T t;
move_construction_triviality_helper() = default;
move_construction_triviality_helper(move_construction_triviality_helper&&) = default;
~move_construction_triviality_helper() = default;
};
template<class T>
union trivial_helper {
T t;
@ -77,6 +92,29 @@ union trivial_helper {
} // end namespace detail
/// An implementation of `std::is_trivially_copy_constructible` since we have
/// users with STLs that don't yet include it.
template <typename T>
struct is_trivially_copy_constructible
: std::is_copy_constructible<
::llvm::detail::copy_construction_triviality_helper<T>> {};
template <typename T>
struct is_trivially_copy_constructible<T &> : std::true_type {};
template <typename T>
struct is_trivially_copy_constructible<T &&> : std::false_type {};
/// An implementation of `std::is_trivially_move_constructible` since we have
/// users with STLs that don't yet include it.
template <typename T>
struct is_trivially_move_constructible
: std::is_move_constructible<
::llvm::detail::move_construction_triviality_helper<T>> {};
template <typename T>
struct is_trivially_move_constructible<T &> : std::true_type {};
template <typename T>
struct is_trivially_move_constructible<T &&> : std::true_type {};
template <typename T>
struct is_copy_assignable {
template<class F>

View File

@ -26,10 +26,10 @@ namespace triviality {
template <typename T, bool IsTriviallyCopyConstructible,
bool IsTriviallyMoveConstructible>
void TrivialityTester() {
static_assert(std::is_trivially_copy_constructible<T>::value ==
static_assert(llvm::is_trivially_copy_constructible<T>::value ==
IsTriviallyCopyConstructible,
"Mismatch in expected trivial copy construction!");
static_assert(std::is_trivially_move_constructible<T>::value ==
static_assert(llvm::is_trivially_move_constructible<T>::value ==
IsTriviallyMoveConstructible,
"Mismatch in expected trivial move construction!");