summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2018-07-03 01:18:21 +0000
committerChandler Carruth <chandlerc@gmail.com>2018-07-03 01:18:21 +0000
commitf814ad8932ef070ae901677299beecb4410e1b53 (patch)
treecc86a5792708a8eb8370899419cfe403f9048d00 /llvm/unittests/Support
parentf8182f1aef5b6ec74cbe2c1618e759f0113921ba (diff)
downloadbcm5719-llvm-f814ad8932ef070ae901677299beecb4410e1b53.tar.gz
bcm5719-llvm-f814ad8932ef070ae901677299beecb4410e1b53.zip
[Support] Fix llvm::unique_function when building with GCC 4.9 by
introducing llvm::trivially_{copy,move}_constructible type traits. This uses a completely portable implementation of these traits provided by Richard Smith. You can see it on compiler explorer in all its glory: https://godbolt.org/g/QEDZjW I have transcribed it, clang-formatted it, added some comments, and made the tests fit into a unittest file. I have also switched llvm::unique_function over to use these new, much more portable traits. =D Hopefully this will fix the build bot breakage from my prior commit. llvm-svn: 336161
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r--llvm/unittests/Support/CMakeLists.txt1
-rw-r--r--llvm/unittests/Support/TypeTraitsTest.cpp77
2 files changed, 78 insertions, 0 deletions
diff --git a/llvm/unittests/Support/CMakeLists.txt b/llvm/unittests/Support/CMakeLists.txt
index 655ca7fb9b4..852180c5cf9 100644
--- a/llvm/unittests/Support/CMakeLists.txt
+++ b/llvm/unittests/Support/CMakeLists.txt
@@ -59,6 +59,7 @@ add_llvm_unittest(SupportTests
Threading.cpp
TimerTest.cpp
TypeNameTest.cpp
+ TypeTraitsTest.cpp
TrailingObjectsTest.cpp
TrigramIndexTest.cpp
UnicodeTest.cpp
diff --git a/llvm/unittests/Support/TypeTraitsTest.cpp b/llvm/unittests/Support/TypeTraitsTest.cpp
new file mode 100644
index 00000000000..06ff9cc7b28
--- /dev/null
+++ b/llvm/unittests/Support/TypeTraitsTest.cpp
@@ -0,0 +1,77 @@
+//===- TypeTraitsTest.cpp -------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/type_traits.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 __clang__ || _MSC_VER || __GNUC__ > 5
+ // 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>();
+
+} // namespace triviality
+
+} // end anonymous namespace
OpenPOWER on IntegriCloud