Home | History | Annotate | Download | only in test
      1 //===----------------- catch_member_data_pointer_01.cpp -------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #include <cassert>
     11 
     12 struct A
     13 {
     14     const int i;
     15     int j;
     16 };
     17 
     18 typedef const int A::*md1;
     19 typedef       int A::*md2;
     20 
     21 struct B : public A
     22 {
     23     const int k;
     24     int l;
     25 };
     26 
     27 typedef const int B::*der1;
     28 typedef       int B::*der2;
     29 
     30 void test1()
     31 {
     32     try
     33     {
     34         throw &A::i;
     35         assert(false);
     36     }
     37     catch (md2)
     38     {
     39         assert(false);
     40     }
     41     catch (md1)
     42     {
     43     }
     44 }
     45 
     46 // Check that cv qualified conversions are allowed.
     47 void test2()
     48 {
     49     try
     50     {
     51         throw &A::j;
     52     }
     53     catch (md2)
     54     {
     55     }
     56     catch (...)
     57     {
     58         assert(false);
     59     }
     60 
     61     try
     62     {
     63         throw &A::j;
     64         assert(false);
     65     }
     66     catch (md1)
     67     {
     68     }
     69     catch (...)
     70     {
     71         assert(false);
     72     }
     73 }
     74 
     75 // Check that Base -> Derived conversions are NOT allowed.
     76 void test3()
     77 {
     78     try
     79     {
     80         throw &A::i;
     81         assert(false);
     82     }
     83     catch (md2)
     84     {
     85         assert(false);
     86     }
     87     catch (der2)
     88     {
     89         assert(false);
     90     }
     91     catch (der1)
     92     {
     93         assert(false);
     94     }
     95     catch (md1)
     96     {
     97     }
     98 }
     99 
    100 // Check that Base -> Derived conversions NOT are allowed with different cv
    101 // qualifiers.
    102 void test4()
    103 {
    104     try
    105     {
    106         throw &A::j;
    107         assert(false);
    108     }
    109     catch (der2)
    110     {
    111         assert(false);
    112     }
    113     catch (der1)
    114     {
    115         assert(false);
    116     }
    117     catch (md2)
    118     {
    119     }
    120     catch (...)
    121     {
    122         assert(false);
    123     }
    124 }
    125 
    126 // Check that no Derived -> Base conversions are allowed.
    127 void test5()
    128 {
    129     try
    130     {
    131         throw &B::k;
    132         assert(false);
    133     }
    134     catch (md1)
    135     {
    136         assert(false);
    137     }
    138     catch (md2)
    139     {
    140         assert(false);
    141     }
    142     catch (der1)
    143     {
    144     }
    145 
    146     try
    147     {
    148         throw &B::l;
    149         assert(false);
    150     }
    151     catch (md1)
    152     {
    153         assert(false);
    154     }
    155     catch (md2)
    156     {
    157         assert(false);
    158     }
    159     catch (der2)
    160     {
    161     }
    162 }
    163 
    164 int main()
    165 {
    166     test1();
    167     test2();
    168     test3();
    169     test4();
    170     test5();
    171 }
    172