Home | History | Annotate | Download | only in jni
      1 // { dg-do run  }
      2 // { dg-options "-w" }
      3 // Copyright (C) 1999, 2000 Free Software Foundation, Inc.
      4 // Contributed by Nathan Sidwell 6 Jun 1999 <nathan (at) acm.org>
      5 
      6 // We cannot catch an ambiguous base class.
      7 // -- public, << private, == virtual
      8 
      9 // D--B--A
     10 // +--C<<A
     11 
     12 
     13 struct A { int m; virtual ~A(){}};
     14 struct B : A { int m; };
     15 struct C : private A { int m; };
     16 struct D : B, C { int m; };
     17 
     18 void fna(A *obj) { throw obj; }
     19 void fnb(B *obj) { throw obj; }
     20 void fnc(C *obj) { throw obj; }
     21 void fnd(D *obj) { throw obj; }
     22 
     23 extern "C" void abort();
     24 
     25 void check(D *d)
     26 {
     27   int caught;
     28 
     29   // try with whole object
     30   caught = 0;
     31   try { fnd(d); }
     32   catch(A *p) { abort(); } // A is ambiguous
     33   catch(D *p) { caught = 1; if (p != d) abort();}
     34   catch(...) { abort(); }
     35   if (!caught) abort();
     36 
     37   caught = 0;
     38   try { fnd(d); }
     39   catch(A *p) { abort(); } // A is ambiguous
     40   catch(B *p) { caught = 1; if (p != d) abort();}
     41   catch(...) { abort(); }
     42   if (!caught) abort();
     43 
     44   caught = 0;
     45   try { fnd(d); }
     46   catch(A *p) { abort(); } // A is ambiguous
     47   catch(C *p) { caught = 1; if (p != d) abort();}
     48   catch(...) { abort(); }
     49   if (!caught) abort();
     50 
     51   // try with an A object
     52   caught = 0;
     53   try { fna((B *)d); }
     54   catch(B *p) { abort(); } // throw type is static type
     55   catch(A *p) { caught = 1; if (p != (B *)d) abort();}
     56   catch(...) { abort(); }
     57   if (!caught) abort();
     58 
     59   caught = 0;
     60   try { fna((A *)(C *)d); }
     61   catch(C *p) { abort(); } // throw type is static type
     62   catch(A *p) { caught = 1; if (p != (A *)(C *)d) abort();}
     63   catch(...) { abort(); }
     64   if (!caught) abort();
     65 
     66   // try with B object
     67   caught = 0;
     68   try { fnb((B *)d); }
     69   catch(A *p) { caught = 1; if (p != (B *)d) abort();}
     70   catch(...) { abort(); }
     71   if (!caught) abort();
     72 
     73   caught = 0;
     74   try { fnb((B *)d); }
     75   catch(B *p) { caught = 1; if (p != d) abort();}
     76   catch(...) { abort(); }
     77   if (!caught) abort();
     78 
     79   caught = 0;
     80   try { fnb((B *)d); }
     81   catch(C *p) { abort(); }
     82   catch(D *p) { abort(); }
     83   catch(...) { caught =1; }
     84   if (!caught) abort();
     85 
     86   // try with C object
     87   caught = 0;
     88   try { fnc((C *)d); }
     89   catch(A *p) { abort();}
     90   catch(C *p) { caught = 1; if (p != d) abort();}
     91   catch(...) { abort(); }
     92   if (!caught) abort();
     93 
     94   caught = 0;
     95   try { fnc((C *)d); }
     96   catch(B *p) { abort(); }
     97   catch(D *p) { abort(); }
     98   catch(...) { caught =1; }
     99   if (!caught) abort();
    100 
    101   return;
    102 }
    103 
    104 int main ()
    105 {
    106   D d;
    107   check (&d); // try with an object
    108   check ((D *)0); // try with no object
    109 
    110   return 0;
    111 }
    112