Debian Codegraph @

libcxxabi/test/catch_const_pointer_nullptr.pass.cpp

raw
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 // UNSUPPORTED: no-exceptions
10
11 // Clang and GCC emit warnings about exceptions of type 'Child' being caught by
12 // an earlier handler of type 'Base'.
13 // ADDITIONAL_COMPILE_FLAGS: -Wno-exceptions
14
15 #include <cassert>
16
17 struct A {};
18
19 void test1()
20 {
21 try
22 {
23 throw nullptr;
24 assert(false);
25 }
26 catch (A* p)
27 {
28 assert(!p);
29 }
30 catch (const A*)
31 {
32 assert(false);
33 }
34 }
35
36
37 void test2()
38 {
39 try
40 {
41 throw nullptr;
42 assert(false);
43 }
44 catch (const A* p)
45 {
46 assert(!p);
47 }
48 catch (A*)
49 {
50 assert(false);
51 }
52 }
53
54 void test3()
55 {
56 try
57 {
58 throw nullptr;
59 assert(false);
60 }
61 catch (const A* const p)
62 {
63 assert(!p);
64 }
65 catch (A*)
66 {
67 assert(false);
68 }
69 }
70
71 void test4()
72 {
73 try
74 {
75 throw nullptr;
76 assert(false);
77 }
78 catch (A* p)
79 {
80 assert(!p);
81 }
82 catch (const A* const)
83 {
84 assert(false);
85 }
86 }
87
88 void test5()
89 {
90 try
91 {
92 throw nullptr;
93 assert(false);
94 }
95 catch (A const* p)
96 {
97 assert(!p);
98 }
99 catch (A*)
100 {
101 assert(false);
102 }
103 }
104
105 void test6()
106 {
107 try
108 {
109 throw nullptr;
110 assert(false);
111 }
112 catch (A* p)
113 {
114 assert(!p);
115 }
116 catch (A const*)
117 {
118 assert(false);
119 }
120 }
121
122 int main(int, char**) {
123 test1();
124 test2();
125 test3();
126 test4();
127 test5();
128 test6();
129
130 return 0;
131 }