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