llvm-project
131 строка · 1.8 Кб
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
17struct A {};
18
19void test1()
20{
21try
22{
23throw nullptr;
24assert(false);
25}
26catch (A* p)
27{
28assert(!p);
29}
30catch (const A*)
31{
32assert(false);
33}
34}
35
36
37void test2()
38{
39try
40{
41throw nullptr;
42assert(false);
43}
44catch (const A* p)
45{
46assert(!p);
47}
48catch (A*)
49{
50assert(false);
51}
52}
53
54void test3()
55{
56try
57{
58throw nullptr;
59assert(false);
60}
61catch (const A* const p)
62{
63assert(!p);
64}
65catch (A*)
66{
67assert(false);
68}
69}
70
71void test4()
72{
73try
74{
75throw nullptr;
76assert(false);
77}
78catch (A* p)
79{
80assert(!p);
81}
82catch (const A* const)
83{
84assert(false);
85}
86}
87
88void test5()
89{
90try
91{
92throw nullptr;
93assert(false);
94}
95catch (A const* p)
96{
97assert(!p);
98}
99catch (A*)
100{
101assert(false);
102}
103}
104
105void test6()
106{
107try
108{
109throw nullptr;
110assert(false);
111}
112catch (A* p)
113{
114assert(!p);
115}
116catch (A const*)
117{
118assert(false);
119}
120}
121
122int main(int, char**) {
123test1();
124test2();
125test3();
126test4();
127test5();
128test6();
129
130return 0;
131}
132