1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

Revert "Switch to std::is_trivially_move_constructible and std::is_trivially_copy_constructible"

This reverts commit c8d406c93c5bb01599990201f78d8428dd29d289.

Builds are broken with some versions of GCC.
This commit is contained in:
Mehdi Amini 2020-12-03 19:57:34 +00:00
parent d8132da4e7
commit 91270b1460
6 changed files with 141 additions and 5 deletions

View File

@ -57,7 +57,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 ReturnT, typename... ParamTs> class UniqueFunctionBase {
@ -83,8 +83,8 @@ protected:
template <typename T>
using AdjustedParamT = typename std::conditional<
!std::is_reference<T>::value &&
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

@ -278,8 +278,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> {
protected:

View File

@ -70,6 +70,20 @@ 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 {
@ -78,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

@ -80,6 +80,7 @@ add_llvm_unittest(SupportTests
TimerTest.cpp
ToolOutputFileTest.cpp
TypeNameTest.cpp
TypeTraitsTest.cpp
TrailingObjectsTest.cpp
TrigramIndexTest.cpp
UnicodeTest.cpp

View File

@ -0,0 +1,97 @@
//===- TypeTraitsTest.cpp -------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/type_traits.h"
#include "gtest/gtest.h"
namespace {
// Compile-time tests using static assert.
namespace triviality {
// Helper for compile time checking trivially copy constructible and trivially
// move constructible type traits.
template <typename T, bool IsTriviallyCopyConstructible,
bool IsTriviallyMoveConstructible>
void TrivialityTester() {
static_assert(llvm::is_trivially_copy_constructible<T>::value ==
IsTriviallyCopyConstructible,
"Mismatch in expected trivial copy construction!");
static_assert(llvm::is_trivially_move_constructible<T>::value ==
IsTriviallyMoveConstructible,
"Mismatch in expected trivial move construction!");
#if defined(_LIBCPP_VERSION) || defined(_MSC_VER)
// On compilers with support for the standard traits, make sure they agree.
static_assert(std::is_trivially_copy_constructible<T>::value ==
IsTriviallyCopyConstructible,
"Mismatch in expected trivial copy construction!");
static_assert(std::is_trivially_move_constructible<T>::value ==
IsTriviallyMoveConstructible,
"Mismatch in expected trivial move construction!");
#endif
}
template void TrivialityTester<int, true, true>();
template void TrivialityTester<void *, true, true>();
template void TrivialityTester<int &, true, true>();
template void TrivialityTester<int &&, false, true>();
struct X {};
struct Y {
Y(const Y &);
};
struct Z {
Z(const Z &);
Z(Z &&);
};
struct A {
A(const A &) = default;
A(A &&);
};
struct B {
B(const B &);
B(B &&) = default;
};
template void TrivialityTester<X, true, true>();
template void TrivialityTester<Y, false, false>();
template void TrivialityTester<Z, false, false>();
template void TrivialityTester<A, true, false>();
template void TrivialityTester<B, false, true>();
template void TrivialityTester<Z &, true, true>();
template void TrivialityTester<A &, true, true>();
template void TrivialityTester<B &, true, true>();
template void TrivialityTester<Z &&, false, true>();
template void TrivialityTester<A &&, false, true>();
template void TrivialityTester<B &&, false, true>();
TEST(Triviality, Tester) {
TrivialityTester<int, true, true>();
TrivialityTester<void *, true, true>();
TrivialityTester<int &, true, true>();
TrivialityTester<int &&, false, true>();
TrivialityTester<X, true, true>();
TrivialityTester<Y, false, false>();
TrivialityTester<Z, false, false>();
TrivialityTester<A, true, false>();
TrivialityTester<B, false, true>();
TrivialityTester<Z &, true, true>();
TrivialityTester<A &, true, true>();
TrivialityTester<B &, true, true>();
TrivialityTester<Z &&, false, true>();
TrivialityTester<A &&, false, true>();
TrivialityTester<B &&, false, true>();
}
} // namespace triviality
} // end anonymous namespace

View File

@ -85,6 +85,7 @@ unittest("SupportTests") {
"TrailingObjectsTest.cpp",
"TrigramIndexTest.cpp",
"TypeNameTest.cpp",
"TypeTraitsTest.cpp",
"UnicodeTest.cpp",
"VersionTupleTest.cpp",
"VirtualFileSystemTest.cpp",