]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/smartp.cc
Update copyright year range in all GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / smartp.cc
1 /* This test script is part of GDB, the GNU debugger.
2
3 Copyright 1999-2019 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18 class Type1{
19 public:
20 int foo(){
21 return 11;
22 }
23 };
24
25 class Type2{
26 public:
27 int foo(){
28 return 22;
29 }
30 };
31
32 class Type3{
33 public:
34 int foo(int){
35 return 33;
36 }
37 int foo(char){
38 return 44;
39 }
40 };
41
42 class Type4 {
43 public:
44 int a;
45 int b;
46 };
47
48 int foo (Type3, float)
49 {
50 return 55;
51 }
52
53 class MyPointer{
54 Type1 *p;
55 public:
56 MyPointer(Type1 *pointer){
57 p = pointer;
58 }
59
60 Type1 *operator->(){
61 return p;
62 }
63 };
64
65 template <typename T> class SmartPointer{
66 T *p;
67 public:
68 SmartPointer(T *pointer){
69 p = pointer;
70 }
71
72 T *operator->(){
73 return p;
74 }
75 };
76
77
78 class A {
79 public:
80 int inta;
81 int foo() { return 66; }
82 };
83
84 class B {
85 public:
86 A a;
87 A* operator->(){
88 return &a;
89 }
90 };
91
92 class C {
93 public:
94 B b;
95 B& operator->(){
96 return b;
97 }
98 };
99
100 class C2 {
101 public:
102 B b;
103 B operator->(){
104 return b;
105 }
106 };
107
108 int main(){
109 Type1 mt1;
110 Type2 mt2;
111 Type3 mt3;
112
113 Type4 mt4;
114 mt4.a = 11;
115 mt4.b = 12;
116
117 MyPointer mp(&mt1);
118 Type1 *mtp = &mt1;
119
120 SmartPointer<Type1> sp1(&mt1);
121 SmartPointer<Type2> sp2(&mt2);
122 SmartPointer<Type3> sp3(&mt3);
123 SmartPointer<Type4> sp4(&mt4);
124
125 mp->foo();
126 mtp->foo();
127
128 sp1->foo();
129 sp2->foo();
130
131 sp3->foo(1);
132 sp3->foo('a');
133
134 sp4->a;
135 sp4->b;
136
137 Type4 *mt4p = &mt4;
138 mt4p->a;
139 mt4p->b;
140
141 A a;
142 B b;
143 C c;
144 C2 c2;
145
146 a.inta = 77;
147 b.a = a;
148 c.b = b;
149 c2.b = b;
150
151 a.foo();
152 b->foo();
153 c->foo();
154
155 b->inta = 77;
156 c->inta = 77;
157 c2->inta = 77;
158
159 return 0; // end of main
160 }
161