summaryrefslogtreecommitdiffstats
path: root/libvtv/testsuite/libvtv.cc/const_vtable.cc
blob: 3229f00830824527ba4763206a0e6edffeec81f4 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// { dg-do run }
extern "C" int printf(const char *,...); 
struct V1 {
  int v; 
  virtual int foo(); 
  V1(); 
  ~V1(); 
}; 
struct V2 : virtual V1 {
  int v2; 
  virtual int foo(); 
  V2(); 
  ~V2(); 
}; 
struct C : virtual V1, virtual V2 {
  int c; 
  virtual int foo(); 
  C(); 
  ~C(); 
}; 

struct B {
  int b; }; 
struct D : B, C {
  int d; 
  virtual int bar(); 
  D(); 
  ~D(); 
}; 
extern "C" int printf(const char *,...); 
main() 
{
  try {
    D *d = new D; 
    delete d; 
  } catch (int) {
    printf("Int caught\n"); 
  } 
} 

int V1::foo() {
  printf("V1::foo called\n"); return 1; } 
V1::V1() : v(5) {
  printf("V1 called\n"); } 
V1::~V1() {
  printf("~V1 called\n"); } 

int V2::foo() {
  printf("V2::foo called\n"); return 1; } 
V2::V2() : v2(6) {
  printf("V2 called\n"); } 
V2::~V2() {
  printf("~V2 called\n"); } 

int C::foo() {
  printf("C::foo called %d\n", c); return 1; } 
C::C() : c(7) {
  printf("C called\n"); 
  V1 *vv = this; vv->foo(); 
  C *cp = dynamic_cast<C *>(vv); 
  if (this == cp) {
    printf("PASSED this == cp\n"); 
  } else {
    printf("FAILED this != cp\n"); 
  } 
} 
C::~C() {
  printf("~C called\n"); 
  V1 *vv = this; vv->foo(); 
  C *cp = dynamic_cast<C *>(vv); 
  if (this == cp) {
    printf("PASSED this == cp\n"); 
  } else {
    printf("FAILED this != cp\n"); 
  } 
} 

int D::bar() {
  printf("D::bar called\n"); return 1; } 
D::D() : d(8) {
  printf("D called\n"); throw 5; } 
D::~D() {
  printf("~D called\n"); } 
OpenPOWER on IntegriCloud