blob: bf817a93a661ecb5ce8fe86841711f432552a205 [file] [log] [blame]
Richard Smith80b64f02016-11-02 23:41:511//===---------------------- catch_function_03.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 function pointer be caught by a non-noexcept catch clause?
Richard Smith366bb542016-12-02 22:14:5911// UNSUPPORTED: libcxxabi-no-exceptions, libcxxabi-no-noexcept-function-type
Richard Smith80b64f02016-11-02 23:41:5112
13#include <cassert>
14
15template<bool Noexcept> void f() noexcept(Noexcept) {}
16template<bool Noexcept> using FnType = void() noexcept(Noexcept);
17
18template<bool ThrowNoexcept, bool CatchNoexcept>
19void check()
20{
21 try
22 {
23 auto *p = f<ThrowNoexcept>;
24 throw p;
25 assert(false);
26 }
27 catch (FnType<CatchNoexcept> *p)
28 {
29 assert(ThrowNoexcept || !CatchNoexcept);
30 assert(p == &f<ThrowNoexcept>);
31 }
32 catch (...)
33 {
34 assert(!ThrowNoexcept && CatchNoexcept);
35 }
36}
37
38void check_deep() {
39 auto *p = f<true>;
40 try
41 {
42 throw &p;
43 }
44 catch (FnType<false> **q)
45 {
46 assert(false);
47 }
48 catch (FnType<true> **q)
49 {
50 }
51 catch (...)
52 {
53 assert(false);
54 }
55}
56
57int main()
58{
59 check<false, false>();
60 check<false, true>();
61 check<true, false>();
62 check<true, true>();
63 check_deep();
Richard Smith80b64f02016-11-02 23:41:5164}