blob: c8d5c42fbf89d15842f8bed59040baa6f59eb78a [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_default_constructible
13
14#include <type_traits>
15
Marshall Clow933afa92013-07-04 00:10:01 +000016template <class T>
Howard Hinnant1468b662010-11-19 22:17:28 +000017void test_is_default_constructible()
18{
Marshall Clow933afa92013-07-04 00:10:01 +000019 static_assert( std::is_default_constructible<T>::value, "");
20 static_assert( std::is_default_constructible<const T>::value, "");
21 static_assert( std::is_default_constructible<volatile T>::value, "");
22 static_assert( std::is_default_constructible<const volatile T>::value, "");
23}
24
25template <class T>
26void test_is_not_default_constructible()
27{
28 static_assert(!std::is_default_constructible<T>::value, "");
29 static_assert(!std::is_default_constructible<const T>::value, "");
30 static_assert(!std::is_default_constructible<volatile T>::value, "");
31 static_assert(!std::is_default_constructible<const volatile T>::value, "");
Howard Hinnant1468b662010-11-19 22:17:28 +000032}
33
34class Empty
35{
36};
37
Marshall Clow82837092014-12-09 15:07:42 +000038class NoDefaultConstructor
39{
Marshall Cloweea9d202015-01-28 20:26:11 +000040 NoDefaultConstructor(int) {}
Marshall Clow82837092014-12-09 15:07:42 +000041};
42
Howard Hinnant1468b662010-11-19 22:17:28 +000043class NotEmpty
44{
45public:
46 virtual ~NotEmpty();
47};
48
49union Union {};
50
51struct bit_zero
52{
53 int : 0;
54};
55
56class Abstract
57{
58public:
59 virtual ~Abstract() = 0;
60};
61
62struct A
63{
64 A();
65};
66
Howard Hinnant6063ec12011-05-13 14:08:16 +000067class B
68{
69 B();
70};
71
Howard Hinnant1468b662010-11-19 22:17:28 +000072int main()
73{
Marshall Clow933afa92013-07-04 00:10:01 +000074 test_is_default_constructible<A>();
75 test_is_default_constructible<Union>();
76 test_is_default_constructible<Empty>();
77 test_is_default_constructible<int>();
78 test_is_default_constructible<double>();
79 test_is_default_constructible<int*>();
80 test_is_default_constructible<const int*>();
81 test_is_default_constructible<char[3]>();
82 test_is_default_constructible<NotEmpty>();
83 test_is_default_constructible<bit_zero>();
Howard Hinnant1468b662010-11-19 22:17:28 +000084
Marshall Clow933afa92013-07-04 00:10:01 +000085 test_is_not_default_constructible<void>();
86 test_is_not_default_constructible<int&>();
87 test_is_not_default_constructible<char[]>();
88 test_is_not_default_constructible<Abstract>();
Marshall Clow82837092014-12-09 15:07:42 +000089 test_is_not_default_constructible<NoDefaultConstructor>();
Marshall Clow933afa92013-07-04 00:10:01 +000090#if __has_feature(cxx_access_control_sfinae)
91 test_is_not_default_constructible<B>();
92#endif
Howard Hinnant1468b662010-11-19 22:17:28 +000093}