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