[clang-tidy][modernize-use-starts-ends-with] Fix operator rewriting false negative...
[llvm-project.git] / libcxxabi / test / catch_pointer_nullptr.pass.cpp
blob3afb88bc4c694bbf2a0838b4392eef4081732245
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 // UNSUPPORTED: c++03
10 // UNSUPPORTED: no-exceptions
12 #include <cassert>
13 #include <cstdlib>
15 struct A {};
17 void test1()
19 try
21 throw nullptr;
22 assert(false);
24 catch (int* p)
26 assert(!p);
28 catch (long*)
30 assert(false);
34 void test2()
36 try
38 throw nullptr;
39 assert(false);
41 catch (A* p)
43 assert(!p);
45 catch (int*)
47 assert(false);
51 template <class Catch>
52 void catch_nullptr_test() {
53 try {
54 throw nullptr;
55 assert(false);
56 } catch (Catch c) {
57 assert(!c);
58 } catch (...) {
59 assert(false);
64 int main(int, char**)
66 // catch naked nullptrs
67 test1();
68 test2();
70 catch_nullptr_test<int*>();
71 catch_nullptr_test<int**>();
72 catch_nullptr_test<int A::*>();
73 catch_nullptr_test<const int A::*>();
74 catch_nullptr_test<int A::**>();
76 return 0;