3 // Test for Container using non-standard pointer types.
6 // Free Software Foundation, Inc.
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 2, or (at your option)
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.
19 // You should have received a copy of the GNU General Public License along
20 // with this library; see the file COPYING. If not, write to the Free
21 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24 // As a special exception, you may use this file as part of a free software
25 // library without restriction. Specifically, if other files instantiate
26 // templates or use macros or inline functions from this file, or you compile
27 // this file and link it with other files to produce an executable, this
28 // file does not by itself cause the resulting executable to be covered by
29 // the GNU General Public License. This exception does not however
30 // invalidate any other reasons why the executable file might be covered by
31 // the GNU General Public License.
36 #include <testsuite_hooks.h>
37 #include <ext/pointer.h>
39 using __gnu_cxx::_Pointer_adapter
;
40 using __gnu_cxx::_Relative_pointer_impl
;
41 using __gnu_cxx::__static_pointer_cast
;
42 using __gnu_cxx::__const_pointer_cast
;
51 typedef _Pointer_adapter
<_Relative_pointer_impl
<B
> > B_pointer
;
52 typedef _Pointer_adapter
<_Relative_pointer_impl
<const B
> > const_B_pointer
;
53 typedef _Pointer_adapter
<_Relative_pointer_impl
<A
> > A_pointer
;
54 typedef _Pointer_adapter
<_Relative_pointer_impl
<const A
> > const_A_pointer
;
58 bool test
__attribute__((unused
)) = true;
65 // Can't implicitly cast from A* to B*
66 B_pointer
bptr1(aptr
); // { dg-error "instantiated from here" 31 }
67 B_pointer
bptr2(&a
); // { dg-error "instantiated from here" 32 }
69 // but explicit cast/conversion is OK.
70 B_pointer
bptr3(__static_pointer_cast
<B_pointer
>(aptr
)); // ok
71 B_pointer
bptr4(__static_pointer_cast
<B_pointer
>(&a
)); // ok
73 // Can't implicitly cast from A* to B*
74 bptr1
= aptr
; // { dg-error "instantiated from here" 39 }
75 bptr1
= &a
; // { dg-error "instantiated from here" 40 }
77 // but explicit cast/conversion is OK.
78 bptr1
= __static_pointer_cast
<B_pointer
>(aptr
); // ok
79 bptr1
= __static_pointer_cast
<B_pointer
>(&a
); // ok
81 // Similarly, can't shed constness via implicit cast
82 const_A_pointer
captr(&a
);
83 A_pointer
aptr2(captr
); // { dg-error "instantiated from here" 48 }
85 // but explicit cast/conversion is OK.
86 A_pointer
aptr3(__const_pointer_cast
<A_pointer
>(captr
)); // ok
88 // Similarly, can't shed constness via implicit cast
89 aptr2
= captr
; // { dg-error "instantiated from here" 54 }
91 // but explicit cast/conversion is OK.
92 aptr3
= __const_pointer_cast
<A_pointer
>(captr
); // ok
94 // Combine explicit const cast with implicit downcast.
95 const_B_pointer
cbptr(&b
);
96 A_pointer
aptr4(cbptr
); // { dg-error "instantiated from here" 61 }
97 aptr4
= cbptr
; // { dg-error "instantiated from here" 62 }
99 A_pointer
aptr5(__const_pointer_cast
<B_pointer
>(cbptr
)); // ok
100 aptr5
= __const_pointer_cast
<B_pointer
>(cbptr
); // ok
103 // { dg-error "invalid conversion " "" { target *-*-* } 299 }
104 // { dg-error "initializing argument 1 of" "" { target *-*-* } 299 }
105 // { dg-error "invalid conversion " "" { target *-*-* } 305 }
106 // { dg-error "initializing argument 1 of" "" { target *-*-* } 305 }
107 // { dg-error "invalid conversion " "" { target *-*-* } 322 }
108 // { dg-error "initializing argument 1 of" "" { target *-*-* } 322 }
109 // { dg-error "invalid conversion " "" { target *-*-* } 330 }
110 // { dg-error "initializing argument 1 of" "" { target *-*-* } 330 }
111 // { dg-excess-errors "In constructor" }