xref: /netbsd-src/external/gpl3/gdb/dist/gdb/testsuite/gdb.cp/mb-ctor.cc (revision 4b169a6ba595ae283ca507b26b15fdff40495b1c)
1 
2 #include <stdio.h>
3 
4 class Base
5 {
6 public:
7   Base(int k);
8   ~Base();
foo()9   virtual void foo() {}
10 private:
11   int k;
12 };
13 
Base(int k)14 Base::Base(int k)
15 {
16   this->k = k;
17 }
18 
~Base()19 Base::~Base()
20 {
21     printf("~Base\n");
22 }
23 
24 class Derived : public virtual Base
25 {
26 public:
27   Derived(int i);
28   ~Derived();
29 private:
30   int i;
31   int i2;
32 };
33 
Derived(int i)34 Derived::Derived(int i) : Base(i)
35 {
36   this->i = i;
37   /* The next statement is spread over two lines on purpose to exercise
38      a bug where breakpoints set on all but the last line of a statement
39      would not get multiple breakpoints.
40      The second line's text for gdb_get_line_number is a subset of the
41      first line so that we don't care which line gdb prints when it stops.  */
42   this->i2 = // set breakpoint here
43     i; // breakpoint here
44 }
45 
~Derived()46 Derived::~Derived()
47 {
48     printf("~Derived\n");
49 }
50 
51 class DeeplyDerived : public Derived
52 {
53 public:
DeeplyDerived(int i)54   DeeplyDerived(int i) : Base(i), Derived(i) {}
55 };
56 
main()57 int main()
58 {
59   /* Invokes the Derived ctor that constructs both
60      Derived and Base.  */
61   Derived d(7);
62   /* Invokes the Derived ctor that constructs only
63      Derived. Base is constructed separately by
64      DeeplyDerived's ctor.  */
65   DeeplyDerived dd(15);
66 
67   Derived *dyn_d = new Derived (24);
68   DeeplyDerived *dyn_dd = new DeeplyDerived (42);
69 
70   delete dyn_d;
71   delete dyn_dd;
72 
73   return 0;
74 }
75