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"
13 // Compile-time tests using static assert.
14 namespace triviality
{
16 // Helper for compile time checking trivially copy constructible and trivially
17 // move constructible type traits.
18 template <typename T
, bool IsTriviallyCopyConstructible
,
19 bool IsTriviallyMoveConstructible
>
20 void TrivialityTester() {
21 static_assert(llvm::is_trivially_copy_constructible
<T
>::value
==
22 IsTriviallyCopyConstructible
,
23 "Mismatch in expected trivial copy construction!");
24 static_assert(llvm::is_trivially_move_constructible
<T
>::value
==
25 IsTriviallyMoveConstructible
,
26 "Mismatch in expected trivial move construction!");
28 #if defined(_LIBCPP_VERSION) || defined(_MSC_VER)
29 // On compilers with support for the standard traits, make sure they agree.
30 static_assert(std::is_trivially_copy_constructible
<T
>::value
==
31 IsTriviallyCopyConstructible
,
32 "Mismatch in expected trivial copy construction!");
33 static_assert(std::is_trivially_move_constructible
<T
>::value
==
34 IsTriviallyMoveConstructible
,
35 "Mismatch in expected trivial move construction!");
39 template void TrivialityTester
<int, true, true>();
40 template void TrivialityTester
<void *, true, true>();
41 template void TrivialityTester
<int &, true, true>();
42 template void TrivialityTester
<int &&, false, true>();
53 A(const A
&) = default;
61 template void TrivialityTester
<X
, true, true>();
62 template void TrivialityTester
<Y
, false, false>();
63 template void TrivialityTester
<Z
, false, false>();
64 template void TrivialityTester
<A
, true, false>();
65 template void TrivialityTester
<B
, false, true>();
67 template void TrivialityTester
<Z
&, true, true>();
68 template void TrivialityTester
<A
&, true, true>();
69 template void TrivialityTester
<B
&, true, true>();
70 template void TrivialityTester
<Z
&&, false, true>();
71 template void TrivialityTester
<A
&&, false, true>();
72 template void TrivialityTester
<B
&&, false, true>();
74 } // namespace triviality
76 } // end anonymous namespace