]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.cp/virtfunc.cc
* gnu-v3-abi.c (struct value_and_voffset): New.
[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
0b302171
JB
3 Copyright 1993-1994, 1997-1999, 2003-2004, 2012 Free Software
4 Foundation, Inc.
0bbed51a
MC
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
a9762ec7 8 the Free Software Foundation; either version 3 of the License, or
0bbed51a
MC
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.
a9762ec7 15
0bbed51a 16 You should have received a copy of the GNU General Public License
a9762ec7 17 along with this program. If not, see <http://www.gnu.org/licenses/>.
0bbed51a
MC
18 */
19
c906108c
SS
20// Pls try the following program on virtual functions and try to do print on
21// most of the code in main(). Almost none of them works !
22
23//
24// The inheritance structure is:
25//
26// V : VA VB
27// A : (V)
28// B : A
29// D : AD (V)
30// C : (V)
31// E : B (V) D C
32//
33
34class VA
35{
36public:
37 int va;
38};
39
40class VB
41{
42public:
43 int vb;
44 int fvb();
45 virtual int vvb();
46};
47
48class V : public VA, public VB
49{
50public:
51 int f();
52 virtual int vv();
53 int w;
54};
55
56class A : virtual public V
57{
58public:
59 virtual int f();
60private:
61 int a;
62};
63
64class B : public A
65{
66public:
67 int f();
68private:
69 int b;
70};
71
72class C : public virtual V
73{
74public:
75 int c;
76};
77
78class AD
79{
80public:
81 virtual int vg() = 0;
82};
83
84class D : public AD, virtual public V
85{
86public:
87 static void s();
88 virtual int vg();
89 virtual int vd();
90 int fd();
91 int d;
92};
93
94class E : public B, virtual public V, public D, public C
95{
96public:
97 int f();
98 int vg();
99 int vv();
100 int e;
101};
102
103D dd;
104D* ppd = &dd;
105AD* pAd = &dd;
106
107A a;
108B b;
109C c;
110D d;
111E e;
112V v;
113VB vb;
c4aeac85 114VA va;
c906108c
SS
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}
c906108c 186
a0b3c4fd 187int main()
c906108c 188{
c906108c
SS
189 init();
190
191 e.w = 7;
192 e.vb = 11;
193
194 test_calls();
a0b3c4fd
JM
195 return 0;
196
c906108c
SS
197}
198
199int A::f() {return 1;}
200int B::f() {return 2;}
201void D::s() {}
202int E::f() {return 20;}
203int D::vg() {return 100+d;}
204int E::vg() {return 200+d;}
205int V::f() {return 600+w;}
206int V::vv() {return 400+w;}
207int E::vv() {return 450+w;}
208int D::fd() {return 250+d;}
209int D::vd() {return 280+d;}
210int VB::fvb() {return 300+vb;}
211int VB::vvb() {return 400+vb;}