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-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: stdlib=apple-libc++ && target={{.+}}-apple-macosx10.{{9|10|11|12}}
12
13// UNSUPPORTED: no-exceptions
14
15#include <cassert>
16
17#if __has_feature(cxx_nullptr)
18
19struct A
20{
21 const int i;
22 int j;
23};
24
25typedef const int A::*md1;
26typedef int A::*md2;
27
28void test1()
29{
30 try
31 {
32 throw nullptr;
33 assert(false);
34 }
35 catch (md2 p)
36 {
37 assert(!p);
38 }
39 catch (md1)
40 {
41 assert(false);
42 }
43}
44
45void test2()
46{
47 try
48 {
49 throw nullptr;
50 assert(false);
51 }
52 catch (md1 p)
53 {
54 assert(!p);
55 }
56 catch (md2)
57 {
58 assert(false);
59 }
60}
61
62#else
63
64void test1()
65{
66}
67
68void test2()
69{
70}
71
72#endif
73
74int main(int, char**)
75{
76 test1();
77 test2();
78
79 return 0;
80}
81

source code of libcxxabi/test/catch_member_pointer_nullptr.pass.cpp