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 //===----------------------------------------------------------------------===//
8 
9 // type_traits
10 
11 // template <class T, class... Args>
12 //   struct is_nothrow_constructible;
13 
14 #include <type_traits>
15 #include "test_macros.h"
16 
17 template <class T>
test_is_nothrow_constructible()18 void test_is_nothrow_constructible()
19 {
20     static_assert(( std::is_nothrow_constructible<T>::value), "");
21 #if TEST_STD_VER > 14
22     static_assert(( std::is_nothrow_constructible_v<T>), "");
23 #endif
24 }
25 
26 template <class T, class A0>
test_is_nothrow_constructible()27 void test_is_nothrow_constructible()
28 {
29     static_assert(( std::is_nothrow_constructible<T, A0>::value), "");
30 #if TEST_STD_VER > 14
31     static_assert(( std::is_nothrow_constructible_v<T, A0>), "");
32 #endif
33 }
34 
35 template <class T>
test_is_not_nothrow_constructible()36 void test_is_not_nothrow_constructible()
37 {
38     static_assert((!std::is_nothrow_constructible<T>::value), "");
39 #if TEST_STD_VER > 14
40     static_assert((!std::is_nothrow_constructible_v<T>), "");
41 #endif
42 }
43 
44 template <class T, class A0>
test_is_not_nothrow_constructible()45 void test_is_not_nothrow_constructible()
46 {
47     static_assert((!std::is_nothrow_constructible<T, A0>::value), "");
48 #if TEST_STD_VER > 14
49     static_assert((!std::is_nothrow_constructible_v<T, A0>), "");
50 #endif
51 }
52 
53 template <class T, class A0, class A1>
test_is_not_nothrow_constructible()54 void test_is_not_nothrow_constructible()
55 {
56     static_assert((!std::is_nothrow_constructible<T, A0, A1>::value), "");
57 #if TEST_STD_VER > 14
58     static_assert((!std::is_nothrow_constructible_v<T, A0, A1>), "");
59 #endif
60 }
61 
62 class Empty
63 {
64 };
65 
66 class NotEmpty
67 {
68     virtual ~NotEmpty();
69 };
70 
71 union Union {};
72 
73 struct bit_zero
74 {
75     int :  0;
76 };
77 
78 class Abstract
79 {
80     virtual ~Abstract() = 0;
81 };
82 
83 struct A
84 {
85     A(const A&);
86 };
87 
88 struct C
89 {
90     C(C&);  // not const
91     void operator=(C&);  // not const
92 };
93 
94 #if TEST_STD_VER >= 11
95 struct Tuple {
TupleTuple96     Tuple(Empty&&) noexcept {}
97 };
98 #endif
99 
main(int,char **)100 int main(int, char**)
101 {
102     test_is_nothrow_constructible<int> ();
103     test_is_nothrow_constructible<int, const int&> ();
104     test_is_nothrow_constructible<Empty> ();
105     test_is_nothrow_constructible<Empty, const Empty&> ();
106 
107     test_is_not_nothrow_constructible<A, int> ();
108     test_is_not_nothrow_constructible<A, int, double> ();
109     test_is_not_nothrow_constructible<A> ();
110     test_is_not_nothrow_constructible<C> ();
111 #if TEST_STD_VER >= 11
112     test_is_nothrow_constructible<Tuple &&, Empty> (); // See bug #19616.
113 
114     static_assert(!std::is_constructible<Tuple&, Empty>::value, "");
115     test_is_not_nothrow_constructible<Tuple &, Empty> (); // See bug #19616.
116 #endif
117 
118   return 0;
119 }
120