|
| 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 | + |
| 10 | +// <type_traits> |
| 11 | +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 |
| 12 | + |
| 13 | +#include <type_traits> |
| 14 | + |
| 15 | +struct A {}; |
| 16 | +struct B { |
| 17 | +public: |
| 18 | + operator A() { return a; } A a; |
| 19 | +}; |
| 20 | + |
| 21 | +class C { }; |
| 22 | +class D { |
| 23 | +public: |
| 24 | + operator C() noexcept { return c; } C c; |
| 25 | +}; |
| 26 | + |
| 27 | +int main(int, char**) { |
| 28 | + static_assert((std::is_nothrow_convertible<int, double>::value), ""); |
| 29 | + static_assert(!(std::is_nothrow_convertible<int, char*>::value), ""); |
| 30 | + |
| 31 | + static_assert(!(std::is_nothrow_convertible<A, B>::value), ""); |
| 32 | + static_assert((std::is_nothrow_convertible<D, C>::value), ""); |
| 33 | + |
| 34 | + static_assert((std::is_nothrow_convertible_v<int, double>), ""); |
| 35 | + static_assert(!(std::is_nothrow_convertible_v<int, char*>), ""); |
| 36 | + |
| 37 | + static_assert(!(std::is_nothrow_convertible_v<A, B>), ""); |
| 38 | + static_assert((std::is_nothrow_convertible_v<D, C>), ""); |
| 39 | + |
| 40 | + static_assert((std::is_nothrow_convertible_v<const void, void>), ""); |
| 41 | + static_assert((std::is_nothrow_convertible_v<volatile void, void>), ""); |
| 42 | + static_assert((std::is_nothrow_convertible_v<void, const void>), ""); |
| 43 | + static_assert((std::is_nothrow_convertible_v<void, volatile void>), ""); |
| 44 | + |
| 45 | + static_assert(!(std::is_nothrow_convertible_v<int[], double[]>), ""); |
| 46 | + static_assert(!(std::is_nothrow_convertible_v<int[], int[]>), ""); |
| 47 | + static_assert(!(std::is_nothrow_convertible_v<int[10], int[10]>), ""); |
| 48 | + static_assert(!(std::is_nothrow_convertible_v<int[10], double[10]>), ""); |
| 49 | + static_assert(!(std::is_nothrow_convertible_v<int[5], double[10]>), ""); |
| 50 | + static_assert(!(std::is_nothrow_convertible_v<int[10], A[10]>), ""); |
| 51 | + |
| 52 | + typedef void V(); |
| 53 | + typedef int I(); |
| 54 | + static_assert(!(std::is_nothrow_convertible_v<V, V>), ""); |
| 55 | + static_assert(!(std::is_nothrow_convertible_v<V, I>), ""); |
| 56 | + |
| 57 | + return 0; |
| 58 | +} |
0 commit comments