1 // { dg-do run { xfail sparc64-*-elf arm-*-pe } } 2 // { dg-options "-fexceptions" } 3 4 class VB { 5 public: 6 int n; 7 VB (int v) { n = v; } 8 VB (const VB& o) { 9 n = o.n; 10 // printf("copying VB from %d to %d\n", &o, this); 11 } 12 }; 13 14 class D : public virtual VB { 15 int j; 16 public: 17 D(int i1, int i2) : VB(i2) { j = i1; } 18 VB& vb() { return *(VB*)this; } 19 const VB& vb() const { return *(const VB*)this; } 20 }; 21 22 class pD : private virtual VB { 23 int j; 24 public: 25 pD(int i1, int i2) : VB(i2) { j = i1; } 26 VB& vb() { return *(VB*)this; } 27 const VB& vb() const { return *(const VB*)this; } 28 }; 29 30 31 int main () { 32 D d(1943, 4279); 33 pD pd(3621, 9527); 34 VB *vb = &d.vb(); 35 VB *pvb = &pd.vb(); 36 37 // A catch of a public virtual base. 38 try { 39 // printf("Throwing D at %d (VB at %d)\n", &d, vb); 40 throw d; 41 } 42 catch (VB& vb) { 43 // printf("Catching VB at %d\n", &vb); 44 if (vb.n != 4279) 45 return 1; 46 } 47 catch (...) { 48 return 1; 49 } 50 51 // A catch of a private virtual base. 52 try { 53 // printf("Throwing D at %d (VB at %d)\n", &pd, pvb); 54 throw pd; 55 } 56 catch (VB& vb) { 57 // printf("Catching VB at %d\n", &vb); 58 // This was a private base of the throw object, don't catch it. 59 return 1; 60 } 61 catch (...) { 62 } 63 } 64