1 // { dg-options "-std=gnu++11" }
2 // { dg-do compile }
3 
4 // 2009-10-29  Paolo Carlini  <paolo.carlini@oracle.com>
5 //
6 // Copyright (C) 2009-2016 Free Software Foundation, Inc.
7 //
8 // This file is part of the GNU ISO C++ Library.  This library is free
9 // software; you can redistribute it and/or modify it under the
10 // terms of the GNU General Public License as published by the
11 // Free Software Foundation; either version 3, or (at your option)
12 // any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License along
20 // with this library; see the file COPYING3.  If not see
21 // <http://www.gnu.org/licenses/>.
22 
23 #include <type_traits>
24 #include <testsuite_tr1.h>
25 
test01()26 void test01()
27 {
28   using std::is_convertible;
29   using namespace __gnu_test;
30 
31   // Positive tests.
32   static_assert(test_relationship<is_convertible, int, int>(true), "");
33   static_assert(test_relationship<is_convertible, int, const int>(true), "");
34   static_assert(test_relationship<is_convertible,
35 		volatile int, const int>(true), "");
36   static_assert(test_relationship<is_convertible, int, float>(true), "");
37   static_assert(test_relationship<is_convertible, double, float>(true), "");
38   static_assert(test_relationship<is_convertible, float, int>(true), "");
39   static_assert(test_relationship<is_convertible, int*, const int*>(true), "");
40   static_assert(test_relationship<is_convertible, int*, void*>(true), "");
41   static_assert(test_relationship<is_convertible, int[4], int*>(true), "");
42   static_assert(test_relationship<is_convertible, float&, int>(true), "");
43   static_assert(test_relationship<is_convertible, int, const int&>(true), "");
44   static_assert(test_relationship<is_convertible, const int&, int>(true), "");
45   static_assert(test_relationship<is_convertible, float, const int&>(true), "");
46   static_assert(test_relationship<is_convertible, int(int),
47 		int(*)(int)>(true), "");
48   static_assert(test_relationship<is_convertible,
49 		int(&)(int), int(*)(int)>(true), "");
50   static_assert(test_relationship<is_convertible, EnumType, int>(true), "");
51   static_assert(test_relationship<is_convertible, ClassType,
52 		ClassType>(true), "");
53   static_assert(test_relationship<is_convertible, DerivedType,
54 		ClassType>(true), "");
55   static_assert(test_relationship<is_convertible, DerivedType*,
56 		ClassType*>(true), "");
57   static_assert(test_relationship<is_convertible, DerivedType&,
58 		ClassType&>(true), "");
59 
60   static_assert(test_relationship<is_convertible, const int,
61 		const int&>(true), "");
62 
63   static_assert(test_relationship<is_convertible, void, void>(true), "");
64   static_assert(test_relationship<is_convertible, const void, void>(true), "");
65   static_assert(test_relationship<is_convertible, void,
66 		volatile void>(true), "");
67   static_assert(test_relationship<is_convertible, double&,
68 		ExplicitClass>(true), "");
69 
70   static_assert(test_relationship<is_convertible, int(int),
71 		int(&)(int)>(true), "");
72 
73   // Negative tests.
74   static_assert(test_relationship<is_convertible, const int*, int*>(false), "");
75   static_assert(test_relationship<is_convertible, int*, float*>(false), "");
76   static_assert(test_relationship<is_convertible, const int[4],
77 		int*>(false), "");
78   static_assert(test_relationship<is_convertible, int[4], int[4]>(false), "");
79   static_assert(test_relationship<is_convertible, const int&, int&>(false), "");
80   static_assert(test_relationship<is_convertible, float&, int&>(false), "");
81   static_assert(test_relationship<is_convertible, float,
82 		volatile int&>(false), "");
83   static_assert(test_relationship<is_convertible, int(int),
84 		int(int)>(false), "");
85   static_assert(test_relationship<is_convertible, int(int),
86 		int(*)(void)>(false), "");
87   static_assert(test_relationship<is_convertible, int(*)(int),
88 		int(&)(int)>(false), "");
89   static_assert(test_relationship<is_convertible, int, EnumType>(false), "");
90   static_assert(test_relationship<is_convertible, int, ClassType>(false), "");
91   static_assert(test_relationship<is_convertible, ClassType,
92 		DerivedType>(false), "");
93   static_assert(test_relationship<is_convertible, ClassType*,
94 		DerivedType*>(false), "");
95   static_assert(test_relationship<is_convertible, ClassType&,
96 		DerivedType&>(false), "");
97 
98   static_assert(test_relationship<is_convertible, void, int>(false), "");
99   static_assert(test_relationship<is_convertible, void, float>(false), "");
100   static_assert(test_relationship<is_convertible, void,
101 		int(*)(int)>(false), "");
102 
103   // C++0x
104   static_assert(test_relationship<is_convertible, int, void>(false), "");
105   static_assert(test_relationship<is_convertible, int[4], void>(false), "");
106 
107   static_assert(test_relationship<is_convertible, int, int&>(false), "");
108   static_assert(test_relationship<is_convertible, float,
109 		volatile float&>(false), "");
110   static_assert(test_relationship<is_convertible, const volatile int,
111 		const volatile int&>(false), "");
112   static_assert(test_relationship<is_convertible, volatile int,
113 		volatile int&>(false), "");
114   static_assert(test_relationship<is_convertible, int&,
115 		ExplicitClass>(false), "");
116   static_assert(test_relationship<is_convertible, void*,
117 		ExplicitClass>(false), "");
118 }
119