1 /* This test script is part of GDB, the GNU debugger.
3 Copyright 1993-2019 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:
46 class V
: public VA
, public VB
54 class A
: virtual public V
70 class C
: public virtual V
82 class D
: public AD
, virtual public V
92 class E
: public B
, virtual public V
, public D
, public C
148 extern "C" int printf(const char *, ...);
151 int failed_count
= 0;
153 #define TEST(EXPR, EXPECTED) \
155 if (ret != EXPECTED) {\
156 printf("Failed %s is %d, should be %d!\n", #EXPR, ret, EXPECTED); \
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
);
197 int A::f() {return 1;}
198 int B::f() {return 2;}
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
;}