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 // UNSUPPORTED: libcxxabi-no-exceptions 11 12 #include <cassert> 13 14 // Clang emits warnings about exceptions of type 'Child' being caught by 15 // an earlier handler of type 'Base'. Congrats clang, you've just 16 // diagnosed the behavior under test. 17 #if defined(__clang__) 18 #pragma clang diagnostic ignored "-Wexceptions" 19 #endif 20 21 #if __has_feature(cxx_nullptr) 22 23 struct A {}; 24 25 void test1() 26 { 27 try 28 { 29 throw nullptr; 30 assert(false); 31 } 32 catch (A* p) 33 { 34 assert(!p); 35 } 36 catch (const A*) 37 { 38 assert(false); 39 } 40 } 41 42 43 void test2() 44 { 45 try 46 { 47 throw nullptr; 48 assert(false); 49 } 50 catch (const A* p) 51 { 52 assert(!p); 53 } 54 catch (A*) 55 { 56 assert(false); 57 } 58 } 59 60 void test3() 61 { 62 try 63 { 64 throw nullptr; 65 assert(false); 66 } 67 catch (const A* const p) 68 { 69 assert(!p); 70 } 71 catch (A*) 72 { 73 assert(false); 74 } 75 } 76 77 void test4() 78 { 79 try 80 { 81 throw nullptr; 82 assert(false); 83 } 84 catch (A* p) 85 { 86 assert(!p); 87 } 88 catch (const A* const) 89 { 90 assert(false); 91 } 92 } 93 94 void test5() 95 { 96 try 97 { 98 throw nullptr; 99 assert(false); 100 } 101 catch (A const* p) 102 { 103 assert(!p); 104 } 105 catch (A*) 106 { 107 assert(false); 108 } 109 } 110 111 void test6() 112 { 113 try 114 { 115 throw nullptr; 116 assert(false); 117 } 118 catch (A* p) 119 { 120 assert(!p); 121 } 122 catch (A const*) 123 { 124 assert(false); 125 } 126 } 127 128 129 #else 130 131 void test1() {} 132 void test2() {} 133 void test3() {} 134 void test4() {} 135 void test5() {} 136 void test6() {} 137 138 #endif 139 140 int main() 141 { 142 test1(); 143 test2(); 144 test3(); 145 test4(); 146 test5(); 147 test6(); 148 } 149