1 // Test for Container using non-standard pointer types.
3 // Copyright (C) 2008-2015 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
22 #include <testsuite_hooks.h>
24 #include <ext/pointer.h>
26 using __gnu_cxx::_Pointer_adapter
;
27 using __gnu_cxx::_Relative_pointer_impl
;
28 using __gnu_cxx::__static_pointer_cast
;
29 using __gnu_cxx::__const_pointer_cast
;
34 bool test
__attribute__((unused
)) = true;
36 typedef _Pointer_adapter
<_Relative_pointer_impl
<int> > pointer
;
37 typedef _Pointer_adapter
<_Relative_pointer_impl
<const int> > const_pointer
;
39 int A
[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
41 // basic pointer assignment/access tests.
44 VERIFY(std::equal(x
, x
+10, A
));
82 typedef _Pointer_adapter
<_Relative_pointer_impl
<B
> > B_pointer
;
83 typedef _Pointer_adapter
<_Relative_pointer_impl
<A
> > A_pointer
;
84 typedef _Pointer_adapter
<_Relative_pointer_impl
<const A
> > const_A_pointer
;
85 typedef _Pointer_adapter
<_Relative_pointer_impl
<const B
> > const_B_pointer
;
88 // Test implicit conversion from B* to A*
89 void inc(_Pointer_adapter
<_Relative_pointer_impl
<A
> > a
) {
92 // Test implicit conversion from B* to const B*
93 void inc2(_Pointer_adapter
<_Relative_pointer_impl
<const B
> > b
) {
97 // Test implicit conversion from B* to const A*
98 void inc3(_Pointer_adapter
<_Relative_pointer_impl
<const A
> > a
) {
103 bool test
__attribute__((unused
)) = true;
110 VERIFY(Bptr
->i
== 2);
114 const_B_pointer
cBptr(&b
);
116 VERIFY(cBptr
->i
== 4);
120 VERIFY(Aptr
->i
== 5);
124 const_A_pointer
cAptr(&b
);
126 VERIFY(cAptr
->i
== 7);
128 const_B_pointer
cBptr2(Bptr
);
130 VERIFY(cBptr2
->i
== 8);
132 A_pointer
Aptr2(Bptr
);
134 VERIFY(Aptr2
->i
== 9);
138 const_A_pointer
cAptr2(Bptr
);
140 VERIFY(cAptr2
->i
== 11);
142 // Implicit casting during invocation
144 VERIFY(Bptr
->i
== 12);
146 VERIFY(Bptr
->i
== 13);
147 VERIFY(Bptr
->j
== 3);
149 VERIFY(Bptr
->i
== 14);
153 bool test
__attribute__((unused
)) = true;
157 A
* aPtr
__attribute__((unused
)) = __static_pointer_cast
<A
*>(bPtr
);
158 const A
*caPtr
__attribute__((unused
)) = __static_pointer_cast
<const A
*>(bPtr
);
159 const B
*cbPtr
__attribute__((unused
)) = __static_pointer_cast
<const B
*>(bPtr
);
161 B_pointer Bptr2
= &b
;
163 const A
* caPtr2
__attribute__((unused
)) = __static_pointer_cast
<const A
*>(Bptr2
);
164 A
* aPtr2
__attribute__((unused
)) = __static_pointer_cast
<A
*>(Bptr2
);
165 const B
* cbPtr2
__attribute__((unused
)) = __const_pointer_cast
<const B
*>(Bptr2
);
167 const_A_pointer caPtr3
__attribute__((unused
)) = __static_pointer_cast
<const A
*>(Bptr2
);
168 A_pointer aPtr3
__attribute__((unused
)) = __static_pointer_cast
<A
*>(Bptr2
);
169 const_B_pointer cbPtr3
__attribute__((unused
)) = __const_pointer_cast
<const B
*>(Bptr2
);
172 // Confirm the usability of the __static_pointer_cast<> template function
173 // to transform between _Pointer_adapter and standard versions.
175 bool test
__attribute__((unused
)) = true;
180 A_pointer aPtr
= __static_pointer_cast
<A_pointer
>(bPtr
);
181 VERIFY(aPtr
== bPtr
);
182 B_pointer bPtr2
= __static_pointer_cast
<B_pointer
>(aPtr
);
183 VERIFY(bPtr2
== aPtr
);
185 A
* aPtr3
= __static_pointer_cast
<A
*>(bPtr
);
186 VERIFY(aPtr3
== bPtr
);
187 B
* bPtr3
= __static_pointer_cast
<B
*>(aPtr
);
188 VERIFY(bPtr3
== aPtr
);