llvm-project
77 строк · 1.3 Кб
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: c++03
10// UNSUPPORTED: no-exceptions
11
12#include <cassert>
13#include <cstdlib>
14
15struct A {};
16
17void test1()
18{
19try
20{
21throw nullptr;
22assert(false);
23}
24catch (int* p)
25{
26assert(!p);
27}
28catch (long*)
29{
30assert(false);
31}
32}
33
34void test2()
35{
36try
37{
38throw nullptr;
39assert(false);
40}
41catch (A* p)
42{
43assert(!p);
44}
45catch (int*)
46{
47assert(false);
48}
49}
50
51template <class Catch>
52void catch_nullptr_test() {
53try {
54throw nullptr;
55assert(false);
56} catch (Catch c) {
57assert(!c);
58} catch (...) {
59assert(false);
60}
61}
62
63
64int main(int, char**)
65{
66// catch naked nullptrs
67test1();
68test2();
69
70catch_nullptr_test<int*>();
71catch_nullptr_test<int**>();
72catch_nullptr_test<int A::*>();
73catch_nullptr_test<const int A::*>();
74catch_nullptr_test<int A::**>();
75
76return 0;
77}
78