blob: 1f63401dacb756ef3355d719817a6a4dd9ea17da [file] [log] [blame]
Howard Hinnant1468b662010-11-19 22:17:28 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// type_traits
11
12// is_trivially_default_constructible
13
14#include <type_traits>
15
16template <class T>
17void test_is_trivially_default_constructible()
18{
19 static_assert( std::is_trivially_default_constructible<T>::value, "");
20 static_assert( std::is_trivially_default_constructible<const T>::value, "");
21 static_assert( std::is_trivially_default_constructible<volatile T>::value, "");
22 static_assert( std::is_trivially_default_constructible<const volatile T>::value, "");
23}
24
25template <class T>
26void test_has_not_trivial_default_constructor()
27{
28 static_assert(!std::is_trivially_default_constructible<T>::value, "");
29 static_assert(!std::is_trivially_default_constructible<const T>::value, "");
30 static_assert(!std::is_trivially_default_constructible<volatile T>::value, "");
31 static_assert(!std::is_trivially_default_constructible<const volatile T>::value, "");
Howard Hinnant1468b662010-11-19 22:17:28 +000032}
33
34class Empty
35{
36};
37
38class NotEmpty
39{
40 virtual ~NotEmpty();
41};
42
43union Union {};
44
45struct bit_zero
46{
47 int : 0;
48};
49
50class Abstract
51{
52 virtual ~Abstract() = 0;
53};
54
55struct A
56{
57 A();
58};
59
60int main()
61{
62 test_has_not_trivial_default_constructor<void>();
63 test_has_not_trivial_default_constructor<int&>();
64 test_has_not_trivial_default_constructor<A>();
65 test_has_not_trivial_default_constructor<Abstract>();
66 test_has_not_trivial_default_constructor<NotEmpty>();
67
68 test_is_trivially_default_constructible<Union>();
69 test_is_trivially_default_constructible<Empty>();
70 test_is_trivially_default_constructible<int>();
71 test_is_trivially_default_constructible<double>();
72 test_is_trivially_default_constructible<int*>();
73 test_is_trivially_default_constructible<const int*>();
74 test_is_trivially_default_constructible<char[3]>();
75 test_is_trivially_default_constructible<bit_zero>();
76}