Copyright updates for 2007.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / virtfunc.cc
CommitLineData
0bbed51a
MC
1/* This test script is part of GDB, the GNU debugger.
2
3 Copyright 1993, 1994, 1997, 1998, 1999, 2003, 2004,
4 Free Software Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program 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.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
c906108c
SS
21// Pls try the following program on virtual functions and try to do print on
22// most of the code in main(). Almost none of them works !
23
24//
25// The inheritance structure is:
26//
27// V : VA VB
28// A : (V)
29// B : A
30// D : AD (V)
31// C : (V)
32// E : B (V) D C
33//
34
35class VA
36{
37public:
38 int va;
39};
40
41class VB
42{
43public:
44 int vb;
45 int fvb();
46 virtual int vvb();
47};
48
49class V : public VA, public VB
50{
51public:
52 int f();
53 virtual int vv();
54 int w;
55};
56
57class A : virtual public V
58{
59public:
60 virtual int f();
61private:
62 int a;
63};
64
65class B : public A
66{
67public:
68 int f();
69private:
70 int b;
71};
72
73class C : public virtual V
74{
75public:
76 int c;
77};
78
79class AD
80{
81public:
82 virtual int vg() = 0;
83};
84
85class D : public AD, virtual public V
86{
87public:
88 static void s();
89 virtual int vg();
90 virtual int vd();
91 int fd();
92 int d;
93};
94
95class E : public B, virtual public V, public D, public C
96{
97public:
98 int f();
99 int vg();
100 int vv();
101 int e;
102};
103
104D dd;
105D* ppd = ⅆ
106AD* pAd = ⅆ
107
108A a;
109B b;
110C c;
111D d;
112E e;
113V v;
114VB vb;
115
116
117A* pAa = &a;
118A* pAe = &e;
119
120B* pBe = &e;
121
122D* pDd = &d;
123D* pDe = &e;
124
125V* pVa = &a;
126V* pVv = &v;
127V* pVe = &e;
128V* pVd = &d;
129
130AD* pADe = &e;
131
132E* pEe = &e;
133
134VB* pVB = &vb;
135
136void init()
137{
138 a.vb = 1;
139 b.vb = 2;
140 c.vb = 3;
141 d.vb = 4;
142 e.vb = 5;
143 v.vb = 6;
144 vb.vb = 7;
145
146 d.d = 1;
147 e.d = 2;
148}
149
150extern "C" int printf(const char *, ...);
151
152int all_count = 0;
153int failed_count = 0;
154
155#define TEST(EXPR, EXPECTED) \
156 ret = EXPR; \
157 if (ret != EXPECTED) {\
158 printf("Failed %s is %d, should be %d!\n", #EXPR, ret, EXPECTED); \
159 failed_count++; } \
160 all_count++;
161
162int ret;
163
164void test_calls()
165{
166 TEST(pAe->f(), 20);
167 TEST(pAa->f(), 1);
168
169 TEST(pDe->vg(), 202);
170 TEST(pADe->vg(), 202);
171 TEST(pDd->vg(), 101);
172
173 TEST(pEe->vvb(), 411);
174
175 TEST(pVB->vvb(), 407);
176
177 TEST(pBe->vvb(), 411);
178 TEST(pDe->vvb(), 411);
179
180 TEST(pEe->vd(), 282);
181 TEST(pEe->fvb(), 311);
182
183 TEST(pEe->D::vg(), 102);
184 printf("Did %d tests, of which %d failed.\n", all_count, failed_count);
185}
186#ifdef usestubs
187extern "C" {
188 void set_debug_traps();
189 void breakpoint();
190};
191#endif
192
a0b3c4fd 193int main()
c906108c
SS
194{
195#ifdef usestubs
196 set_debug_traps();
197 breakpoint();
198#endif
199 init();
200
201 e.w = 7;
202 e.vb = 11;
203
204 test_calls();
a0b3c4fd
JM
205 return 0;
206
c906108c
SS
207}
208
209int A::f() {return 1;}
210int B::f() {return 2;}
211void D::s() {}
212int E::f() {return 20;}
213int D::vg() {return 100+d;}
214int E::vg() {return 200+d;}
215int V::f() {return 600+w;}
216int V::vv() {return 400+w;}
217int E::vv() {return 450+w;}
218int D::fd() {return 250+d;}
219int D::vd() {return 280+d;}
220int VB::fvb() {return 300+vb;}
221int VB::vvb() {return 400+vb;}
This page took 0.634975 seconds and 4 git commands to generate.