]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/virtfunc.cc
10c6034ac34fea4712841c9deea8c6780c354abd
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / virtfunc.cc
1 /* This test script is part of GDB, the GNU debugger.
2
3 Copyright 1993-2017 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 // 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
32 class VA
33 {
34 public:
35 int va;
36 };
37
38 class VB
39 {
40 public:
41 int vb;
42 int fvb();
43 virtual int vvb();
44 };
45
46 class V : public VA, public VB
47 {
48 public:
49 int f();
50 virtual int vv();
51 int w;
52 };
53
54 class A : virtual public V
55 {
56 public:
57 virtual int f();
58 private:
59 int a;
60 };
61
62 class B : public A
63 {
64 public:
65 int f();
66 private:
67 int b;
68 };
69
70 class C : public virtual V
71 {
72 public:
73 int c;
74 };
75
76 class AD
77 {
78 public:
79 virtual int vg() = 0;
80 };
81
82 class D : public AD, virtual public V
83 {
84 public:
85 static void s();
86 virtual int vg();
87 virtual int vd();
88 int fd();
89 int d;
90 };
91
92 class E : public B, virtual public V, public D, public C
93 {
94 public:
95 int f();
96 int vg();
97 int vv();
98 int e;
99 };
100
101 D dd;
102 D* ppd = &dd;
103 AD* pAd = &dd;
104
105 A a;
106 B b;
107 C c;
108 D d;
109 E e;
110 V v;
111 VB vb;
112 VA va;
113
114
115 A* pAa = &a;
116 A* pAe = &e;
117
118 B* pBe = &e;
119
120 D* pDd = &d;
121 D* pDe = &e;
122
123 V* pVa = &a;
124 V* pVv = &v;
125 V* pVe = &e;
126 V* pVd = &d;
127
128 AD* pADe = &e;
129
130 E* pEe = &e;
131
132 VB* pVB = &vb;
133
134 void 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
148 extern "C" int printf(const char *, ...);
149
150 int all_count = 0;
151 int 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
160 int ret;
161
162 void 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 }
184
185 int main()
186 {
187 init();
188
189 e.w = 7;
190 e.vb = 11;
191
192 test_calls();
193 return 0;
194
195 }
196
197 int A::f() {return 1;}
198 int B::f() {return 2;}
199 void D::s() {}
200 int E::f() {return 20;}
201 int D::vg() {return 100+d;}
202 int E::vg() {return 200+d;}
203 int V::f() {return 600+w;}
204 int V::vv() {return 400+w;}
205 int E::vv() {return 450+w;}
206 int D::fd() {return 250+d;}
207 int D::vd() {return 280+d;}
208 int VB::fvb() {return 300+vb;}
209 int VB::vvb() {return 400+vb;}