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 test1()25void 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 test2()43void 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 test3()60void 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 test4()77void 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 test5()94void 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 test6()111void 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 test1()131void test1() {} test2()132void test2() {} test3()133void test3() {} test4()134void test4() {} test5()135void test5() {} test6()136void test6() {} 137 138 #endif 139 main()140int main() 141 { 142 test1(); 143 test2(); 144 test3(); 145 test4(); 146 test5(); 147 test6(); 148 } 149