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