| 1 |
// { dg-do run } |
| 2 |
extern "C" int printf(const char *,...); |
| 3 |
struct V1 { |
| 4 |
int v; |
| 5 |
virtual int foo(); |
| 6 |
V1(); |
| 7 |
~V1(); |
| 8 |
}; |
| 9 |
struct V2 : virtual V1 { |
| 10 |
int v2; |
| 11 |
virtual int foo(); |
| 12 |
V2(); |
| 13 |
~V2(); |
| 14 |
}; |
| 15 |
struct C : virtual V1, virtual V2 { |
| 16 |
int c; |
| 17 |
virtual int foo(); |
| 18 |
C(); |
| 19 |
~C(); |
| 20 |
}; |
| 21 |
|
| 22 |
struct B { |
| 23 |
int b; }; |
| 24 |
struct D : B, C { |
| 25 |
int d; |
| 26 |
virtual int bar(); |
| 27 |
D(); |
| 28 |
~D(); |
| 29 |
}; |
| 30 |
extern "C" int printf(const char *,...); |
| 31 |
int main(int argc, char**argv) |
| 32 |
{ |
| 33 |
try { |
| 34 |
D *d = new D; |
| 35 |
delete d; |
| 36 |
} catch (int) { |
| 37 |
printf("Int caught\n"); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
int V1::foo() { |
| 42 |
printf("V1::foo called\n"); return 1; } |
| 43 |
V1::V1() : v(5) { |
| 44 |
printf("V1 called\n"); } |
| 45 |
V1::~V1() { |
| 46 |
printf("~V1 called\n"); } |
| 47 |
|
| 48 |
int V2::foo() { |
| 49 |
printf("V2::foo called\n"); return 1; } |
| 50 |
V2::V2() : v2(6) { |
| 51 |
printf("V2 called\n"); } |
| 52 |
V2::~V2() { |
| 53 |
printf("~V2 called\n"); } |
| 54 |
|
| 55 |
int C::foo() { |
| 56 |
printf("C::foo called %d\n", c); return 1; } |
| 57 |
C::C() : c(7) { |
| 58 |
printf("C called\n"); |
| 59 |
V1 *vv = this; vv->foo(); |
| 60 |
C *cp = dynamic_cast<C *>(vv); |
| 61 |
if (this == cp) { |
| 62 |
printf("PASSED this == cp\n"); |
| 63 |
} else { |
| 64 |
printf("FAILED this != cp\n"); |
| 65 |
} |
| 66 |
} |
| 67 |
C::~C() { |
| 68 |
printf("~C called\n"); |
| 69 |
V1 *vv = this; vv->foo(); |
| 70 |
C *cp = dynamic_cast<C *>(vv); |
| 71 |
if (this == cp) { |
| 72 |
printf("PASSED this == cp\n"); |
| 73 |
} else { |
| 74 |
printf("FAILED this != cp\n"); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
int D::bar() { |
| 79 |
printf("D::bar called\n"); return 1; } |
| 80 |
D::D() : d(8) { |
| 81 |
printf("D called\n"); throw 5; } |
| 82 |
D::~D() { |
| 83 |
printf("~D called\n"); } |