1
2#include <stdio.h>
3
4class Base
5{
6public:
7  Base(int k);
8  ~Base();
9  virtual void foo() {}
10private:
11  int k;
12};
13
14Base::Base(int k)
15{
16  this->k = k;
17}
18
19Base::~Base()
20{
21    printf("~Base\n");
22}
23
24class Derived : public virtual Base
25{
26public:
27  Derived(int i);
28  ~Derived();
29private:
30  int i;
31  int i2;
32};
33
34Derived::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
46Derived::~Derived()
47{
48    printf("~Derived\n");
49}
50
51class DeeplyDerived : public Derived
52{
53public:
54  DeeplyDerived(int i) : Base(i), Derived(i) {}
55};
56
57int 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  return 0;
68}
69