summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.mike/virt5.C
blob: cee8b3cb19809c835834500e7783227173f8eb12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// { dg-do run  }
// Ensure that virtual base upcast and downcasting works on this
// conversions during virtual function dispatch at ctor/dtor time
// when dynamic vtable fixups for deltas are needed.

int fail = 0;

struct BASE1 {
  virtual ~BASE1 () { }      
};   

class MID;

class BASE2 {
public: 
  virtual MID *VFN (){ return 0; }
};   

class MIBASE : public BASE1, public BASE2 { };   

class VBB : public MIBASE {
public:
  virtual long get_STATE () const = 0;
  void print_STATE() { if (get_STATE () != 87654321) fail = 1; }
};   

class VBD : public virtual VBB {
  long STATE;
public:
  long get_STATE() const { return STATE; }
  VBD() { STATE = 87654321; }
  ~VBD() { STATE = 87654321; }
};   

class MID : public virtual VBD {
public:
  MID () { print_STATE(); }
  ~MID () { print_STATE(); }
  virtual MID *VFN() { return this; }
};  

class LAST : public MID {
public:
  LAST () { print_STATE(); }
  ~LAST () { print_STATE(); }
};

int main() {
  MIBASE *o = new LAST;
  MID *p = o->VFN();
  p->print_STATE();
  delete o;
  return fail;
}