1 // { dg-do compile { target c++11 } }
2
3 // 2009-10-29 Paolo Carlini <paolo.carlini@oracle.com>
4 //
5 // Copyright (C) 2009-2018 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 <type_traits>
23 #include <testsuite_tr1.h>
24
test01()25 void test01()
26 {
27 using std::is_convertible;
28 using namespace __gnu_test;
29
30 // Positive tests.
31 static_assert(test_relationship<is_convertible, int, int>(true), "");
32 static_assert(test_relationship<is_convertible, int, const int>(true), "");
33 static_assert(test_relationship<is_convertible,
34 volatile int, const int>(true), "");
35 static_assert(test_relationship<is_convertible, int, float>(true), "");
36 static_assert(test_relationship<is_convertible, double, float>(true), "");
37 static_assert(test_relationship<is_convertible, float, int>(true), "");
38 static_assert(test_relationship<is_convertible, int*, const int*>(true), "");
39 static_assert(test_relationship<is_convertible, int*, void*>(true), "");
40 static_assert(test_relationship<is_convertible, int[4], int*>(true), "");
41 static_assert(test_relationship<is_convertible, float&, int>(true), "");
42 static_assert(test_relationship<is_convertible, int, const int&>(true), "");
43 static_assert(test_relationship<is_convertible, const int&, int>(true), "");
44 static_assert(test_relationship<is_convertible, float, const int&>(true), "");
45 static_assert(test_relationship<is_convertible, int(int),
46 int(*)(int)>(true), "");
47 static_assert(test_relationship<is_convertible,
48 int(&)(int), int(*)(int)>(true), "");
49 static_assert(test_relationship<is_convertible, EnumType, int>(true), "");
50 static_assert(test_relationship<is_convertible, ClassType,
51 ClassType>(true), "");
52 static_assert(test_relationship<is_convertible, DerivedType,
53 ClassType>(true), "");
54 static_assert(test_relationship<is_convertible, DerivedType*,
55 ClassType*>(true), "");
56 static_assert(test_relationship<is_convertible, DerivedType&,
57 ClassType&>(true), "");
58
59 static_assert(test_relationship<is_convertible, const int,
60 const int&>(true), "");
61
62 static_assert(test_relationship<is_convertible, void, void>(true), "");
63 static_assert(test_relationship<is_convertible, const void, void>(true), "");
64 static_assert(test_relationship<is_convertible, void,
65 volatile void>(true), "");
66 static_assert(test_relationship<is_convertible, double&,
67 ExplicitClass>(true), "");
68
69 static_assert(test_relationship<is_convertible, int(int),
70 int(&)(int)>(true), "");
71
72 // Negative tests.
73 static_assert(test_relationship<is_convertible, const int*, int*>(false), "");
74 static_assert(test_relationship<is_convertible, int*, float*>(false), "");
75 static_assert(test_relationship<is_convertible, const int[4],
76 int*>(false), "");
77 static_assert(test_relationship<is_convertible, int[4], int[4]>(false), "");
78 static_assert(test_relationship<is_convertible, const int&, int&>(false), "");
79 static_assert(test_relationship<is_convertible, float&, int&>(false), "");
80 static_assert(test_relationship<is_convertible, float,
81 volatile int&>(false), "");
82 static_assert(test_relationship<is_convertible, int(int),
83 int(int)>(false), "");
84 static_assert(test_relationship<is_convertible, int(int),
85 int(*)(void)>(false), "");
86 static_assert(test_relationship<is_convertible, int(*)(int),
87 int(&)(int)>(false), "");
88 static_assert(test_relationship<is_convertible, int, EnumType>(false), "");
89 static_assert(test_relationship<is_convertible, int, ClassType>(false), "");
90 static_assert(test_relationship<is_convertible, ClassType,
91 DerivedType>(false), "");
92 static_assert(test_relationship<is_convertible, ClassType*,
93 DerivedType*>(false), "");
94 static_assert(test_relationship<is_convertible, ClassType&,
95 DerivedType&>(false), "");
96
97 static_assert(test_relationship<is_convertible, void, int>(false), "");
98 static_assert(test_relationship<is_convertible, void, float>(false), "");
99 static_assert(test_relationship<is_convertible, void,
100 int(*)(int)>(false), "");
101
102 // C++0x
103 static_assert(test_relationship<is_convertible, int, void>(false), "");
104 static_assert(test_relationship<is_convertible, int[4], void>(false), "");
105
106 static_assert(test_relationship<is_convertible, int, int&>(false), "");
107 static_assert(test_relationship<is_convertible, float,
108 volatile float&>(false), "");
109 static_assert(test_relationship<is_convertible, const volatile int,
110 const volatile int&>(false), "");
111 static_assert(test_relationship<is_convertible, volatile int,
112 volatile int&>(false), "");
113 static_assert(test_relationship<is_convertible, int&,
114 ExplicitClass>(false), "");
115 static_assert(test_relationship<is_convertible, void*,
116 ExplicitClass>(false), "");
117 }
118