blob: 6bd9e6fe6a14f0231f0845916583b55f3579c1ce [file] [log] [blame]
Richard Smithc320e4c2016-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 Smith6d9aad02016-12-02 22:14:59 +000012// UNSUPPORTED: libcxxabi-no-exceptions, libcxxabi-no-noexcept-function-type
Richard Smithc320e4c2016-11-02 23:41:51 +000013
Eric Fiselier8ca586d2017-05-09 00:11:02 +000014// GCC 7 and 8 support noexcept function types but this test still fails.
15// This is likely a bug in their implementation. Investigation needed.
16// XFAIL: gcc-7, gcc-8
17
Richard Smithc320e4c2016-11-02 23:41:51 +000018#include <cassert>
19
20struct X {
21 template<bool Noexcept> void f() noexcept(Noexcept) {}
22};
23template<bool Noexcept> using FnType = void (X::*)() noexcept(Noexcept);
24
25template<bool ThrowNoexcept, bool CatchNoexcept>
26void check()
27{
28 try
29 {
30 auto p = &X::f<ThrowNoexcept>;
31 throw p;
32 assert(false);
33 }
34 catch (FnType<CatchNoexcept> p)
35 {
36 assert(ThrowNoexcept || !CatchNoexcept);
37 assert(p == &X::f<ThrowNoexcept>);
38 }
39 catch (...)
40 {
41 assert(!ThrowNoexcept && CatchNoexcept);
42 }
43}
44
45void check_deep() {
46 FnType<true> p = &X::f<true>;
47 try
48 {
49 throw &p;
50 }
51 catch (FnType<false> *q)
52 {
53 assert(false);
54 }
55 catch (FnType<true> *q)
56 {
57 }
58 catch (...)
59 {
60 assert(false);
61 }
62}
63
64int main()
65{
66 check<false, false>();
67 check<false, true>();
68 check<true, false>();
69 check<true, true>();
70 check_deep();
Richard Smithc320e4c2016-11-02 23:41:51 +000071}