| 1 | //{ dg-do run { target c++11 } } |
| 2 | |
| 3 | // 2019-04-10 Nina Dinka Ranns <[email protected]> |
| 4 | // |
| 5 | // Copyright (C) 2019-2025 Free Software Foundation, Inc. |
| 6 | // |
| 7 | // This file is part of the GNU ISO C++ Library. This library is free |
| 8 | // software; you can redistribute it and/or modify it under the |
| 9 | // terms of the GNU General Public License as published by the |
| 10 | // Free Software Foundation; either version 3, or (at your option) |
| 11 | // any later version. |
| 12 | // |
| 13 | // This library is distributed in the hope that it will be useful, |
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | // GNU General Public License for more details. |
| 17 | // |
| 18 | // You should have received a copy of the GNU General Public License along |
| 19 | // with this library; see the file COPYING3. If not see |
| 20 | // <http://www.gnu.org/licenses/>. |
| 21 | |
| 22 | #include <tuple> |
| 23 | #include <testsuite_tr1.h> |
| 24 | #include <utility> |
| 25 | |
| 26 | using namespace __gnu_test; |
| 27 | |
| 28 | bool throwing_ctor_called = false; |
| 29 | |
| 30 | namespace test_trait{ |
| 31 | template <bool B> |
| 32 | using bool_constant = std::integral_constant<bool, B>; |
| 33 | |
| 34 | template<typename From, typename To, |
| 35 | bool = std::__or_<std::is_void<From>, std::is_function<To>, |
| 36 | std::is_array<To>>::value> |
| 37 | struct is_nt_convertible_helper |
| 38 | : std::is_void<To> |
| 39 | { }; |
| 40 | |
| 41 | template<typename From, typename To> |
| 42 | class is_nt_convertible_helper<From, To, false> |
| 43 | { |
| 44 | template<typename To1> |
| 45 | static void test_aux(To1) noexcept; |
| 46 | |
| 47 | template<typename From1, typename To1> |
| 48 | static bool_constant<noexcept(test_aux<To1>({std::declval<From1>()}))> |
| 49 | test(int); |
| 50 | |
| 51 | template<typename, typename> |
| 52 | static std::false_type |
| 53 | test(...); |
| 54 | |
| 55 | public: |
| 56 | using type = decltype(test<From, To>(0)); |
| 57 | }; |
| 58 | |
| 59 | // Similar to std::is_nothrow_convertible, but only considers whether the |
| 60 | // actual conversion can throw (and not any potential copies of From). |
| 61 | // This means the result is not affected by copy elision of From in C++17. |
| 62 | template<typename From, typename To> |
| 63 | struct is_nothrow_convertible |
| 64 | : public is_nt_convertible_helper<From, To>::type |
| 65 | { }; |
| 66 | } |
| 67 | |
| 68 | template<typename T> |
| 69 | bool checkDefaultThrowConstruct() |
| 70 | { |
| 71 | throwing_ctor_called = false; |
| 72 | bool deduced_nothrow = std::is_nothrow_constructible<T>::value; |
| 73 | T t{}; |
| 74 | return throwing_ctor_called != deduced_nothrow; |
| 75 | } |
| 76 | template<typename T, typename U> |
| 77 | bool checkCopyThrowConstruct() |
| 78 | { |
| 79 | throwing_ctor_called = false; |
| 80 | bool deduced_nothrow = std::is_nothrow_constructible<T, U&>::value; |
| 81 | U u; |
| 82 | T t{u}; |
| 83 | return throwing_ctor_called != deduced_nothrow; |
| 84 | } |
| 85 | template<typename T, typename U> |
| 86 | bool checkMoveThrowConstruct() |
| 87 | { |
| 88 | throwing_ctor_called = false; |
| 89 | bool deduced_nothrow = std::is_nothrow_constructible<T, U&&>::value; |
| 90 | U u; |
| 91 | T t{std::move(u)}; |
| 92 | return throwing_ctor_called != deduced_nothrow; |
| 93 | } |
| 94 | |
| 95 | typedef std::tuple<int> IT; |
| 96 | typedef std::tuple<const int> CIT; |
| 97 | typedef std::tuple<int&&> RVIT; |
| 98 | typedef std::tuple<int, int> IIT; |
| 99 | typedef std::pair<int, int> IIP; |
| 100 | typedef std::tuple<int, int, int> IIIT; |
| 101 | |
| 102 | namespace DefaultConstructionTests |
| 103 | { |
| 104 | struct NoexceptDC |
| 105 | { |
| 106 | NoexceptDC() noexcept(true){} |
| 107 | }; |
| 108 | |
| 109 | struct ExceptDC |
| 110 | { |
| 111 | ExceptDC() noexcept(false) |
| 112 | { throwing_ctor_called = true; } |
| 113 | }; |
| 114 | |
| 115 | struct ExplicitNoexceptDC |
| 116 | { |
| 117 | explicit ExplicitNoexceptDC() noexcept(true) |
| 118 | {} |
| 119 | }; |
| 120 | |
| 121 | struct ExplicitExceptDC |
| 122 | { |
| 123 | explicit ExplicitExceptDC() noexcept(false) |
| 124 | { throwing_ctor_called = true; } |
| 125 | }; |
| 126 | |
| 127 | typedef std::tuple<NoexceptDC> NDT; |
| 128 | typedef std::tuple<ExceptDC> EDT; |
| 129 | typedef std::tuple<ExplicitNoexceptDC> X_NDT; |
| 130 | typedef std::tuple<ExplicitExceptDC> X_EDT; |
| 131 | |
| 132 | typedef std::tuple<NoexceptDC,NoexceptDC> NNDT; |
| 133 | typedef std::tuple<ExceptDC,ExceptDC> EEDT; |
| 134 | typedef std::tuple<ExceptDC,NoexceptDC> ENDT; |
| 135 | typedef std::tuple<ExplicitNoexceptDC,NoexceptDC> X_NNDT; |
| 136 | typedef std::tuple<ExplicitExceptDC,ExceptDC> X_EEDT; |
| 137 | typedef std::tuple<ExceptDC,ExplicitNoexceptDC> X_ENDT; |
| 138 | |
| 139 | typedef std::tuple<long, NoexceptDC, NoexceptDC> LNDNDT; |
| 140 | typedef std::tuple<long, NoexceptDC, ExceptDC> LNDEDT; |
| 141 | typedef std::tuple<long, ExplicitNoexceptDC, NoexceptDC> X_LNEDNDT; |
| 142 | typedef std::tuple<long, ExplicitNoexceptDC, ExceptDC> X_LNEDEDT; |
| 143 | typedef std::tuple<long, ExplicitExceptDC, ExceptDC> X_LEEDEDT; |
| 144 | |
| 145 | |
| 146 | /* if it has E in the name, it contains a type that throws when default constructed */ |
| 147 | static_assert(std::is_nothrow_constructible<IT>::value, ""); |
| 148 | static_assert(std::is_nothrow_constructible<NDT>::value, ""); |
| 149 | static_assert(!std::is_nothrow_constructible<EDT>::value, ""); |
| 150 | static_assert(std::is_nothrow_constructible<X_NDT>::value, ""); |
| 151 | static_assert(!std::is_nothrow_constructible<X_EDT>::value, ""); |
| 152 | |
| 153 | static_assert(std::is_nothrow_constructible<IIT>::value, ""); |
| 154 | static_assert(std::is_nothrow_constructible<NNDT>::value, ""); |
| 155 | static_assert(!std::is_nothrow_constructible<EEDT>::value, ""); |
| 156 | static_assert(!std::is_nothrow_constructible<ENDT>::value, ""); |
| 157 | static_assert(std::is_nothrow_constructible<X_NNDT>::value, ""); |
| 158 | static_assert(!std::is_nothrow_constructible<X_EEDT>::value, ""); |
| 159 | static_assert(!std::is_nothrow_constructible<X_ENDT>::value, ""); |
| 160 | |
| 161 | static_assert(std::is_nothrow_constructible<IIIT>::value, ""); |
| 162 | static_assert(std::is_nothrow_constructible<LNDNDT>::value, ""); |
| 163 | static_assert(!std::is_nothrow_constructible<LNDEDT>::value, ""); |
| 164 | static_assert(std::is_nothrow_constructible<X_LNEDNDT>::value, ""); |
| 165 | static_assert(!std::is_nothrow_constructible<X_LNEDEDT>::value, ""); |
| 166 | static_assert(!std::is_nothrow_constructible<X_LEEDEDT>::value, ""); |
| 167 | |
| 168 | void Run() |
| 169 | { |
| 170 | VERIFY( checkDefaultThrowConstruct<IT>() ); |
| 171 | VERIFY( checkDefaultThrowConstruct<NDT>() ); |
| 172 | VERIFY( checkDefaultThrowConstruct<EDT>() ); |
| 173 | VERIFY( checkDefaultThrowConstruct<X_NDT>() ); |
| 174 | VERIFY( checkDefaultThrowConstruct<X_EDT>() ); |
| 175 | |
| 176 | VERIFY( checkDefaultThrowConstruct<IIT>() ); |
| 177 | VERIFY( checkDefaultThrowConstruct<NNDT>() ); |
| 178 | VERIFY( checkDefaultThrowConstruct<EEDT>() ); |
| 179 | VERIFY( checkDefaultThrowConstruct<ENDT>() ); |
| 180 | VERIFY( checkDefaultThrowConstruct<X_NNDT>() ); |
| 181 | VERIFY( checkDefaultThrowConstruct<X_EEDT>() ); |
| 182 | VERIFY( checkDefaultThrowConstruct<X_ENDT>() ); |
| 183 | |
| 184 | VERIFY( checkDefaultThrowConstruct<IIIT>() ); |
| 185 | VERIFY( checkDefaultThrowConstruct<LNDNDT>() ); |
| 186 | VERIFY( checkDefaultThrowConstruct<LNDEDT>() ); |
| 187 | VERIFY( checkDefaultThrowConstruct<X_LNEDNDT>() ); |
| 188 | VERIFY( checkDefaultThrowConstruct<X_LNEDEDT>() ); |
| 189 | } |
| 190 | } |
| 191 | namespace AllNoThrow |
| 192 | { |
| 193 | static_assert(std::is_nothrow_constructible<IT, int&>::value, ""); |
| 194 | static_assert(std::is_nothrow_constructible<IT, const int&>::value, ""); |
| 195 | static_assert(std::is_nothrow_constructible<IT, int&&>::value, ""); |
| 196 | static_assert(std::is_nothrow_constructible<IT, const int&&>::value, ""); |
| 197 | |
| 198 | static_assert(std::is_nothrow_constructible<IT, IT>::value, ""); |
| 199 | static_assert(std::is_nothrow_constructible<IT, const IT &>::value, ""); |
| 200 | static_assert(std::is_nothrow_constructible<IT, CIT>::value, ""); |
| 201 | |
| 202 | static_assert(test_trait::is_nothrow_convertible<int&, IT>::value, ""); |
| 203 | static_assert(test_trait::is_nothrow_convertible<const int&, IT>::value, ""); |
| 204 | static_assert(test_trait::is_nothrow_convertible<int&&, IT>::value, ""); |
| 205 | static_assert(test_trait::is_nothrow_convertible<const int&&, IT>::value, ""); |
| 206 | |
| 207 | static_assert(std::is_nothrow_constructible<IIT, int&, int&>::value, ""); |
| 208 | static_assert(std::is_nothrow_constructible<IIT, const int&, const int&>::value, ""); |
| 209 | static_assert(std::is_nothrow_constructible<IIT, int&&, int&&>::value, ""); |
| 210 | static_assert(std::is_nothrow_constructible<IIT, const int&&, const int&&>::value, ""); |
| 211 | |
| 212 | static_assert(std::is_nothrow_constructible<IIT, IIT>::value, ""); |
| 213 | static_assert(std::is_nothrow_constructible<IIT, const IIT &>::value, ""); |
| 214 | static_assert(std::is_nothrow_constructible<IIT, IIP>::value, ""); |
| 215 | static_assert(std::is_nothrow_constructible<IIT, const IIP>::value, ""); |
| 216 | |
| 217 | static_assert(test_trait::is_nothrow_convertible<IIT, IIT>::value, ""); |
| 218 | static_assert(test_trait::is_nothrow_convertible<const IIT &, IIT>::value, ""); |
| 219 | static_assert(test_trait::is_nothrow_convertible<IIP, IIT>::value, ""); |
| 220 | static_assert(test_trait::is_nothrow_convertible<const IIP, IIT>::value, ""); |
| 221 | |
| 222 | static_assert(std::is_nothrow_constructible<IIIT, IIIT&>::value, ""); |
| 223 | static_assert(std::is_nothrow_constructible<IIIT, const IIIT &>::value, ""); |
| 224 | static_assert(std::is_nothrow_constructible<IIIT, IIIT&&>::value, ""); |
| 225 | static_assert(std::is_nothrow_constructible<IIIT, const IIIT&&>::value, ""); |
| 226 | |
| 227 | static_assert(test_trait::is_nothrow_convertible<IIIT&, IIIT>::value, ""); |
| 228 | static_assert(test_trait::is_nothrow_convertible<const IIIT &, IIIT>::value, ""); |
| 229 | static_assert(test_trait::is_nothrow_convertible<IIIT&&, IIIT>::value, ""); |
| 230 | static_assert(test_trait::is_nothrow_convertible<const IIIT&&, IIIT>::value, ""); |
| 231 | |
| 232 | static_assert(std::is_nothrow_constructible<IIIT, int&, int&, int&>::value, ""); |
| 233 | static_assert(std::is_nothrow_constructible<IIIT, const int&, const int&, int&>::value, ""); |
| 234 | static_assert(std::is_nothrow_constructible<IIIT, int&&, int&&, int&>::value, ""); |
| 235 | static_assert(std::is_nothrow_constructible<IIIT, const int&&, const int&&, int&>::value, ""); |
| 236 | } |
| 237 | namespace ThrowCopyNothrowConversion |
| 238 | { |
| 239 | struct A |
| 240 | { |
| 241 | A() noexcept(true) |
| 242 | {} |
| 243 | |
| 244 | A(const int&) noexcept(true) |
| 245 | {} |
| 246 | |
| 247 | A(const A&) noexcept(false) |
| 248 | { throwing_ctor_called = true; } |
| 249 | |
| 250 | }; |
| 251 | |
| 252 | typedef std::tuple<A> AT; |
| 253 | typedef std::tuple<A,A> AAT; |
| 254 | typedef std::pair<A,A> AAP; |
| 255 | typedef std::tuple<int,A> IAT; |
| 256 | typedef std::pair<int,A> IAP; |
| 257 | typedef std::tuple<A,A,A> AAAT; |
| 258 | typedef std::tuple<int,int,A> IIAT; |
| 259 | |
| 260 | /* one element tests */ |
| 261 | static_assert(std::is_nothrow_constructible<AT,int>::value,""); |
| 262 | static_assert(std::is_nothrow_constructible<AT,const int>::value,""); |
| 263 | static_assert(std::is_nothrow_constructible<AT,int&>::value,""); |
| 264 | static_assert(std::is_nothrow_constructible<AT,const int &>::value,""); |
| 265 | |
| 266 | static_assert(std::is_nothrow_constructible<AT,IT>::value,""); |
| 267 | static_assert(std::is_nothrow_constructible<AT,const IT>::value,""); |
| 268 | static_assert(std::is_nothrow_constructible<AT,IT&>::value,""); |
| 269 | static_assert(std::is_nothrow_constructible<AT,const IT &>::value,""); |
| 270 | static_assert(std::is_nothrow_constructible<AT,std::tuple<int&>>::value,""); |
| 271 | static_assert(std::is_nothrow_constructible<AT,const std::tuple<int&&>>::value,""); |
| 272 | |
| 273 | static_assert(test_trait::is_nothrow_convertible<int,AT>::value,""); |
| 274 | static_assert(test_trait::is_nothrow_convertible<const int,AT>::value,""); |
| 275 | static_assert(test_trait::is_nothrow_convertible<int&,AT>::value,""); |
| 276 | static_assert(test_trait::is_nothrow_convertible<const int &,AT>::value,""); |
| 277 | |
| 278 | static_assert(test_trait::is_nothrow_convertible<IT,AT>::value,""); |
| 279 | static_assert(test_trait::is_nothrow_convertible<const IT,AT>::value,""); |
| 280 | static_assert(test_trait::is_nothrow_convertible<IT&,AT>::value,""); |
| 281 | static_assert(test_trait::is_nothrow_convertible<const IT &,AT>::value,""); |
| 282 | static_assert(test_trait::is_nothrow_convertible<std::tuple<int&>,AT>::value,""); |
| 283 | static_assert(test_trait::is_nothrow_convertible<const std::tuple<int&&>,AT>::value,""); |
| 284 | |
| 285 | static_assert(!std::is_nothrow_constructible<AT,A>::value,""); |
| 286 | static_assert(!std::is_nothrow_constructible<AT,const A>::value,""); |
| 287 | static_assert(!std::is_nothrow_constructible<AT,A&>::value,""); |
| 288 | static_assert(!std::is_nothrow_constructible<AT,const A &>::value,""); |
| 289 | |
| 290 | static_assert(!std::is_nothrow_constructible<AT,AT>::value,""); |
| 291 | static_assert(!std::is_nothrow_constructible<AT,const AT>::value,""); |
| 292 | static_assert(!std::is_nothrow_constructible<AT,AT&>::value,""); |
| 293 | static_assert(!std::is_nothrow_constructible<AT,const AT &>::value,""); |
| 294 | static_assert(!std::is_nothrow_constructible<AT,std::tuple<A&>>::value,""); |
| 295 | static_assert(!std::is_nothrow_constructible<AT,const std::tuple<A&&>>::value,""); |
| 296 | |
| 297 | static_assert(!test_trait::is_nothrow_convertible<A,AT>::value,""); |
| 298 | static_assert(!test_trait::is_nothrow_convertible<const A,AT>::value,""); |
| 299 | static_assert(!test_trait::is_nothrow_convertible<A&,AT>::value,""); |
| 300 | static_assert(!test_trait::is_nothrow_convertible<const A &,AT>::value,""); |
| 301 | |
| 302 | static_assert(!test_trait::is_nothrow_convertible<AT,AT>::value,""); |
| 303 | static_assert(!test_trait::is_nothrow_convertible<const AT,AT>::value,""); |
| 304 | static_assert(!test_trait::is_nothrow_convertible<AT&,AT>::value,""); |
| 305 | static_assert(!test_trait::is_nothrow_convertible<const AT &,AT>::value,""); |
| 306 | static_assert(!test_trait::is_nothrow_convertible<std::tuple<A&>,AT>::value,""); |
| 307 | static_assert(!test_trait::is_nothrow_convertible<const std::tuple<A&&>,AT>::value,""); |
| 308 | |
| 309 | /* two element tests */ |
| 310 | |
| 311 | static_assert(std::is_nothrow_constructible<AAT,IIT>::value,""); |
| 312 | static_assert(std::is_nothrow_constructible<AAT,const IIT>::value,""); |
| 313 | static_assert(std::is_nothrow_constructible<AAT,IIT&>::value,""); |
| 314 | static_assert(std::is_nothrow_constructible<AAT,const IIT &>::value,""); |
| 315 | static_assert(std::is_nothrow_constructible<AAT,IIP>::value,""); |
| 316 | static_assert(std::is_nothrow_constructible<AAT,const IIP>::value,""); |
| 317 | static_assert(std::is_nothrow_constructible<AAT,IIP&>::value,""); |
| 318 | static_assert(std::is_nothrow_constructible<AAT,const IIP &>::value,""); |
| 319 | static_assert(std::is_nothrow_constructible<AAT,std::tuple<int&,int&>>::value,""); |
| 320 | |
| 321 | static_assert(test_trait::is_nothrow_convertible<IIT,AAT>::value,""); |
| 322 | static_assert(test_trait::is_nothrow_convertible<const IIT,AAT>::value,""); |
| 323 | static_assert(test_trait::is_nothrow_convertible<IIT&,AAT>::value,""); |
| 324 | static_assert(test_trait::is_nothrow_convertible<const IIT &,AAT>::value,""); |
| 325 | static_assert(test_trait::is_nothrow_convertible<IIP,AAT>::value,""); |
| 326 | static_assert(test_trait::is_nothrow_convertible<const IIP,AAT>::value,""); |
| 327 | static_assert(test_trait::is_nothrow_convertible<IIP&,AAT>::value,""); |
| 328 | static_assert(test_trait::is_nothrow_convertible<const IIP &,AAT>::value,""); |
| 329 | static_assert(test_trait::is_nothrow_convertible<std::tuple<int&,int&>,AAT>::value,""); |
| 330 | |
| 331 | |
| 332 | static_assert(!std::is_nothrow_constructible<AAT,AAT>::value,""); |
| 333 | static_assert(!std::is_nothrow_constructible<AAT,const AAT>::value,""); |
| 334 | static_assert(!std::is_nothrow_constructible<AAT,AAT&>::value,""); |
| 335 | static_assert(!std::is_nothrow_constructible<AAT,const AAT &>::value,""); |
| 336 | static_assert(!std::is_nothrow_constructible<AAT,AAP>::value,""); |
| 337 | static_assert(!std::is_nothrow_constructible<AAT,const AAP>::value,""); |
| 338 | static_assert(!std::is_nothrow_constructible<AAT,AAP&>::value,""); |
| 339 | static_assert(!std::is_nothrow_constructible<AAT,const AAP &>::value,""); |
| 340 | static_assert(!std::is_nothrow_constructible<AAT,std::tuple<A&,A&>>::value,""); |
| 341 | |
| 342 | static_assert(!std::is_nothrow_constructible<AAT,IAT>::value,""); |
| 343 | static_assert(!std::is_nothrow_constructible<AAT,const IAT>::value,""); |
| 344 | static_assert(!std::is_nothrow_constructible<AAT,IAT&>::value,""); |
| 345 | static_assert(!std::is_nothrow_constructible<AAT,const IAT &>::value,""); |
| 346 | static_assert(!std::is_nothrow_constructible<AAT,IAP>::value,""); |
| 347 | static_assert(!std::is_nothrow_constructible<AAT,const IAP>::value,""); |
| 348 | static_assert(!std::is_nothrow_constructible<AAT,IAP&>::value,""); |
| 349 | static_assert(!std::is_nothrow_constructible<AAT,const IAP &>::value,""); |
| 350 | static_assert(!std::is_nothrow_constructible<AAT,std::tuple<A&,int&>>::value,""); |
| 351 | |
| 352 | static_assert(!test_trait::is_nothrow_convertible<AAT,AAT>::value,""); |
| 353 | static_assert(!test_trait::is_nothrow_convertible<const AAT,AAT>::value,""); |
| 354 | static_assert(!test_trait::is_nothrow_convertible<AAT&,AAT>::value,""); |
| 355 | static_assert(!test_trait::is_nothrow_convertible<const AAT &,AAT>::value,""); |
| 356 | static_assert(!test_trait::is_nothrow_convertible<AAP,AAT>::value,""); |
| 357 | static_assert(!test_trait::is_nothrow_convertible<const AAP,AAT>::value,""); |
| 358 | static_assert(!test_trait::is_nothrow_convertible<AAP&,AAT>::value,""); |
| 359 | static_assert(!test_trait::is_nothrow_convertible<const AAP &,AAT>::value,""); |
| 360 | static_assert(!test_trait::is_nothrow_convertible<std::tuple<A&,A&>,AAT>::value,""); |
| 361 | |
| 362 | static_assert(!test_trait::is_nothrow_convertible<IAT,AAT>::value,""); |
| 363 | static_assert(!test_trait::is_nothrow_convertible<const IAT,AAT>::value,""); |
| 364 | static_assert(!test_trait::is_nothrow_convertible<IAT&,AAT>::value,""); |
| 365 | static_assert(!test_trait::is_nothrow_convertible<const IAT &,AAT>::value,""); |
| 366 | static_assert(!test_trait::is_nothrow_convertible<IAP,AAT>::value,""); |
| 367 | static_assert(!test_trait::is_nothrow_convertible<const IAP,AAT>::value,""); |
| 368 | static_assert(!test_trait::is_nothrow_convertible<IAP&,AAT>::value,""); |
| 369 | static_assert(!test_trait::is_nothrow_convertible<const IAP &,AAT>::value,""); |
| 370 | static_assert(!test_trait::is_nothrow_convertible<std::tuple<A&,int&>,AAT>::value,""); |
| 371 | |
| 372 | |
| 373 | static_assert(std::is_nothrow_constructible<AAT,int&,const int&>::value,""); |
| 374 | static_assert(std::is_nothrow_constructible<AAT,int&&,const int&&>::value,""); |
| 375 | |
| 376 | static_assert(!std::is_nothrow_constructible<AAT,A&,const A&>::value,""); |
| 377 | static_assert(!std::is_nothrow_constructible<AAT,A&&,const A&&>::value,""); |
| 378 | static_assert(!std::is_nothrow_constructible<AAT,const A &&,const int&&>::value,""); |
| 379 | |
| 380 | /* three element tests */ |
| 381 | static_assert(std::is_nothrow_constructible<AAAT,IIIT>::value,""); |
| 382 | static_assert(std::is_nothrow_constructible<AAAT,const IIIT>::value,""); |
| 383 | static_assert(std::is_nothrow_constructible<AAAT,IIIT&>::value,""); |
| 384 | static_assert(std::is_nothrow_constructible<AAAT,const IIIT &>::value,""); |
| 385 | |
| 386 | static_assert(test_trait::is_nothrow_convertible<IIIT,AAAT>::value,""); |
| 387 | static_assert(test_trait::is_nothrow_convertible<const IIIT,AAAT>::value,""); |
| 388 | static_assert(test_trait::is_nothrow_convertible<IIIT&,AAAT>::value,""); |
| 389 | static_assert(test_trait::is_nothrow_convertible<const IIIT &,AAAT>::value,""); |
| 390 | |
| 391 | static_assert(!std::is_nothrow_constructible<AAAT,IIAT>::value,""); |
| 392 | static_assert(!std::is_nothrow_constructible<AAAT,const IIAT>::value,""); |
| 393 | static_assert(!std::is_nothrow_constructible<AAAT,IIAT&>::value,""); |
| 394 | static_assert(!std::is_nothrow_constructible<AAAT,const IIAT &>::value,""); |
| 395 | |
| 396 | static_assert(!test_trait::is_nothrow_convertible<IIAT,AAAT>::value,""); |
| 397 | static_assert(!test_trait::is_nothrow_convertible<const IIAT,AAAT>::value,""); |
| 398 | static_assert(!test_trait::is_nothrow_convertible<IIAT&,AAAT>::value,""); |
| 399 | static_assert(!test_trait::is_nothrow_convertible<const IIAT &,AAAT>::value,""); |
| 400 | |
| 401 | static_assert(std::is_nothrow_constructible<AAAT,int&,const int&,int&&>::value,""); |
| 402 | static_assert(!std::is_nothrow_constructible<AAAT,int &,const A &&,const int&&>::value,""); |
| 403 | |
| 404 | void Run() |
| 405 | { |
| 406 | VERIFY( (checkCopyThrowConstruct<AT,int>()) ); |
| 407 | VERIFY( (checkMoveThrowConstruct<AT,int>()) ); |
| 408 | VERIFY( (checkCopyThrowConstruct<AT,A>()) ); |
| 409 | VERIFY( (checkMoveThrowConstruct<AT,A>()) ); |
| 410 | VERIFY( (checkCopyThrowConstruct<AT,AT>()) ); |
| 411 | VERIFY( (checkMoveThrowConstruct<AT,AT>()) ); |
| 412 | VERIFY( (checkCopyThrowConstruct<AT,IT>()) ); |
| 413 | VERIFY( (checkMoveThrowConstruct<AT,IT>()) ); |
| 414 | VERIFY( (checkMoveThrowConstruct<AT,CIT>()) ); |
| 415 | VERIFY( (checkCopyThrowConstruct<AAT,AAT>()) ); |
| 416 | VERIFY( (checkMoveThrowConstruct<AAT,AAT>()) ); |
| 417 | VERIFY( (checkCopyThrowConstruct<AAT,IIT>()) ); |
| 418 | VERIFY( (checkMoveThrowConstruct<AAT,IIT>()) ); |
| 419 | VERIFY( (checkCopyThrowConstruct<AAT,IIP>()) ); |
| 420 | VERIFY( (checkMoveThrowConstruct<AAT,IIP>()) ); |
| 421 | |
| 422 | VERIFY( (checkCopyThrowConstruct<AAT,std::tuple<int,A>>()) ); |
| 423 | VERIFY( (checkMoveThrowConstruct<AAT,std::tuple<int,A>>()) ); |
| 424 | VERIFY( (checkCopyThrowConstruct<AAT,std::pair<int,A>>()) ); |
| 425 | VERIFY( (checkMoveThrowConstruct<AAT,std::pair<int,A>>()) ); |
| 426 | |
| 427 | VERIFY( (checkCopyThrowConstruct<AAAT,AAAT>()) ); |
| 428 | VERIFY( (checkMoveThrowConstruct<AAAT,AAAT>()) ); |
| 429 | VERIFY( (checkCopyThrowConstruct<AAAT,IIAT>()) ); |
| 430 | VERIFY( (checkMoveThrowConstruct<AAAT,IIAT>()) ); |
| 431 | } |
| 432 | } |
| 433 | namespace NothrowCopyThrowMoveThrowCopyConversionNothrowMoveConversion |
| 434 | { |
| 435 | struct B |
| 436 | { |
| 437 | B() noexcept(true) |
| 438 | {} |
| 439 | |
| 440 | B(const int&) noexcept(false) |
| 441 | { throwing_ctor_called = true; } |
| 442 | |
| 443 | B(int&&) noexcept(true) |
| 444 | {} |
| 445 | |
| 446 | B(const B&) noexcept(true) |
| 447 | {} |
| 448 | |
| 449 | B(B&&) noexcept(false) |
| 450 | { throwing_ctor_called = true; } |
| 451 | }; |
| 452 | |
| 453 | |
| 454 | struct D |
| 455 | { |
| 456 | D() noexcept(true) |
| 457 | {} |
| 458 | |
| 459 | explicit |
| 460 | D(const int&) noexcept(false) |
| 461 | { throwing_ctor_called = true; } |
| 462 | |
| 463 | explicit |
| 464 | D(int&&) noexcept(true) |
| 465 | {} |
| 466 | |
| 467 | explicit |
| 468 | D(const D&) noexcept(true) |
| 469 | {} |
| 470 | |
| 471 | explicit |
| 472 | D(D&&) noexcept(false) |
| 473 | { throwing_ctor_called = true; } |
| 474 | |
| 475 | }; |
| 476 | |
| 477 | typedef std::tuple<B> BT; |
| 478 | typedef std::tuple<B,B> BBT; |
| 479 | typedef std::pair<B,B> BBP; |
| 480 | typedef std::tuple<D> DT; |
| 481 | typedef std::tuple<D,D> DDT; |
| 482 | typedef std::pair<D,D> DDP; |
| 483 | typedef std::tuple<int,D> IDT; |
| 484 | typedef std::pair<int,D> IDP; |
| 485 | typedef std::tuple<int,B> IBT; |
| 486 | typedef std::pair<int,B> IBP; |
| 487 | typedef std::tuple<D,B> DBT; |
| 488 | typedef std::pair<D,B> DBP; |
| 489 | typedef std::tuple<B,B,B> BBBT; |
| 490 | typedef std::tuple<D,D,D> DDDT; |
| 491 | typedef std::tuple<int,D,int> IDIT; |
| 492 | typedef std::tuple<int,B,int> IBIT; |
| 493 | typedef std::tuple<int,D,B> IDBT; |
| 494 | |
| 495 | /* one element tests */ |
| 496 | static_assert(std::is_nothrow_constructible<BT, int>::value, ""); |
| 497 | static_assert(!std::is_nothrow_constructible<BT, const int>::value, ""); |
| 498 | static_assert(!std::is_nothrow_constructible<BT, int&>::value, ""); |
| 499 | static_assert(!std::is_nothrow_constructible<BT, const int &>::value, ""); |
| 500 | |
| 501 | static_assert(std::is_nothrow_constructible<BT, IT>::value, ""); |
| 502 | static_assert(!std::is_nothrow_constructible<BT,const IT>::value, ""); |
| 503 | static_assert(!std::is_nothrow_constructible<BT, IT&>::value, ""); |
| 504 | static_assert(!std::is_nothrow_constructible<BT, const IT &>::value, ""); |
| 505 | static_assert(!std::is_nothrow_constructible<BT, std::tuple<int&>>::value, ""); |
| 506 | #if __cplusplus > 202002L |
| 507 | // C++23 extended tuple's constructor overload set as part of P2321R2, after |
| 508 | // which its converting constructors more accurately forward the elements |
| 509 | // from a non-const tuple lvalue and from a const tuple rvalue. In particular |
| 510 | // for the below test we now forward int&& as an rvalue reference instead of |
| 511 | // as an lvalue reference, which means we now select the noexcept B(int&&) |
| 512 | // ctor instead of the non-noexcept B(const int&) ctor. |
| 513 | static_assert(std::is_nothrow_constructible<BT, const std::tuple<int&&>>::value, ""); |
| 514 | #else |
| 515 | static_assert(!std::is_nothrow_constructible<BT, const std::tuple<int&&>>::value, ""); |
| 516 | #endif |
| 517 | |
| 518 | static_assert(test_trait::is_nothrow_convertible<int,BT>::value,""); |
| 519 | static_assert(!test_trait::is_nothrow_convertible<const int,BT>::value,""); |
| 520 | static_assert(!test_trait::is_nothrow_convertible<int&,BT>::value,""); |
| 521 | static_assert(!test_trait::is_nothrow_convertible<const int &,BT>::value,""); |
| 522 | |
| 523 | static_assert(test_trait::is_nothrow_convertible<IT,BT>::value,""); |
| 524 | static_assert(!test_trait::is_nothrow_convertible<const IT,BT>::value,""); |
| 525 | static_assert(!test_trait::is_nothrow_convertible<IT&,BT>::value,""); |
| 526 | static_assert(!test_trait::is_nothrow_convertible<const IT &,BT>::value,""); |
| 527 | static_assert(!test_trait::is_nothrow_convertible<std::tuple<int&>,BT>::value,""); |
| 528 | #if __cplusplus > 202002L |
| 529 | // See the note about P2321R2 above. |
| 530 | static_assert(test_trait::is_nothrow_convertible<const std::tuple<int&&>,BT>::value,""); |
| 531 | #else |
| 532 | static_assert(!test_trait::is_nothrow_convertible<const std::tuple<int&&>,BT>::value,""); |
| 533 | #endif |
| 534 | |
| 535 | |
| 536 | |
| 537 | static_assert(!std::is_nothrow_constructible<BT, B>::value, ""); |
| 538 | static_assert(std::is_nothrow_constructible<BT,const B>::value, ""); |
| 539 | static_assert(std::is_nothrow_constructible<BT, B&>::value, ""); |
| 540 | static_assert(std::is_nothrow_constructible<BT, const B &>::value, ""); |
| 541 | |
| 542 | static_assert(!std::is_nothrow_constructible<BT, BT>::value, ""); |
| 543 | static_assert(std::is_nothrow_constructible<BT,const BT>::value, ""); |
| 544 | static_assert(std::is_nothrow_constructible<BT, BT&>::value, ""); |
| 545 | static_assert(std::is_nothrow_constructible<BT, const BT &>::value, ""); |
| 546 | static_assert(std::is_nothrow_constructible<BT, std::tuple<B&>>::value, ""); |
| 547 | #if __cplusplus > 202002L |
| 548 | // See the note about P2321R2 above. |
| 549 | static_assert(!std::is_nothrow_constructible<BT, const std::tuple<B&&>>::value, ""); |
| 550 | #else |
| 551 | static_assert(std::is_nothrow_constructible<BT, const std::tuple<B&&>>::value, ""); |
| 552 | #endif |
| 553 | |
| 554 | static_assert(!test_trait::is_nothrow_convertible<B,BT>::value,""); |
| 555 | static_assert(test_trait::is_nothrow_convertible<const B,BT>::value,""); |
| 556 | static_assert(test_trait::is_nothrow_convertible<B&,BT>::value,""); |
| 557 | static_assert(test_trait::is_nothrow_convertible<const B &,BT>::value,""); |
| 558 | |
| 559 | static_assert(!test_trait::is_nothrow_convertible<BT,BT>::value,""); |
| 560 | static_assert(test_trait::is_nothrow_convertible<const BT,BT>::value,""); |
| 561 | static_assert(test_trait::is_nothrow_convertible<BT&,BT>::value,""); |
| 562 | static_assert(test_trait::is_nothrow_convertible<const BT &,BT>::value,""); |
| 563 | static_assert(test_trait::is_nothrow_convertible<std::tuple<B&>,BT>::value,""); |
| 564 | #if __cplusplus > 202002L |
| 565 | // See the note about P2321R2 above. |
| 566 | static_assert(!test_trait::is_nothrow_convertible<const std::tuple<B&&>,BT>::value,""); |
| 567 | #else |
| 568 | static_assert(test_trait::is_nothrow_convertible<const std::tuple<B&&>,BT>::value,""); |
| 569 | #endif |
| 570 | |
| 571 | /* explicit */ |
| 572 | static_assert(std::is_nothrow_constructible<DT, int>::value, ""); |
| 573 | static_assert(!std::is_nothrow_constructible<DT, const int>::value, ""); |
| 574 | static_assert(!std::is_nothrow_constructible<DT, int&>::value, ""); |
| 575 | static_assert(!std::is_nothrow_constructible<DT, const int &>::value, ""); |
| 576 | |
| 577 | static_assert(std::is_nothrow_constructible<DT, IT>::value, ""); |
| 578 | static_assert(!std::is_nothrow_constructible<DT,const IT>::value, ""); |
| 579 | static_assert(!std::is_nothrow_constructible<DT, IT&>::value, ""); |
| 580 | static_assert(!std::is_nothrow_constructible<DT, const IT &>::value, ""); |
| 581 | static_assert(!std::is_nothrow_constructible<DT, std::tuple<int&>>::value, ""); |
| 582 | #if __cplusplus > 202002L |
| 583 | // See the note about P2321R2 above. |
| 584 | static_assert(std::is_nothrow_constructible<DT, const std::tuple<int&&>>::value, ""); |
| 585 | #else |
| 586 | static_assert(!std::is_nothrow_constructible<DT, const std::tuple<int&&>>::value, ""); |
| 587 | #endif |
| 588 | |
| 589 | static_assert(!std::is_nothrow_constructible<DT, D>::value, ""); |
| 590 | static_assert(std::is_nothrow_constructible<DT,const D>::value, ""); |
| 591 | static_assert(std::is_nothrow_constructible<DT, D&>::value, ""); |
| 592 | static_assert(std::is_nothrow_constructible<DT, const D &>::value, ""); |
| 593 | |
| 594 | static_assert(!std::is_nothrow_constructible<DT, DT>::value, ""); |
| 595 | static_assert(std::is_nothrow_constructible<DT,const DT>::value, ""); |
| 596 | static_assert(std::is_nothrow_constructible<DT, DT&>::value, ""); |
| 597 | static_assert(std::is_nothrow_constructible<DT, const DT &>::value, ""); |
| 598 | static_assert(std::is_nothrow_constructible<DT, std::tuple<D&>>::value, ""); |
| 599 | #if __cplusplus > 202002L |
| 600 | // See note about P2321R2 above. |
| 601 | static_assert(!std::is_nothrow_constructible<DT, const std::tuple<D&&>>::value, ""); |
| 602 | #else |
| 603 | static_assert(std::is_nothrow_constructible<DT, const std::tuple<D&&>>::value, ""); |
| 604 | #endif |
| 605 | |
| 606 | static_assert(!test_trait::is_nothrow_convertible<DT,DT>::value,""); |
| 607 | static_assert(test_trait::is_nothrow_convertible<const DT,DT>::value,""); |
| 608 | static_assert(test_trait::is_nothrow_convertible<DT&,DT>::value,""); |
| 609 | static_assert(test_trait::is_nothrow_convertible<const DT &,DT>::value,""); |
| 610 | |
| 611 | /* two elements tests */ |
| 612 | static_assert(std::is_nothrow_constructible<BBT,IIT>::value,""); |
| 613 | static_assert(!std::is_nothrow_constructible<BBT,const IIT>::value,""); |
| 614 | static_assert(!std::is_nothrow_constructible<BBT,IIT&>::value,""); |
| 615 | static_assert(!std::is_nothrow_constructible<BBT,const IIT &>::value,""); |
| 616 | static_assert(std::is_nothrow_constructible<BBT,IIP>::value,""); |
| 617 | static_assert(!std::is_nothrow_constructible<BBT,const IIP>::value,""); |
| 618 | static_assert(!std::is_nothrow_constructible<BBT,IIP&>::value,""); |
| 619 | static_assert(!std::is_nothrow_constructible<BBT,const IIP &>::value,""); |
| 620 | static_assert(!std::is_nothrow_constructible<BBT,std::tuple<int&,int&>>::value,""); |
| 621 | |
| 622 | static_assert(test_trait::is_nothrow_convertible<IIT,BBT>::value,""); |
| 623 | static_assert(!test_trait::is_nothrow_convertible<const IIT,BBT>::value,""); |
| 624 | static_assert(!test_trait::is_nothrow_convertible<IIT&,BBT>::value,""); |
| 625 | static_assert(!test_trait::is_nothrow_convertible<const IIT &,BBT>::value,""); |
| 626 | static_assert(test_trait::is_nothrow_convertible<IIP,BBT>::value,""); |
| 627 | static_assert(!test_trait::is_nothrow_convertible<const IIP,BBT>::value,""); |
| 628 | static_assert(!test_trait::is_nothrow_convertible<IIP&,BBT>::value,""); |
| 629 | static_assert(!test_trait::is_nothrow_convertible<const IIP &,BBT>::value,""); |
| 630 | static_assert(!test_trait::is_nothrow_convertible<std::tuple<int&,int&>,BBT>::value,""); |
| 631 | |
| 632 | static_assert(!std::is_nothrow_constructible<BBT,BBT>::value,""); |
| 633 | static_assert(std::is_nothrow_constructible<BBT,const BBT>::value,""); |
| 634 | static_assert(std::is_nothrow_constructible<BBT,BBT&>::value,""); |
| 635 | static_assert(std::is_nothrow_constructible<BBT,const BBT &>::value,""); |
| 636 | static_assert(!std::is_nothrow_constructible<BBT,BBP>::value,""); |
| 637 | static_assert(std::is_nothrow_constructible<BBT,const BBP>::value,""); |
| 638 | static_assert(std::is_nothrow_constructible<BBT,BBP&>::value,""); |
| 639 | static_assert(std::is_nothrow_constructible<BBT,const BBP &>::value,""); |
| 640 | static_assert(std::is_nothrow_constructible<BBT,std::tuple<B&,B&>>::value,""); |
| 641 | |
| 642 | static_assert(!std::is_nothrow_constructible<BBT,IBT>::value,""); |
| 643 | static_assert(!std::is_nothrow_constructible<BBT,const IBT>::value,""); |
| 644 | static_assert(!std::is_nothrow_constructible<BBT,IBT&>::value,""); |
| 645 | static_assert(!std::is_nothrow_constructible<BBT,const IBT &>::value,""); |
| 646 | static_assert(!std::is_nothrow_constructible<BBT,IBP>::value,""); |
| 647 | static_assert(!std::is_nothrow_constructible<BBT,const IBP>::value,""); |
| 648 | static_assert(!std::is_nothrow_constructible<BBT,IBP&>::value,""); |
| 649 | static_assert(!std::is_nothrow_constructible<BBT,const IBP &>::value,""); |
| 650 | static_assert(std::is_nothrow_constructible<BBT,std::tuple<const B&,int&&>>::value,""); |
| 651 | |
| 652 | static_assert(!test_trait::is_nothrow_convertible<BBT,BBT>::value,""); |
| 653 | static_assert(test_trait::is_nothrow_convertible<const BBT,BBT>::value,""); |
| 654 | static_assert(test_trait::is_nothrow_convertible<BBT&,BBT>::value,""); |
| 655 | static_assert(test_trait::is_nothrow_convertible<const BBT &,BBT>::value,""); |
| 656 | static_assert(!test_trait::is_nothrow_convertible<BBP,BBT>::value,""); |
| 657 | static_assert(test_trait::is_nothrow_convertible<const BBP,BBT>::value,""); |
| 658 | static_assert(test_trait::is_nothrow_convertible<BBP&,BBT>::value,""); |
| 659 | static_assert(test_trait::is_nothrow_convertible<const BBP &,BBT>::value,""); |
| 660 | static_assert(test_trait::is_nothrow_convertible<std::tuple<B&,int&&>,BBT>::value,""); |
| 661 | |
| 662 | static_assert(!test_trait::is_nothrow_convertible<IBT,BBT>::value,""); |
| 663 | static_assert(!test_trait::is_nothrow_convertible<const IBT,BBT>::value,""); |
| 664 | static_assert(!test_trait::is_nothrow_convertible<IBT&,BBT>::value,""); |
| 665 | static_assert(!test_trait::is_nothrow_convertible<const IBT &,BBT>::value,""); |
| 666 | static_assert(!test_trait::is_nothrow_convertible<IBP,BBT>::value,""); |
| 667 | static_assert(!test_trait::is_nothrow_convertible<const IBP,BBT>::value,""); |
| 668 | static_assert(!test_trait::is_nothrow_convertible<IBP&,BBT>::value,""); |
| 669 | static_assert(!test_trait::is_nothrow_convertible<const IBP &,BBT>::value,""); |
| 670 | static_assert(!test_trait::is_nothrow_convertible<std::tuple<B&,int&>,BBT>::value,""); |
| 671 | |
| 672 | |
| 673 | static_assert(!std::is_nothrow_constructible<BBT,int&,const int&>::value,""); |
| 674 | static_assert(std::is_nothrow_constructible<BBT,int&&,const B&>::value,""); |
| 675 | |
| 676 | static_assert(std::is_nothrow_constructible<BBT,B&,const B&>::value,""); |
| 677 | static_assert(!std::is_nothrow_constructible<BBT,B&&,const B&&>::value,""); |
| 678 | static_assert(!std::is_nothrow_constructible<BBT,const B &&,const int&&>::value,""); |
| 679 | |
| 680 | /* explicit */ |
| 681 | static_assert(std::is_nothrow_constructible<DDT,IIT>::value,""); |
| 682 | static_assert(!std::is_nothrow_constructible<DDT,const IIT>::value,""); |
| 683 | static_assert(!std::is_nothrow_constructible<DDT,IIT&>::value,""); |
| 684 | static_assert(!std::is_nothrow_constructible<DDT,const IIT &>::value,""); |
| 685 | static_assert(std::is_nothrow_constructible<DDT,IIP>::value,""); |
| 686 | static_assert(!std::is_nothrow_constructible<DDT,const IIP>::value,""); |
| 687 | static_assert(!std::is_nothrow_constructible<DDT,IIP&>::value,""); |
| 688 | static_assert(!std::is_nothrow_constructible<DDT,const IIP &>::value,""); |
| 689 | static_assert(!std::is_nothrow_constructible<DDT,std::tuple<int&,int&>>::value,""); |
| 690 | |
| 691 | static_assert(!std::is_nothrow_constructible<DDT,DDT>::value,""); |
| 692 | static_assert(std::is_nothrow_constructible<DDT,const DDT>::value,""); |
| 693 | static_assert(std::is_nothrow_constructible<DDT,DDT&>::value,""); |
| 694 | static_assert(std::is_nothrow_constructible<DDT,const DDT &>::value,""); |
| 695 | static_assert(!std::is_nothrow_constructible<DDT,DDP>::value,""); |
| 696 | static_assert(std::is_nothrow_constructible<DDT,const DDP>::value,""); |
| 697 | static_assert(std::is_nothrow_constructible<DDT,DDP&>::value,""); |
| 698 | static_assert(std::is_nothrow_constructible<DDT,const DDP &>::value,""); |
| 699 | static_assert(std::is_nothrow_constructible<DDT,std::tuple<D&,D&>>::value,""); |
| 700 | |
| 701 | static_assert(!std::is_nothrow_constructible<DDT,IDT>::value,""); |
| 702 | static_assert(!std::is_nothrow_constructible<DDT,const IDT>::value,""); |
| 703 | static_assert(!std::is_nothrow_constructible<DDT,IDT&>::value,""); |
| 704 | static_assert(!std::is_nothrow_constructible<DDT,const IDT &>::value,""); |
| 705 | static_assert(!std::is_nothrow_constructible<DDT,IDP>::value,""); |
| 706 | static_assert(!std::is_nothrow_constructible<DDT,const IDP>::value,""); |
| 707 | static_assert(!std::is_nothrow_constructible<DDT,IDP&>::value,""); |
| 708 | static_assert(!std::is_nothrow_constructible<DDT,const IDP &>::value,""); |
| 709 | static_assert(std::is_nothrow_constructible<DDT,std::tuple<const D&,int&&>>::value,""); |
| 710 | |
| 711 | static_assert(!test_trait::is_nothrow_convertible<DDT,DDT>::value,""); |
| 712 | static_assert(test_trait::is_nothrow_convertible<const DDT,DDT>::value,""); |
| 713 | static_assert(test_trait::is_nothrow_convertible<DDT&,DDT>::value,""); |
| 714 | static_assert(test_trait::is_nothrow_convertible<const DDT &,DDT>::value,""); |
| 715 | |
| 716 | static_assert(!std::is_nothrow_constructible<DDT,int&,const int&>::value,""); |
| 717 | static_assert(std::is_nothrow_constructible<DDT,int&&,const D&>::value,""); |
| 718 | |
| 719 | static_assert(std::is_nothrow_constructible<DDT,D&,const D&>::value,""); |
| 720 | static_assert(!std::is_nothrow_constructible<DDT,D&&,const D&&>::value,""); |
| 721 | static_assert(!std::is_nothrow_constructible<DDT,const D &&,const int&&>::value,""); |
| 722 | |
| 723 | /* three elements tests */ |
| 724 | static_assert(std::is_nothrow_constructible<BBBT,IIIT>::value,""); |
| 725 | static_assert(!std::is_nothrow_constructible<BBBT,const IIIT>::value,""); |
| 726 | static_assert(!std::is_nothrow_constructible<BBBT,IIIT&>::value,""); |
| 727 | static_assert(!std::is_nothrow_constructible<BBBT,const IIIT &>::value,""); |
| 728 | |
| 729 | static_assert(test_trait::is_nothrow_convertible<IIIT,BBBT>::value,""); |
| 730 | static_assert(!test_trait::is_nothrow_convertible<const IIIT,BBBT>::value,""); |
| 731 | static_assert(!test_trait::is_nothrow_convertible<IIIT&,BBBT>::value,""); |
| 732 | static_assert(!test_trait::is_nothrow_convertible<const IIIT &,BBBT>::value,""); |
| 733 | |
| 734 | static_assert(!std::is_nothrow_constructible<BBBT,BBBT>::value,""); |
| 735 | static_assert(std::is_nothrow_constructible<BBBT,const BBBT>::value,""); |
| 736 | static_assert(std::is_nothrow_constructible<BBBT,BBBT&>::value,""); |
| 737 | static_assert(std::is_nothrow_constructible<BBBT,const BBBT &>::value,""); |
| 738 | |
| 739 | static_assert(!test_trait::is_nothrow_convertible<BBBT,BBBT>::value,""); |
| 740 | static_assert(test_trait::is_nothrow_convertible<const BBBT,BBBT>::value,""); |
| 741 | static_assert(test_trait::is_nothrow_convertible<BBBT&,BBBT>::value,""); |
| 742 | static_assert(test_trait::is_nothrow_convertible<const BBBT &,BBBT>::value,""); |
| 743 | |
| 744 | static_assert(!std::is_nothrow_constructible<BBBT,int&,const int&,int&&>::value,""); |
| 745 | static_assert(!std::is_nothrow_constructible<BBBT,int&, B&&,const int&&>::value,""); |
| 746 | static_assert(std::is_nothrow_constructible<BBBT,int&&, B&,const B&&>::value,""); |
| 747 | |
| 748 | static_assert(!std::is_nothrow_constructible<BBBT,std::tuple<int&,const int&,int&&>>::value,""); |
| 749 | static_assert(!std::is_nothrow_constructible<BBBT,std::tuple<int &, B&&,const int&&>>::value,""); |
| 750 | static_assert(std::is_nothrow_constructible<BBBT,std::tuple<int &&, B&,const B&&>>::value,""); |
| 751 | |
| 752 | /* explicit */ |
| 753 | static_assert(std::is_nothrow_constructible<DDDT,IIIT>::value,""); |
| 754 | static_assert(!std::is_nothrow_constructible<DDDT,const IIIT>::value,""); |
| 755 | static_assert(!std::is_nothrow_constructible<DDDT,IIIT&>::value,""); |
| 756 | static_assert(!std::is_nothrow_constructible<DDDT,const IIIT &>::value,""); |
| 757 | |
| 758 | static_assert(!std::is_nothrow_constructible<DDDT,DDDT>::value,""); |
| 759 | static_assert(std::is_nothrow_constructible<DDDT,const DDDT>::value,""); |
| 760 | static_assert(std::is_nothrow_constructible<DDDT,DDDT&>::value,""); |
| 761 | static_assert(std::is_nothrow_constructible<DDDT,const DDDT &>::value,""); |
| 762 | |
| 763 | static_assert(!test_trait::is_nothrow_convertible<DDDT,DDDT>::value,""); |
| 764 | static_assert(test_trait::is_nothrow_convertible<const DDDT,DDDT>::value,""); |
| 765 | static_assert(test_trait::is_nothrow_convertible<DDDT&,DDDT>::value,""); |
| 766 | static_assert(test_trait::is_nothrow_convertible<const DDDT &,DDDT>::value,""); |
| 767 | |
| 768 | static_assert(!std::is_nothrow_constructible<DDDT,int&,const int&,int&&>::value,""); |
| 769 | static_assert(!std::is_nothrow_constructible<DDDT,int &, D&&,const int&&>::value,""); |
| 770 | static_assert(std::is_nothrow_constructible<DDDT,int &&, D&,const D&&>::value,""); |
| 771 | |
| 772 | static_assert(!std::is_nothrow_constructible<DDDT,std::tuple<int&,const int&,int&&>>::value,""); |
| 773 | static_assert(!std::is_nothrow_constructible<DDDT,std::tuple<int &, D&&,const int&&>>::value,""); |
| 774 | static_assert(std::is_nothrow_constructible<DDDT,std::tuple<int &&, D&,const D&&>>::value,""); |
| 775 | |
| 776 | |
| 777 | void Run() |
| 778 | { |
| 779 | VERIFY( (checkCopyThrowConstruct<BT, int>()) ); |
| 780 | VERIFY( (checkMoveThrowConstruct<BT, int>()) ); |
| 781 | VERIFY( (checkCopyThrowConstruct<BT, B>()) ); |
| 782 | VERIFY( (checkMoveThrowConstruct<BT, B>()) ); |
| 783 | VERIFY( (checkCopyThrowConstruct<BT, IT>()) ); |
| 784 | VERIFY( (checkMoveThrowConstruct<BT, IT>()) ); |
| 785 | VERIFY( (checkMoveThrowConstruct<BT, CIT>()) ); |
| 786 | VERIFY( (checkCopyThrowConstruct<BBT, IIT>()) ); |
| 787 | VERIFY( (checkMoveThrowConstruct<BBT, IIT>()) ); |
| 788 | VERIFY( (checkCopyThrowConstruct<BBT, IIP>()) ); |
| 789 | VERIFY( (checkMoveThrowConstruct<BBT, IIP>()) ); |
| 790 | VERIFY( (checkCopyThrowConstruct<BBT, BBP>()) ); |
| 791 | VERIFY( (checkMoveThrowConstruct<BBT, BBP>()) ); |
| 792 | VERIFY( (checkCopyThrowConstruct<BBT, std::tuple<B, int>>()) ); |
| 793 | VERIFY( (checkMoveThrowConstruct<BBT, std::tuple<B, int>>()) ); |
| 794 | |
| 795 | VERIFY( (checkCopyThrowConstruct<DT, int>()) ); |
| 796 | VERIFY( (checkMoveThrowConstruct<DT, int>()) ); |
| 797 | VERIFY( (checkCopyThrowConstruct<DT, D>()) ); |
| 798 | VERIFY( (checkMoveThrowConstruct<DT, D>()) ); |
| 799 | VERIFY( (checkCopyThrowConstruct<DT, IT>()) ); |
| 800 | VERIFY( (checkMoveThrowConstruct<DT, IT>()) ); |
| 801 | VERIFY( (checkMoveThrowConstruct<DT, CIT>()) ); |
| 802 | VERIFY( (checkCopyThrowConstruct<DDT, IIT>()) ); |
| 803 | VERIFY( (checkMoveThrowConstruct<DDT, IIT>()) ); |
| 804 | VERIFY( (checkCopyThrowConstruct<DDT, IIP>()) ); |
| 805 | VERIFY( (checkMoveThrowConstruct<DDT, IIP>()) ); |
| 806 | VERIFY( (checkCopyThrowConstruct<DDT, DDP>()) ); |
| 807 | VERIFY( (checkMoveThrowConstruct<DDT, DDP>()) ); |
| 808 | VERIFY( (checkCopyThrowConstruct<DDT, std::tuple<D, int>>()) ); |
| 809 | VERIFY( (checkMoveThrowConstruct<DDT, std::tuple<D, int>>()) ); |
| 810 | |
| 811 | VERIFY( (checkCopyThrowConstruct<DBT, IIT>()) ); |
| 812 | VERIFY( (checkMoveThrowConstruct<DBT, IIT>()) ); |
| 813 | VERIFY( (checkCopyThrowConstruct<DBT, DBT>()) ); |
| 814 | VERIFY( (checkMoveThrowConstruct<DBT, DBT>()) ); |
| 815 | VERIFY( (checkCopyThrowConstruct<DBT, DBP>()) ); |
| 816 | VERIFY( (checkMoveThrowConstruct<DBT, DBP>()) ); |
| 817 | VERIFY( (checkCopyThrowConstruct<DBT, IIP>()) ); |
| 818 | VERIFY( (checkMoveThrowConstruct<DBT, IIP>()) ); |
| 819 | |
| 820 | |
| 821 | VERIFY( (checkCopyThrowConstruct<IDIT, IIIT>()) ); |
| 822 | VERIFY( (checkMoveThrowConstruct<IDIT, IIIT>()) ); |
| 823 | VERIFY( (checkCopyThrowConstruct<IDIT, IDIT>()) ); |
| 824 | VERIFY( (checkMoveThrowConstruct<IDIT, IDIT>()) ); |
| 825 | VERIFY( (checkCopyThrowConstruct<IBIT, IIIT>()) ); |
| 826 | VERIFY( (checkMoveThrowConstruct<IBIT, IIIT>()) ); |
| 827 | VERIFY( (checkCopyThrowConstruct<IBIT, IBIT>()) ); |
| 828 | VERIFY( (checkMoveThrowConstruct<IBIT, IBIT>()) ); |
| 829 | VERIFY( (checkCopyThrowConstruct<IDBT, IIIT>()) ); |
| 830 | VERIFY( (checkMoveThrowConstruct<IDBT, IIIT>()) ); |
| 831 | VERIFY( (checkCopyThrowConstruct<IDBT, IDBT>()) ); |
| 832 | VERIFY( (checkMoveThrowConstruct<IDBT, IDBT>()) ); |
| 833 | |
| 834 | } |
| 835 | } |
| 836 | namespace ThrowCopy |
| 837 | { |
| 838 | struct C |
| 839 | { |
| 840 | C() noexcept(true) |
| 841 | {} |
| 842 | |
| 843 | explicit |
| 844 | C(const C&) noexcept(true) {} |
| 845 | |
| 846 | }; |
| 847 | |
| 848 | typedef std::tuple<C> CT; |
| 849 | typedef std::tuple<C,C> CCT; |
| 850 | typedef std::pair<C,C> CCP; |
| 851 | typedef std::tuple<int,int,C> IICT; |
| 852 | |
| 853 | static_assert(std::is_nothrow_constructible<CT, C&>::value, ""); |
| 854 | static_assert(std::is_nothrow_constructible<CT, const C&>::value, ""); |
| 855 | static_assert(std::is_nothrow_constructible<CT, C&&>::value, ""); |
| 856 | static_assert(std::is_nothrow_constructible<CT, const C &&>::value, ""); |
| 857 | |
| 858 | |
| 859 | static_assert(std::is_nothrow_constructible<CCT, C&, C&>::value, ""); |
| 860 | static_assert(std::is_nothrow_constructible<CCT, const C&, const C&>::value, ""); |
| 861 | static_assert(std::is_nothrow_constructible<CCT, C&&, C&&>::value, ""); |
| 862 | static_assert(std::is_nothrow_constructible<CCT, const C &&, const C &&>::value, ""); |
| 863 | |
| 864 | static_assert(std::is_nothrow_constructible<IICT, int, int, C&>::value, ""); |
| 865 | static_assert(std::is_nothrow_constructible<IICT, int, int, const C&>::value, ""); |
| 866 | static_assert(std::is_nothrow_constructible<IICT, int, int, C&&>::value, ""); |
| 867 | static_assert(std::is_nothrow_constructible<IICT, int, int, const C &&>::value, ""); |
| 868 | |
| 869 | static_assert(std::is_nothrow_constructible<CT, CT&>::value, ""); |
| 870 | static_assert(std::is_nothrow_constructible<CT, const CT&>::value, ""); |
| 871 | static_assert(std::is_nothrow_constructible<CT, CT&&>::value, ""); |
| 872 | static_assert(std::is_nothrow_constructible<CT, const CT &&>::value, ""); |
| 873 | |
| 874 | static_assert(std::is_nothrow_constructible<CCT, CCT&>::value, ""); |
| 875 | static_assert(std::is_nothrow_constructible<CCT, const CCT&>::value, ""); |
| 876 | static_assert(std::is_nothrow_constructible<CCT, CCT&&>::value, ""); |
| 877 | static_assert(std::is_nothrow_constructible<CCT, const CCT &&>::value, ""); |
| 878 | |
| 879 | static_assert(std::is_nothrow_constructible<CCT, CCP&>::value, ""); |
| 880 | static_assert(std::is_nothrow_constructible<CCT, const CCP&>::value, ""); |
| 881 | static_assert(std::is_nothrow_constructible<CCT, CCP&&>::value, ""); |
| 882 | static_assert(std::is_nothrow_constructible<CCT, const CCP &&>::value, ""); |
| 883 | |
| 884 | static_assert(std::is_nothrow_constructible<IICT, IICT&>::value, ""); |
| 885 | static_assert(std::is_nothrow_constructible<IICT, const IICT&>::value, ""); |
| 886 | static_assert(std::is_nothrow_constructible<IICT, IICT&&>::value, ""); |
| 887 | static_assert(std::is_nothrow_constructible<IICT, const IICT &&>::value, ""); |
| 888 | |
| 889 | } |
| 890 | namespace ThrowMoveNothrowConversion |
| 891 | { |
| 892 | struct D |
| 893 | { |
| 894 | D() noexcept(true) |
| 895 | {} |
| 896 | |
| 897 | explicit |
| 898 | D(const int&) noexcept(true) |
| 899 | {} |
| 900 | |
| 901 | explicit |
| 902 | D(int&&) noexcept(false) |
| 903 | { throwing_ctor_called = true; } |
| 904 | |
| 905 | }; |
| 906 | |
| 907 | typedef std::tuple<D> DT; |
| 908 | typedef std::tuple<D,D> DDT; |
| 909 | typedef std::pair<D,D> DDP; |
| 910 | typedef std::tuple<int,D,int> IDIT; |
| 911 | |
| 912 | |
| 913 | static_assert(!std::is_nothrow_constructible<DT, int>::value, ""); |
| 914 | static_assert(std::is_nothrow_constructible<DT, const int>::value, ""); |
| 915 | static_assert(std::is_nothrow_constructible<DT, int&>::value, ""); |
| 916 | static_assert(std::is_nothrow_constructible<DT, const int &>::value, ""); |
| 917 | |
| 918 | static_assert(!std::is_nothrow_constructible<DT, IT>::value, ""); |
| 919 | static_assert(std::is_nothrow_constructible<DT,const IT>::value, ""); |
| 920 | static_assert(std::is_nothrow_constructible<DT, IT&>::value, ""); |
| 921 | static_assert(std::is_nothrow_constructible<DT, const IT &>::value, ""); |
| 922 | static_assert(std::is_nothrow_constructible<DT, std::tuple<int&>>::value, ""); |
| 923 | #if __cplusplus > 202002L |
| 924 | // See the note about P2321R2 above. |
| 925 | static_assert(!std::is_nothrow_constructible<DT, const std::tuple<int&&>>::value, ""); |
| 926 | #else |
| 927 | static_assert(std::is_nothrow_constructible<DT, const std::tuple<int&&>>::value, ""); |
| 928 | #endif |
| 929 | |
| 930 | static_assert(test_trait::is_nothrow_convertible<DT,DT>::value,""); |
| 931 | static_assert(test_trait::is_nothrow_convertible<D,DT>::value,""); |
| 932 | |
| 933 | /* two elements tests */ |
| 934 | static_assert(!std::is_nothrow_constructible<DDT,IIT>::value,""); |
| 935 | static_assert(std::is_nothrow_constructible<DDT,const IIT>::value,""); |
| 936 | static_assert(std::is_nothrow_constructible<DDT,IIT&>::value,""); |
| 937 | static_assert(std::is_nothrow_constructible<DDT,const IIT &>::value,""); |
| 938 | static_assert(!std::is_nothrow_constructible<DDT,IIP>::value,""); |
| 939 | static_assert(std::is_nothrow_constructible<DDT,const IIP>::value,""); |
| 940 | static_assert(std::is_nothrow_constructible<DDT,IIP&>::value,""); |
| 941 | static_assert(std::is_nothrow_constructible<DDT,const IIP &>::value,""); |
| 942 | static_assert(std::is_nothrow_constructible<DDT,std::tuple<int&,int&>>::value,""); |
| 943 | |
| 944 | static_assert(std::is_nothrow_constructible<DDT,DDT>::value,""); |
| 945 | static_assert(std::is_nothrow_constructible<DDT,DDP>::value,""); |
| 946 | static_assert(std::is_nothrow_constructible<DDT,std::tuple<int&,D>>::value,""); |
| 947 | static_assert(!std::is_nothrow_constructible<DDT,std::pair<D,int&&>>::value,""); |
| 948 | |
| 949 | static_assert(std::is_convertible<DDT,DDT>::value,""); |
| 950 | |
| 951 | /* three elements tests */ |
| 952 | static_assert(!std::is_nothrow_constructible<IDIT,IIIT>::value,""); |
| 953 | static_assert(std::is_nothrow_constructible<IDIT,const IIIT>::value,""); |
| 954 | static_assert(std::is_nothrow_constructible<IDIT,IIIT&>::value,""); |
| 955 | static_assert(std::is_nothrow_constructible<IDIT,const IIIT &>::value,""); |
| 956 | |
| 957 | static_assert(test_trait::is_nothrow_convertible<IDIT,IDIT>::value,""); |
| 958 | static_assert(test_trait::is_nothrow_convertible<IDIT,IDIT>::value,""); |
| 959 | |
| 960 | static_assert(std::is_nothrow_constructible<IDIT,int&,const int&,int&&>::value,""); |
| 961 | static_assert(std::is_nothrow_constructible<IDIT,int &, D&&,const int&&>::value,""); |
| 962 | static_assert(std::is_nothrow_constructible<IDIT,std::tuple<int&,const int&,int&&>>::value,""); |
| 963 | static_assert(!std::is_nothrow_constructible<IDIT,std::tuple<int &, int&&,const int&&>>::value,""); |
| 964 | |
| 965 | void Run() |
| 966 | { |
| 967 | VERIFY( (checkCopyThrowConstruct<DDT, IIT>()) ); |
| 968 | VERIFY( (checkMoveThrowConstruct<DDT, IIT>()) ); |
| 969 | VERIFY( (checkCopyThrowConstruct<DDT, std::tuple<D, int>>()) ); |
| 970 | VERIFY( (checkMoveThrowConstruct<DDT, std::tuple<D, int>>()) ); |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | int main() |
| 975 | { |
| 976 | |
| 977 | DefaultConstructionTests::Run(); |
| 978 | |
| 979 | ThrowCopyNothrowConversion::Run(); |
| 980 | |
| 981 | NothrowCopyThrowMoveThrowCopyConversionNothrowMoveConversion::Run(); |
| 982 | |
| 983 | ThrowMoveNothrowConversion::Run(); |
| 984 | |
| 985 | } |
| 986 |