]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/ext/ext_pointer/1_neg.cc
* decl2.c (mark_used): Adjust error for use of deleted function.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / ext / ext_pointer / 1_neg.cc
CommitLineData
b74318f1
BW
1// Bob Walters 10-2008
2
3// Test for Container using non-standard pointer types.
4
748086b7 5// Copyright (C) 2008, 2009
b74318f1
BW
6// 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
748086b7 11// Free Software Foundation; either version 3, or (at your option)
b74318f1
BW
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
748086b7
JJ
20// with this library; see the file COPYING3. If not see
21// <http://www.gnu.org/licenses/>.
22
b74318f1
BW
23
24// { dg-do compile }
25
26#include <algorithm>
27#include <testsuite_hooks.h>
28#include <ext/pointer.h>
29
30using __gnu_cxx::_Pointer_adapter;
31using __gnu_cxx::_Relative_pointer_impl;
32using __gnu_cxx::__static_pointer_cast;
33using __gnu_cxx::__const_pointer_cast;
34
35
36struct A {
37 int i;
38};
39struct B : public A{
40 int j;
41};
42typedef _Pointer_adapter<_Relative_pointer_impl<B> > B_pointer;
43typedef _Pointer_adapter<_Relative_pointer_impl<const B> > const_B_pointer;
44typedef _Pointer_adapter<_Relative_pointer_impl<A> > A_pointer;
45typedef _Pointer_adapter<_Relative_pointer_impl<const A> > const_A_pointer;
46
47
48void test01(void) {
49 bool test __attribute__((unused)) = true;
50
51 A a;
52 B b;
53
54 A_pointer aptr( &a );
55
56 // Can't implicitly cast from A* to B*
57 B_pointer bptr1(aptr); // { dg-error "instantiated from here" 31 }
58 B_pointer bptr2(&a); // { dg-error "instantiated from here" 32 }
59
60 // but explicit cast/conversion is OK.
61 B_pointer bptr3(__static_pointer_cast<B_pointer>(aptr)); // ok
62 B_pointer bptr4(__static_pointer_cast<B_pointer>(&a)); // ok
63
64 // Can't implicitly cast from A* to B*
65 bptr1 = aptr; // { dg-error "instantiated from here" 39 }
66 bptr1 = &a; // { dg-error "instantiated from here" 40 }
67
68 // but explicit cast/conversion is OK.
69 bptr1 = __static_pointer_cast<B_pointer>(aptr); // ok
70 bptr1 = __static_pointer_cast<B_pointer>(&a); // ok
71
72 // Similarly, can't shed constness via implicit cast
73 const_A_pointer captr(&a);
74 A_pointer aptr2(captr); // { dg-error "instantiated from here" 48 }
75
76 // but explicit cast/conversion is OK.
77 A_pointer aptr3(__const_pointer_cast<A_pointer>(captr)); // ok
78
79 // Similarly, can't shed constness via implicit cast
80 aptr2 = captr; // { dg-error "instantiated from here" 54 }
81
82 // but explicit cast/conversion is OK.
83 aptr3 = __const_pointer_cast<A_pointer>(captr); // ok
84
85 // Combine explicit const cast with implicit downcast.
86 const_B_pointer cbptr(&b);
87 A_pointer aptr4(cbptr); // { dg-error "instantiated from here" 61 }
88 aptr4 = cbptr; // { dg-error "instantiated from here" 62 }
89
90 A_pointer aptr5(__const_pointer_cast<B_pointer>(cbptr)); // ok
91 aptr5 = __const_pointer_cast<B_pointer>(cbptr); // ok
92}
93
9a71b305 94// { dg-prune-output "include" }