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 // is_nothrow_default_constructible
12 
13 #include <type_traits>
14 #include "test_macros.h"
15 
16 template <class T>
test_is_nothrow_default_constructible()17 void test_is_nothrow_default_constructible()
18 {
19     static_assert( std::is_nothrow_default_constructible<T>::value, "");
20     static_assert( std::is_nothrow_default_constructible<const T>::value, "");
21     static_assert( std::is_nothrow_default_constructible<volatile T>::value, "");
22     static_assert( std::is_nothrow_default_constructible<const volatile T>::value, "");
23 #if TEST_STD_VER > 14
24     static_assert( std::is_nothrow_default_constructible_v<T>, "");
25     static_assert( std::is_nothrow_default_constructible_v<const T>, "");
26     static_assert( std::is_nothrow_default_constructible_v<volatile T>, "");
27     static_assert( std::is_nothrow_default_constructible_v<const volatile T>, "");
28 #endif
29 }
30 
31 template <class T>
test_has_not_nothrow_default_constructor()32 void test_has_not_nothrow_default_constructor()
33 {
34     static_assert(!std::is_nothrow_default_constructible<T>::value, "");
35     static_assert(!std::is_nothrow_default_constructible<const T>::value, "");
36     static_assert(!std::is_nothrow_default_constructible<volatile T>::value, "");
37     static_assert(!std::is_nothrow_default_constructible<const volatile T>::value, "");
38 #if TEST_STD_VER > 14
39     static_assert(!std::is_nothrow_default_constructible_v<T>, "");
40     static_assert(!std::is_nothrow_default_constructible_v<const T>, "");
41     static_assert(!std::is_nothrow_default_constructible_v<volatile T>, "");
42     static_assert(!std::is_nothrow_default_constructible_v<const volatile T>, "");
43 #endif
44 }
45 
46 class Empty
47 {
48 };
49 
50 union Union {};
51 
52 struct bit_zero
53 {
54     int :  0;
55 };
56 
57 struct A
58 {
59     A();
60 };
61 
62 #if TEST_STD_VER >= 11
63 struct DThrows
64 {
DThrowsDThrows65     DThrows()  noexcept(true) {}
~DThrowsDThrows66     ~DThrows() noexcept(false) {}
67 };
68 #endif
69 
main(int,char **)70 int main(int, char**)
71 {
72     test_has_not_nothrow_default_constructor<void>();
73     test_has_not_nothrow_default_constructor<int&>();
74     test_has_not_nothrow_default_constructor<A>();
75 #if TEST_STD_VER >= 11
76     test_has_not_nothrow_default_constructor<DThrows>(); // This is LWG2116
77 #endif
78 
79     test_is_nothrow_default_constructible<Union>();
80     test_is_nothrow_default_constructible<Empty>();
81     test_is_nothrow_default_constructible<int>();
82     test_is_nothrow_default_constructible<double>();
83     test_is_nothrow_default_constructible<int*>();
84     test_is_nothrow_default_constructible<const int*>();
85     test_is_nothrow_default_constructible<char[3]>();
86     test_is_nothrow_default_constructible<bit_zero>();
87 
88   return 0;
89 }
90