Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / meta / meta.unary / meta.unary.prop / is_trivially_copyable.pass.cpp
blob4f0d31a30fd474f4bdf4c1d384ef3c1e1f071b9a
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // type_traits
11 // is_trivially_copyable
13 #include <type_traits>
14 #include <cassert>
15 #include "test_macros.h"
17 template <class T>
18 void test_is_trivially_copyable()
20 static_assert( std::is_trivially_copyable<T>::value, "");
21 static_assert( std::is_trivially_copyable<const T>::value, "");
22 static_assert( std::is_trivially_copyable<volatile T>::value, "");
23 static_assert( std::is_trivially_copyable<const volatile T>::value, "");
24 #if TEST_STD_VER > 14
25 static_assert( std::is_trivially_copyable_v<T>, "");
26 static_assert( std::is_trivially_copyable_v<const T>, "");
27 static_assert( std::is_trivially_copyable_v<volatile T>, "");
28 static_assert( std::is_trivially_copyable_v<const volatile T>, "");
29 #endif
32 template <class T>
33 void test_is_not_trivially_copyable()
35 static_assert(!std::is_trivially_copyable<T>::value, "");
36 static_assert(!std::is_trivially_copyable<const T>::value, "");
37 static_assert(!std::is_trivially_copyable<volatile T>::value, "");
38 static_assert(!std::is_trivially_copyable<const volatile T>::value, "");
39 #if TEST_STD_VER > 14
40 static_assert(!std::is_trivially_copyable_v<T>, "");
41 static_assert(!std::is_trivially_copyable_v<const T>, "");
42 static_assert(!std::is_trivially_copyable_v<volatile T>, "");
43 static_assert(!std::is_trivially_copyable_v<const volatile T>, "");
44 #endif
47 struct A
49 int i_;
52 struct B
54 int i_;
55 ~B() {assert(i_ == 0);}
58 class C
60 public:
61 C();
64 int main(int, char**)
66 test_is_trivially_copyable<int> ();
67 test_is_trivially_copyable<const int> ();
68 test_is_trivially_copyable<A> ();
69 test_is_trivially_copyable<const A> ();
70 test_is_trivially_copyable<C> ();
72 test_is_not_trivially_copyable<int&> ();
73 test_is_not_trivially_copyable<const A&> ();
74 test_is_not_trivially_copyable<B> ();
76 return 0;