[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / libcxxabi / test / catch_pointer_nullptr.pass.cpp
blob24f8432a5fff67dd15afdb24ff777eaa40bc0c51
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 //===----------------------------------------------------------------------===//
9 // Catching an exception thrown as nullptr was not properly handled before
10 // 2f984cab4fa7, which landed in macOS 10.13
11 // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}}
13 // UNSUPPORTED: c++03
14 // UNSUPPORTED: no-exceptions
16 #include <cassert>
17 #include <cstdlib>
19 struct A {};
21 void test1()
23 try
25 throw nullptr;
26 assert(false);
28 catch (int* p)
30 assert(!p);
32 catch (long*)
34 assert(false);
38 void test2()
40 try
42 throw nullptr;
43 assert(false);
45 catch (A* p)
47 assert(!p);
49 catch (int*)
51 assert(false);
55 template <class Catch>
56 void catch_nullptr_test() {
57 try {
58 throw nullptr;
59 assert(false);
60 } catch (Catch c) {
61 assert(!c);
62 } catch (...) {
63 assert(false);
68 int main(int, char**)
70 // catch naked nullptrs
71 test1();
72 test2();
74 catch_nullptr_test<int*>();
75 catch_nullptr_test<int**>();
76 catch_nullptr_test<int A::*>();
77 catch_nullptr_test<const int A::*>();
78 catch_nullptr_test<int A::**>();
80 return 0;