annotate libcxxabi/test/catch_member_function_pointer_02.pass.cpp @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 0572611fdcc8
children 5f17cb93ff66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===--------------- catch_member_function_pointer_02.cpp -----------------===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 // Can a noexcept member function pointer be caught by a non-noexcept catch
anatofuz
parents:
diff changeset
10 // clause?
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
11 // UNSUPPORTED: no-exceptions, libcxxabi-no-noexcept-function-type
150
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 // GCC 7 and 8 support noexcept function types but this test still fails.
anatofuz
parents:
diff changeset
14 // This is likely a bug in their implementation. Investigation needed.
anatofuz
parents:
diff changeset
15 // XFAIL: gcc-7, gcc-8, gcc-9, gcc-10
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 #include <cassert>
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 struct X {
anatofuz
parents:
diff changeset
20 template<bool Noexcept> void f() noexcept(Noexcept) {}
anatofuz
parents:
diff changeset
21 };
anatofuz
parents:
diff changeset
22 template<bool Noexcept> using FnType = void (X::*)() noexcept(Noexcept);
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 template<bool ThrowNoexcept, bool CatchNoexcept>
anatofuz
parents:
diff changeset
25 void check()
anatofuz
parents:
diff changeset
26 {
anatofuz
parents:
diff changeset
27 try
anatofuz
parents:
diff changeset
28 {
anatofuz
parents:
diff changeset
29 auto p = &X::f<ThrowNoexcept>;
anatofuz
parents:
diff changeset
30 throw p;
anatofuz
parents:
diff changeset
31 assert(false);
anatofuz
parents:
diff changeset
32 }
anatofuz
parents:
diff changeset
33 catch (FnType<CatchNoexcept> p)
anatofuz
parents:
diff changeset
34 {
anatofuz
parents:
diff changeset
35 assert(ThrowNoexcept || !CatchNoexcept);
anatofuz
parents:
diff changeset
36 assert(p == &X::f<ThrowNoexcept>);
anatofuz
parents:
diff changeset
37 }
anatofuz
parents:
diff changeset
38 catch (...)
anatofuz
parents:
diff changeset
39 {
anatofuz
parents:
diff changeset
40 assert(!ThrowNoexcept && CatchNoexcept);
anatofuz
parents:
diff changeset
41 }
anatofuz
parents:
diff changeset
42 }
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 void check_deep() {
anatofuz
parents:
diff changeset
45 FnType<true> p = &X::f<true>;
anatofuz
parents:
diff changeset
46 try
anatofuz
parents:
diff changeset
47 {
anatofuz
parents:
diff changeset
48 throw &p;
anatofuz
parents:
diff changeset
49 }
anatofuz
parents:
diff changeset
50 catch (FnType<false> *q)
anatofuz
parents:
diff changeset
51 {
anatofuz
parents:
diff changeset
52 assert(false);
anatofuz
parents:
diff changeset
53 }
anatofuz
parents:
diff changeset
54 catch (FnType<true> *q)
anatofuz
parents:
diff changeset
55 {
anatofuz
parents:
diff changeset
56 }
anatofuz
parents:
diff changeset
57 catch (...)
anatofuz
parents:
diff changeset
58 {
anatofuz
parents:
diff changeset
59 assert(false);
anatofuz
parents:
diff changeset
60 }
anatofuz
parents:
diff changeset
61 }
anatofuz
parents:
diff changeset
62
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
63 int main(int, char**)
150
anatofuz
parents:
diff changeset
64 {
anatofuz
parents:
diff changeset
65 check<false, false>();
anatofuz
parents:
diff changeset
66 check<false, true>();
anatofuz
parents:
diff changeset
67 check<true, false>();
anatofuz
parents:
diff changeset
68 check<true, true>();
anatofuz
parents:
diff changeset
69 check_deep();
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
70
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
71 return 0;
150
anatofuz
parents:
diff changeset
72 }