blob: 5ce2359105f620c7252f08e7a2e5de2f0b301bba [file] [log] [blame]
Richard Smith80b64f02016-11-02 23:41:51 +00001//===--------------- catch_member_function_pointer_02.cpp -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// Can a noexcept member function pointer be caught by a non-noexcept catch
11// clause?
Richard Smith366bb542016-12-02 22:14:59 +000012// UNSUPPORTED: libcxxabi-no-exceptions, libcxxabi-no-noexcept-function-type
Richard Smith80b64f02016-11-02 23:41:51 +000013
14#include <cassert>
15
16struct X {
17 template<bool Noexcept> void f() noexcept(Noexcept) {}
18};
19template<bool Noexcept> using FnType = void (X::*)() noexcept(Noexcept);
20
21template<bool ThrowNoexcept, bool CatchNoexcept>
22void check()
23{
24 try
25 {
26 auto p = &X::f<ThrowNoexcept>;
27 throw p;
28 assert(false);
29 }
30 catch (FnType<CatchNoexcept> p)
31 {
32 assert(ThrowNoexcept || !CatchNoexcept);
33 assert(p == &X::f<ThrowNoexcept>);
34 }
35 catch (...)
36 {
37 assert(!ThrowNoexcept && CatchNoexcept);
38 }
39}
40
41void check_deep() {
42 FnType<true> p = &X::f<true>;
43 try
44 {
45 throw &p;
46 }
47 catch (FnType<false> *q)
48 {
49 assert(false);
50 }
51 catch (FnType<true> *q)
52 {
53 }
54 catch (...)
55 {
56 assert(false);
57 }
58}
59
60int main()
61{
62 check<false, false>();
63 check<false, true>();
64 check<true, false>();
65 check<true, true>();
66 check_deep();
Richard Smith80b64f02016-11-02 23:41:51 +000067}