]>
Commit | Line | Data |
---|---|---|
83ffe9cd | 1 | // Copyright (C) 2018-2023 Free Software Foundation, Inc. |
8df27fcb JW |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | // | |
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | // | |
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
18 | // { dg-options "-std=gnu++2a" } | |
19 | // { dg-do compile { target c++2a } } | |
20 | ||
21 | #include <type_traits> | |
22 | #include <testsuite_tr1.h> | |
23 | ||
ce9f305e | 24 | using std::is_nothrow_convertible; |
ce9f305e | 25 | |
8df27fcb JW |
26 | void test01() |
27 | { | |
8df27fcb JW |
28 | using namespace __gnu_test; |
29 | ||
30 | // Positive conversion tests. | |
31 | static_assert(test_relationship<is_nothrow_convertible, | |
32 | int, int>(true)); | |
33 | static_assert(test_relationship<is_nothrow_convertible, | |
34 | int, const int>(true)); | |
35 | static_assert(test_relationship<is_nothrow_convertible, | |
36 | volatile int, const int>(true)); | |
37 | static_assert(test_relationship<is_nothrow_convertible, | |
38 | int, float>(true)); | |
39 | static_assert(test_relationship<is_nothrow_convertible, | |
40 | double, float>(true)); | |
41 | static_assert(test_relationship<is_nothrow_convertible, | |
42 | float, int>(true)); | |
43 | static_assert(test_relationship<is_nothrow_convertible, | |
44 | int*, const int*>(true)); | |
45 | static_assert(test_relationship<is_nothrow_convertible, | |
46 | int*, void*>(true)); | |
47 | static_assert(test_relationship<is_nothrow_convertible, | |
48 | int[4], int*>(true)); | |
49 | static_assert(test_relationship<is_nothrow_convertible, | |
50 | float&, int>(true)); | |
51 | static_assert(test_relationship<is_nothrow_convertible, | |
52 | int, const int&>(true)); | |
53 | static_assert(test_relationship<is_nothrow_convertible, | |
54 | const int&, int>(true)); | |
55 | static_assert(test_relationship<is_nothrow_convertible, | |
56 | float, const int&>(true)); | |
57 | static_assert(test_relationship<is_nothrow_convertible, | |
58 | int(int), int(*)(int)>(true)); | |
59 | static_assert(test_relationship<is_nothrow_convertible, | |
60 | int(&)(int), int(*)(int)>(true)); | |
61 | static_assert(test_relationship<is_nothrow_convertible, | |
62 | EnumType, int>(true)); | |
63 | static_assert(test_relationship<is_nothrow_convertible, | |
64 | ClassType, ClassType>(true)); | |
65 | static_assert(test_relationship<is_nothrow_convertible, | |
66 | DerivedType, ClassType>(true)); | |
67 | static_assert(test_relationship<is_nothrow_convertible, | |
68 | DerivedType*, ClassType*>(true)); | |
69 | static_assert(test_relationship<is_nothrow_convertible, | |
70 | DerivedType&, ClassType&>(true)); | |
71 | ||
72 | static_assert(test_relationship<is_nothrow_convertible, | |
73 | const int, const int&>(true)); | |
74 | ||
75 | static_assert(test_relationship<is_nothrow_convertible, | |
76 | void, void>(true)); | |
77 | static_assert(test_relationship<is_nothrow_convertible, | |
78 | const void, void>(true)); | |
79 | static_assert(test_relationship<is_nothrow_convertible, | |
80 | void, volatile void>(true)); | |
81 | static_assert(test_relationship<is_nothrow_convertible, | |
82 | double&, NoexceptExplicitClass>(true)); | |
83 | static_assert(test_relationship<is_nothrow_convertible, | |
84 | NoexceptCopyConsClass, | |
85 | NoexceptCopyConsClass>(true)); | |
86 | static_assert(test_relationship<is_nothrow_convertible, | |
87 | const NoexceptCopyConsClass, | |
88 | NoexceptCopyConsClass>(true)); | |
89 | static_assert(test_relationship<is_nothrow_convertible, | |
90 | const NoexceptCopyConsClass&, | |
91 | NoexceptCopyConsClass>(true)); | |
92 | static_assert(test_relationship<is_nothrow_convertible, | |
93 | NoexceptMoveConsClass, | |
94 | NoexceptMoveConsClass>(true)); | |
95 | ||
96 | static_assert(test_relationship<is_nothrow_convertible, | |
97 | int(int), int(&)(int)>(true)); | |
98 | ||
99 | // Negative conversion tests. | |
100 | static_assert(test_relationship<is_nothrow_convertible, | |
101 | const int*, int*>(false)); | |
102 | static_assert(test_relationship<is_nothrow_convertible, | |
103 | int*, float*>(false)); | |
104 | static_assert(test_relationship<is_nothrow_convertible, | |
105 | const int[4], int*>(false)); | |
106 | static_assert(test_relationship<is_nothrow_convertible, | |
107 | int[4], int[4]>(false)); | |
108 | static_assert(test_relationship<is_nothrow_convertible, | |
109 | const int&, int&>(false)); | |
110 | static_assert(test_relationship<is_nothrow_convertible, | |
111 | float&, int&>(false)); | |
112 | static_assert(test_relationship<is_nothrow_convertible, | |
113 | float, volatile int&>(false)); | |
114 | static_assert(test_relationship<is_nothrow_convertible, | |
115 | int(int), int(int)>(false)); | |
116 | static_assert(test_relationship<is_nothrow_convertible, | |
117 | int(int), int(*)(void)>(false)); | |
118 | static_assert(test_relationship<is_nothrow_convertible, | |
119 | int(*)(int), int(&)(int)>(false)); | |
120 | static_assert(test_relationship<is_nothrow_convertible, | |
121 | int, EnumType>(false)); | |
122 | static_assert(test_relationship<is_nothrow_convertible, | |
123 | int, ClassType>(false)); | |
124 | static_assert(test_relationship<is_nothrow_convertible, | |
125 | ClassType, DerivedType>(false)); | |
126 | static_assert(test_relationship<is_nothrow_convertible, | |
127 | ClassType*, DerivedType*>(false)); | |
128 | static_assert(test_relationship<is_nothrow_convertible, | |
129 | ClassType&, DerivedType&>(false)); | |
130 | ||
131 | static_assert(test_relationship<is_nothrow_convertible, | |
132 | void, int>(false)); | |
133 | static_assert(test_relationship<is_nothrow_convertible, | |
134 | void, float>(false)); | |
135 | static_assert(test_relationship<is_nothrow_convertible, | |
136 | void, int(*)(int)>(false)); | |
137 | ||
138 | // C++0x | |
139 | static_assert(test_relationship<is_nothrow_convertible, | |
140 | int, void>(false)); | |
141 | static_assert(test_relationship<is_nothrow_convertible, | |
142 | int[4], void>(false)); | |
143 | ||
144 | static_assert(test_relationship<is_nothrow_convertible, | |
145 | int, int&>(false)); | |
146 | static_assert(test_relationship<is_nothrow_convertible, | |
147 | float, volatile float&>(false)); | |
148 | static_assert(test_relationship<is_nothrow_convertible, | |
149 | const volatile int, | |
150 | const volatile int&>(false)); | |
151 | static_assert(test_relationship<is_nothrow_convertible, | |
152 | volatile int, volatile int&>(false)); | |
153 | static_assert(test_relationship<is_nothrow_convertible, | |
154 | double&, ExplicitClass>(false)); | |
155 | static_assert(test_relationship<is_nothrow_convertible, | |
156 | int&, ExplicitClass>(false)); | |
157 | static_assert(test_relationship<is_nothrow_convertible, | |
158 | void*, ExplicitClass>(false)); | |
159 | ||
160 | static_assert(test_relationship<is_nothrow_convertible, | |
161 | ExceptCopyConsClass, | |
162 | ExceptCopyConsClass>(false)); | |
163 | static_assert(test_relationship<is_nothrow_convertible, | |
164 | const ExceptCopyConsClass, | |
165 | ExceptCopyConsClass>(false)); | |
166 | static_assert(test_relationship<is_nothrow_convertible, | |
167 | const ExceptCopyConsClass&, | |
168 | ExceptCopyConsClass>(false)); | |
169 | static_assert(test_relationship<is_nothrow_convertible, | |
170 | ExceptMoveConsClass, | |
171 | ExceptMoveConsClass>(false)); | |
172 | static_assert(test_relationship<is_nothrow_convertible, | |
173 | ExceptMoveConsClass&, | |
174 | ExceptMoveConsClass>(false)); | |
175 | static_assert(test_relationship<is_nothrow_convertible, | |
176 | NoexceptMoveConsClass&, | |
177 | NoexceptMoveConsClass>(false)); | |
178 | } | |
ce9f305e JW |
179 | |
180 | void test02() | |
181 | { | |
182 | struct X { }; | |
183 | ||
184 | struct Y | |
185 | { | |
186 | explicit Y(X) noexcept; // not viable for implicit conversions | |
187 | Y(...); | |
188 | }; | |
189 | ||
190 | static_assert(!is_nothrow_convertible<X, Y>::value, ""); | |
191 | } |