]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/is_nothrow_convertible/value.cc
1 // Copyright (C) 2018-2019 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do compile { target c++2a } }
21 #include <type_traits>
22 #include <testsuite_tr1.h>
26 using std::is_nothrow_convertible
;
27 using namespace __gnu_test
;
29 // Positive conversion tests.
30 static_assert(test_relationship
<is_nothrow_convertible
,
32 static_assert(test_relationship
<is_nothrow_convertible
,
33 int, const int>(true));
34 static_assert(test_relationship
<is_nothrow_convertible
,
35 volatile int, const int>(true));
36 static_assert(test_relationship
<is_nothrow_convertible
,
38 static_assert(test_relationship
<is_nothrow_convertible
,
39 double, float>(true));
40 static_assert(test_relationship
<is_nothrow_convertible
,
42 static_assert(test_relationship
<is_nothrow_convertible
,
43 int*, const int*>(true));
44 static_assert(test_relationship
<is_nothrow_convertible
,
46 static_assert(test_relationship
<is_nothrow_convertible
,
48 static_assert(test_relationship
<is_nothrow_convertible
,
50 static_assert(test_relationship
<is_nothrow_convertible
,
51 int, const int&>(true));
52 static_assert(test_relationship
<is_nothrow_convertible
,
53 const int&, int>(true));
54 static_assert(test_relationship
<is_nothrow_convertible
,
55 float, const int&>(true));
56 static_assert(test_relationship
<is_nothrow_convertible
,
57 int(int), int(*)(int)>(true));
58 static_assert(test_relationship
<is_nothrow_convertible
,
59 int(&)(int), int(*)(int)>(true));
60 static_assert(test_relationship
<is_nothrow_convertible
,
61 EnumType
, int>(true));
62 static_assert(test_relationship
<is_nothrow_convertible
,
63 ClassType
, ClassType
>(true));
64 static_assert(test_relationship
<is_nothrow_convertible
,
65 DerivedType
, ClassType
>(true));
66 static_assert(test_relationship
<is_nothrow_convertible
,
67 DerivedType
*, ClassType
*>(true));
68 static_assert(test_relationship
<is_nothrow_convertible
,
69 DerivedType
&, ClassType
&>(true));
71 static_assert(test_relationship
<is_nothrow_convertible
,
72 const int, const int&>(true));
74 static_assert(test_relationship
<is_nothrow_convertible
,
76 static_assert(test_relationship
<is_nothrow_convertible
,
77 const void, void>(true));
78 static_assert(test_relationship
<is_nothrow_convertible
,
79 void, volatile void>(true));
80 static_assert(test_relationship
<is_nothrow_convertible
,
81 double&, NoexceptExplicitClass
>(true));
82 static_assert(test_relationship
<is_nothrow_convertible
,
83 NoexceptCopyConsClass
,
84 NoexceptCopyConsClass
>(true));
85 static_assert(test_relationship
<is_nothrow_convertible
,
86 const NoexceptCopyConsClass
,
87 NoexceptCopyConsClass
>(true));
88 static_assert(test_relationship
<is_nothrow_convertible
,
89 const NoexceptCopyConsClass
&,
90 NoexceptCopyConsClass
>(true));
91 static_assert(test_relationship
<is_nothrow_convertible
,
92 NoexceptMoveConsClass
,
93 NoexceptMoveConsClass
>(true));
95 static_assert(test_relationship
<is_nothrow_convertible
,
96 int(int), int(&)(int)>(true));
98 // Negative conversion tests.
99 static_assert(test_relationship
<is_nothrow_convertible
,
100 const int*, int*>(false));
101 static_assert(test_relationship
<is_nothrow_convertible
,
102 int*, float*>(false));
103 static_assert(test_relationship
<is_nothrow_convertible
,
104 const int[4], int*>(false));
105 static_assert(test_relationship
<is_nothrow_convertible
,
106 int[4], int[4]>(false));
107 static_assert(test_relationship
<is_nothrow_convertible
,
108 const int&, int&>(false));
109 static_assert(test_relationship
<is_nothrow_convertible
,
110 float&, int&>(false));
111 static_assert(test_relationship
<is_nothrow_convertible
,
112 float, volatile int&>(false));
113 static_assert(test_relationship
<is_nothrow_convertible
,
114 int(int), int(int)>(false));
115 static_assert(test_relationship
<is_nothrow_convertible
,
116 int(int), int(*)(void)>(false));
117 static_assert(test_relationship
<is_nothrow_convertible
,
118 int(*)(int), int(&)(int)>(false));
119 static_assert(test_relationship
<is_nothrow_convertible
,
120 int, EnumType
>(false));
121 static_assert(test_relationship
<is_nothrow_convertible
,
122 int, ClassType
>(false));
123 static_assert(test_relationship
<is_nothrow_convertible
,
124 ClassType
, DerivedType
>(false));
125 static_assert(test_relationship
<is_nothrow_convertible
,
126 ClassType
*, DerivedType
*>(false));
127 static_assert(test_relationship
<is_nothrow_convertible
,
128 ClassType
&, DerivedType
&>(false));
130 static_assert(test_relationship
<is_nothrow_convertible
,
132 static_assert(test_relationship
<is_nothrow_convertible
,
133 void, float>(false));
134 static_assert(test_relationship
<is_nothrow_convertible
,
135 void, int(*)(int)>(false));
138 static_assert(test_relationship
<is_nothrow_convertible
,
140 static_assert(test_relationship
<is_nothrow_convertible
,
141 int[4], void>(false));
143 static_assert(test_relationship
<is_nothrow_convertible
,
145 static_assert(test_relationship
<is_nothrow_convertible
,
146 float, volatile float&>(false));
147 static_assert(test_relationship
<is_nothrow_convertible
,
149 const volatile int&>(false));
150 static_assert(test_relationship
<is_nothrow_convertible
,
151 volatile int, volatile int&>(false));
152 static_assert(test_relationship
<is_nothrow_convertible
,
153 double&, ExplicitClass
>(false));
154 static_assert(test_relationship
<is_nothrow_convertible
,
155 int&, ExplicitClass
>(false));
156 static_assert(test_relationship
<is_nothrow_convertible
,
157 void*, ExplicitClass
>(false));
159 static_assert(test_relationship
<is_nothrow_convertible
,
161 ExceptCopyConsClass
>(false));
162 static_assert(test_relationship
<is_nothrow_convertible
,
163 const ExceptCopyConsClass
,
164 ExceptCopyConsClass
>(false));
165 static_assert(test_relationship
<is_nothrow_convertible
,
166 const ExceptCopyConsClass
&,
167 ExceptCopyConsClass
>(false));
168 static_assert(test_relationship
<is_nothrow_convertible
,
170 ExceptMoveConsClass
>(false));
171 static_assert(test_relationship
<is_nothrow_convertible
,
172 ExceptMoveConsClass
&,
173 ExceptMoveConsClass
>(false));
174 static_assert(test_relationship
<is_nothrow_convertible
,
175 NoexceptMoveConsClass
&,
176 NoexceptMoveConsClass
>(false));