1 //===----------------- catch_member_pointer_nullptr.cpp -------------------===// 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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // Catching an exception thrown as nullptr was not properly handled before 10 // 2f984cab4fa7, which landed in macOS 10.13 11 // XFAIL: with_system_cxx_lib=macosx10.12 12 // XFAIL: with_system_cxx_lib=macosx10.11 13 // XFAIL: with_system_cxx_lib=macosx10.10 14 // XFAIL: with_system_cxx_lib=macosx10.9 15 16 // UNSUPPORTED: no-exceptions 17 18 #include <cassert> 19 20 #if __has_feature(cxx_nullptr) 21 22 struct A 23 { 24 const int i; 25 int j; 26 }; 27 28 typedef const int A::*md1; 29 typedef int A::*md2; 30 31 void test1() 32 { 33 try 34 { 35 throw nullptr; 36 assert(false); 37 } 38 catch (md2 p) 39 { 40 assert(!p); 41 } 42 catch (md1) 43 { 44 assert(false); 45 } 46 } 47 48 void test2() 49 { 50 try 51 { 52 throw nullptr; 53 assert(false); 54 } 55 catch (md1 p) 56 { 57 assert(!p); 58 } 59 catch (md2) 60 { 61 assert(false); 62 } 63 } 64 65 #else 66 67 void test1() 68 { 69 } 70 71 void test2() 72 { 73 } 74 75 #endif 76 77 int main(int, char**) 78 { 79 test1(); 80 test2(); 81 82 return 0; 83 } 84