1 //===- TypeTraitsTest.cpp -------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Support/type_traits.h"
10 #include "gtest/gtest.h"
14 // Compile-time tests using static assert.
15 namespace triviality
{
17 // Helper for compile time checking trivially copy constructible and trivially
18 // move constructible type traits.
19 template <typename T
, bool IsTriviallyCopyConstructible
,
20 bool IsTriviallyMoveConstructible
>
21 void TrivialityTester() {
22 static_assert(llvm::is_trivially_copy_constructible
<T
>::value
==
23 IsTriviallyCopyConstructible
,
24 "Mismatch in expected trivial copy construction!");
25 static_assert(llvm::is_trivially_move_constructible
<T
>::value
==
26 IsTriviallyMoveConstructible
,
27 "Mismatch in expected trivial move construction!");
29 #if defined(_LIBCPP_VERSION) || defined(_MSC_VER)
30 // On compilers with support for the standard traits, make sure they agree.
31 static_assert(std::is_trivially_copy_constructible
<T
>::value
==
32 IsTriviallyCopyConstructible
,
33 "Mismatch in expected trivial copy construction!");
34 static_assert(std::is_trivially_move_constructible
<T
>::value
==
35 IsTriviallyMoveConstructible
,
36 "Mismatch in expected trivial move construction!");
40 template void TrivialityTester
<int, true, true>();
41 template void TrivialityTester
<void *, true, true>();
42 template void TrivialityTester
<int &, true, true>();
43 template void TrivialityTester
<int &&, false, true>();
54 A(const A
&) = default;
62 template void TrivialityTester
<X
, true, true>();
63 template void TrivialityTester
<Y
, false, false>();
64 template void TrivialityTester
<Z
, false, false>();
65 template void TrivialityTester
<A
, true, false>();
66 template void TrivialityTester
<B
, false, true>();
68 template void TrivialityTester
<Z
&, true, true>();
69 template void TrivialityTester
<A
&, true, true>();
70 template void TrivialityTester
<B
&, true, true>();
71 template void TrivialityTester
<Z
&&, false, true>();
72 template void TrivialityTester
<A
&&, false, true>();
73 template void TrivialityTester
<B
&&, false, true>();
75 TEST(Triviality
, Tester
) {
76 TrivialityTester
<int, true, true>();
77 TrivialityTester
<void *, true, true>();
78 TrivialityTester
<int &, true, true>();
79 TrivialityTester
<int &&, false, true>();
81 TrivialityTester
<X
, true, true>();
82 TrivialityTester
<Y
, false, false>();
83 TrivialityTester
<Z
, false, false>();
84 TrivialityTester
<A
, true, false>();
85 TrivialityTester
<B
, false, true>();
87 TrivialityTester
<Z
&, true, true>();
88 TrivialityTester
<A
&, true, true>();
89 TrivialityTester
<B
&, true, true>();
90 TrivialityTester
<Z
&&, false, true>();
91 TrivialityTester
<A
&&, false, true>();
92 TrivialityTester
<B
&&, false, true>();
95 } // namespace triviality
97 } // end anonymous namespace