xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.cp/derivation.cc (revision 212397c69a103ae7e5eafa8731ddfae671d2dee7)
1 /* This testcase is part of GDB, the GNU debugger.
2 
3    Copyright 2003-2015 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 extern void foo2 (); /* from derivation2.cc */
19 
20 namespace N {
21   typedef double value_type;
22   struct Base { typedef int value_type; };
23   struct Derived : public Base {
24     void doit (void) const {
25        int i = 3;
26 
27        while (i > 0)
28          --i;
29      }
30   };
31 }
32 
33 class A {
34 public:
35     typedef int value_type;
36     value_type a;
37     value_type aa;
38 
39     A()
40     {
41         a=1;
42         aa=2;
43     }
44     value_type afoo();
45     value_type foo();
46 };
47 
48 
49 
50 class B {
51 public:
52     A::value_type b;
53     A::value_type bb;
54 
55     B()
56     {
57         b=3;
58         bb=4;
59     }
60     A::value_type bfoo();
61     A::value_type foo();
62 
63 };
64 
65 
66 
67 class C {
68 public:
69     int c;
70     int cc;
71 
72     C()
73     {
74         c=5;
75         cc=6;
76     }
77     int cfoo();
78     int foo();
79 
80 };
81 
82 
83 
84 class D : private A, public B, protected C {
85 public:
86     value_type d;
87     value_type dd;
88 
89     D()
90     {
91         d =7;
92         dd=8;
93     }
94     value_type dfoo();
95     value_type foo();
96 
97 };
98 
99 
100 class E : public A, B, protected C {
101 public:
102     value_type e;
103     value_type ee;
104 
105     E()
106     {
107         e =9;
108         ee=10;
109     }
110     value_type efoo();
111     value_type foo();
112 
113 };
114 
115 
116 class F : A, public B, C {
117 public:
118     value_type f;
119     value_type ff;
120 
121     F()
122     {
123         f =11;
124         ff=12;
125     }
126     value_type ffoo();
127     value_type foo();
128 
129 };
130 
131 class G : private A, public B, protected C {
132 public:
133     int g;
134     int gg;
135     int a;
136     int b;
137     int c;
138 
139     G()
140     {
141         g =13;
142         gg =14;
143         a=15;
144         b=16;
145         c=17;
146 
147     }
148     int gfoo();
149     int foo();
150 
151 };
152 
153 class Z : public A
154 {
155 public:
156   typedef float value_type;
157   value_type z;
158 };
159 
160 class ZZ : public Z
161 {
162 public:
163   value_type zz;
164 };
165 
166 class V_base
167 {
168 public:
169   virtual void m();
170   int base;
171 };
172 
173 void
174 V_base::m()
175 {
176 }
177 
178 class V_inter : public virtual V_base
179 {
180 public:
181   virtual void f();
182   int inter;
183 };
184 
185 void
186 V_inter::f()
187 {
188 }
189 
190 class V_derived : public V_inter
191 {
192 public:
193   double x;
194 };
195 
196 V_derived vderived;
197 
198 A::value_type A::afoo() {
199     return 1;
200 }
201 
202 A::value_type B::bfoo() {
203     return 2;
204 }
205 
206 A::value_type C::cfoo() {
207     return 3;
208 }
209 
210 D::value_type D::dfoo() {
211     return 4;
212 }
213 
214 E::value_type E::efoo() {
215     return 5;
216 }
217 
218 F::value_type F::ffoo() {
219     return 6;
220 }
221 
222 int G::gfoo() {
223     return 77;
224 }
225 
226 A::value_type A::foo()
227 {
228     return 7;
229 
230 }
231 
232 A::value_type B::foo()
233 {
234     return 8;
235 
236 }
237 
238 A::value_type C::foo()
239 {
240     return 9;
241 
242 }
243 
244 D::value_type D::foo()
245 {
246     return 10;
247 
248 }
249 
250 E::value_type E::foo()
251 {
252     return 11;
253 
254 }
255 
256 F::value_type F::foo()
257 {
258     return 12;
259 
260 }
261 
262 int G::foo()
263 {
264     return 13;
265 
266 }
267 
268 
269 void marker1()
270 {
271 }
272 
273 
274 int main(void)
275 {
276 
277     A a_instance;
278     B b_instance;
279     C c_instance;
280     D d_instance;
281     E e_instance;
282     F f_instance;
283     G g_instance;
284     Z z_instance;
285     ZZ zz_instance;
286 
287     marker1(); // marker1-returns-here
288 
289     a_instance.a = 20; // marker1-returns-here
290     a_instance.aa = 21;
291     b_instance.b = 22;
292     b_instance.bb = 23;
293     c_instance.c = 24;
294     c_instance.cc = 25;
295     d_instance.d = 26;
296     d_instance.dd = 27;
297     e_instance.e = 28;
298     e_instance.ee =29;
299     f_instance.f =30;
300     f_instance.ff =31;
301     g_instance.g = 32;
302     g_instance.gg = 33;
303     z_instance.z = 34.0;
304     zz_instance.zz = 35.0;
305 
306     N::Derived dobj;
307     N::Derived::value_type d = 1;
308     N::value_type n = 3.0;
309     dobj.doit ();
310     foo2 ();
311     return 0;
312 
313 }
314