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 | #include "common.h" |
17 | |
18 | template <class T> |
19 | void test_is_nothrow_default_constructible() |
20 | { |
21 | static_assert( std::is_nothrow_default_constructible<T>::value, "" ); |
22 | static_assert( std::is_nothrow_default_constructible<const T>::value, "" ); |
23 | static_assert( std::is_nothrow_default_constructible<volatile T>::value, "" ); |
24 | static_assert( std::is_nothrow_default_constructible<const volatile T>::value, "" ); |
25 | #if TEST_STD_VER > 14 |
26 | static_assert( std::is_nothrow_default_constructible_v<T>, "" ); |
27 | static_assert( std::is_nothrow_default_constructible_v<const T>, "" ); |
28 | static_assert( std::is_nothrow_default_constructible_v<volatile T>, "" ); |
29 | static_assert( std::is_nothrow_default_constructible_v<const volatile T>, "" ); |
30 | #endif |
31 | } |
32 | |
33 | template <class T> |
34 | void test_has_not_nothrow_default_constructor() |
35 | { |
36 | static_assert(!std::is_nothrow_default_constructible<T>::value, "" ); |
37 | static_assert(!std::is_nothrow_default_constructible<const T>::value, "" ); |
38 | static_assert(!std::is_nothrow_default_constructible<volatile T>::value, "" ); |
39 | static_assert(!std::is_nothrow_default_constructible<const volatile T>::value, "" ); |
40 | #if TEST_STD_VER > 14 |
41 | static_assert(!std::is_nothrow_default_constructible_v<T>, "" ); |
42 | static_assert(!std::is_nothrow_default_constructible_v<const T>, "" ); |
43 | static_assert(!std::is_nothrow_default_constructible_v<volatile T>, "" ); |
44 | static_assert(!std::is_nothrow_default_constructible_v<const volatile T>, "" ); |
45 | #endif |
46 | } |
47 | |
48 | #if TEST_STD_VER >= 11 |
49 | struct DThrows |
50 | { |
51 | DThrows() noexcept(true) {} |
52 | ~DThrows() noexcept(false) {} |
53 | }; |
54 | #endif |
55 | |
56 | int main(int, char**) |
57 | { |
58 | test_has_not_nothrow_default_constructor<void>(); |
59 | test_has_not_nothrow_default_constructor<int&>(); |
60 | test_has_not_nothrow_default_constructor<A>(); |
61 | #if TEST_STD_VER >= 11 |
62 | test_has_not_nothrow_default_constructor<DThrows>(); // This is LWG2116 |
63 | // TODO: enable the test for GCC once https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106611 is resolved |
64 | #ifndef TEST_COMPILER_GCC |
65 | test_has_not_nothrow_default_constructor<TrivialNotNoexcept>(); |
66 | #endif |
67 | #endif |
68 | |
69 | test_is_nothrow_default_constructible<Union>(); |
70 | test_is_nothrow_default_constructible<Empty>(); |
71 | test_is_nothrow_default_constructible<int>(); |
72 | test_is_nothrow_default_constructible<double>(); |
73 | test_is_nothrow_default_constructible<int*>(); |
74 | test_is_nothrow_default_constructible<const int*>(); |
75 | test_is_nothrow_default_constructible<char[3]>(); |
76 | test_is_nothrow_default_constructible<bit_zero>(); |
77 | |
78 | return 0; |
79 | } |
80 | |