1 //===--------------------- catch_const_pointer_nullptr.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 #if __has_feature(cxx_nullptr) 13 14 struct A {}; 15 16 void test1() 17 { 18 try 19 { 20 throw nullptr; 21 assert(false); 22 } 23 catch (A*) 24 { 25 } 26 catch (const A*) 27 { 28 assert(false); 29 } 30 } 31 32 33 void test2() 34 { 35 try 36 { 37 throw nullptr; 38 assert(false); 39 } 40 catch (const A*) 41 { 42 } 43 catch (A*) 44 { 45 assert(false); 46 } 47 } 48 49 void test3() 50 { 51 try 52 { 53 throw nullptr; 54 assert(false); 55 } 56 catch (const A* const) 57 { 58 } 59 catch (A*) 60 { 61 assert(false); 62 } 63 } 64 65 void test4() 66 { 67 try 68 { 69 throw nullptr; 70 assert(false); 71 } 72 catch (A*) 73 { 74 } 75 catch (const A* const) 76 { 77 assert(false); 78 } 79 } 80 81 void test5() 82 { 83 try 84 { 85 throw nullptr; 86 assert(false); 87 } 88 catch (A const*) 89 { 90 } 91 catch (A*) 92 { 93 assert(false); 94 } 95 } 96 97 void test6() 98 { 99 try 100 { 101 throw nullptr; 102 assert(false); 103 } 104 catch (A*) 105 { 106 } 107 catch (A const*) 108 { 109 assert(false); 110 } 111 } 112 113 114 #else 115 116 void test1() {} 117 void test2() {} 118 void test3() {} 119 void test4() {} 120 void test5() {} 121 void test6() {} 122 123 #endif 124 125 int main() 126 { 127 test1(); 128 test2(); 129 test3(); 130 test4(); 131 test5(); 132 test6(); 133 } 134