177 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: no-exceptions10 11#include <cassert>12 13struct A14{15 A() : i(0), j(0) {} // explicitly initialize 'i' to prevent warnings16 const int i;17 int j;18};19 20typedef const int A::*md1;21typedef int A::*md2;22 23struct B : public A24{25 B() : k(0), l(0) {} // explicitly initialize 'k' to prevent warnings.26 const int k;27 int l;28};29 30typedef const int B::*der1;31typedef int B::*der2;32 33void test1()34{35 try36 {37 throw &A::i;38 assert(false);39 }40 catch (md2)41 {42 assert(false);43 }44 catch (md1)45 {46 }47}48 49// Check that cv qualified conversions are allowed.50void test2()51{52 try53 {54 throw &A::j;55 }56 catch (md2)57 {58 }59 catch (...)60 {61 assert(false);62 }63 64 try65 {66 throw &A::j;67 assert(false);68 }69 catch (md1)70 {71 }72 catch (...)73 {74 assert(false);75 }76}77 78// Check that Base -> Derived conversions are NOT allowed.79void test3()80{81 try82 {83 throw &A::i;84 assert(false);85 }86 catch (md2)87 {88 assert(false);89 }90 catch (der2)91 {92 assert(false);93 }94 catch (der1)95 {96 assert(false);97 }98 catch (md1)99 {100 }101}102 103// Check that Base -> Derived conversions NOT are allowed with different cv104// qualifiers.105void test4()106{107 try108 {109 throw &A::j;110 assert(false);111 }112 catch (der2)113 {114 assert(false);115 }116 catch (der1)117 {118 assert(false);119 }120 catch (md2)121 {122 }123 catch (...)124 {125 assert(false);126 }127}128 129// Check that no Derived -> Base conversions are allowed.130void test5()131{132 try133 {134 throw &B::k;135 assert(false);136 }137 catch (md1)138 {139 assert(false);140 }141 catch (md2)142 {143 assert(false);144 }145 catch (der1)146 {147 }148 149 try150 {151 throw &B::l;152 assert(false);153 }154 catch (md1)155 {156 assert(false);157 }158 catch (md2)159 {160 assert(false);161 }162 catch (der2)163 {164 }165}166 167int main(int, char**)168{169 test1();170 test2();171 test3();172 test4();173 test5();174 175 return 0;176}177