Automatic date update in version.in
[binutils-gdb.git] / gdb / testsuite / gdb.cp / virtfunc.cc
blob6c894c5ec60a8d8386afe2ce4b532245a1720b56
1 /* This test script is part of GDB, the GNU debugger.
3 Copyright 1993-2024 Free Software Foundation, Inc.
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.
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.
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/>. */
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 !
22 // The inheritance structure is:
24 // V : VA VB
25 // A : (V)
26 // B : A
27 // D : AD (V)
28 // C : (V)
29 // E : B (V) D C
32 class VA
34 public:
35 int va;
38 class VB
40 public:
41 int vb;
42 int fvb();
43 virtual int vvb();
46 class V : public VA, public VB
48 public:
49 int f();
50 virtual int vv();
51 int w;
54 class A : virtual public V
56 public:
57 virtual int f();
58 private:
59 int a;
62 class B : public A
64 public:
65 int f();
66 private:
67 int b;
70 class C : public virtual V
72 public:
73 int c;
76 class AD
78 public:
79 virtual int vg() = 0;
82 class D : public AD, virtual public V
84 public:
85 static void s();
86 virtual int vg();
87 virtual int vd();
88 int fd();
89 int d;
92 class E : public B, virtual public V, public D, public C
94 public:
95 int f();
96 int vg();
97 int vv();
98 int e;
101 D dd;
102 D* ppd = &dd;
103 AD* pAd = &dd;
105 A a;
106 B b;
107 C c;
108 D d;
109 E e;
110 V v;
111 VB vb;
112 VA va;
115 A* pAa = &a;
116 A* pAe = &e;
118 B* pBe = &e;
120 D* pDd = &d;
121 D* pDe = &e;
123 V* pVa = &a;
124 V* pVv = &v;
125 V* pVe = &e;
126 V* pVd = &d;
128 AD* pADe = &e;
130 E* pEe = &e;
132 VB* pVB = &vb;
134 void init()
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;
144 d.d = 1;
145 e.d = 2;
148 extern "C" int printf(const char *, ...);
150 int all_count = 0;
151 int failed_count = 0;
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++;
160 int ret;
162 void test_calls()
164 TEST(pAe->f(), 20);
165 TEST(pAa->f(), 1);
167 TEST(pDe->vg(), 202);
168 TEST(pADe->vg(), 202);
169 TEST(pDd->vg(), 101);
171 TEST(pEe->vvb(), 411);
173 TEST(pVB->vvb(), 407);
175 TEST(pBe->vvb(), 411);
176 TEST(pDe->vvb(), 411);
178 TEST(pEe->vd(), 282);
179 TEST(pEe->fvb(), 311);
181 TEST(pEe->D::vg(), 102);
182 printf("Did %d tests, of which %d failed.\n", all_count, failed_count);
185 int main()
187 init();
189 e.w = 7;
190 e.vb = 11;
192 test_calls();
193 return 0;
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;}