• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===---------------------- 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?
11 // UNSUPPORTED: libcxxabi-no-exceptions, libcxxabi-no-noexcept-function-type
12 
13 #include <cassert>
14 
f()15 template<bool Noexcept> void f() noexcept(Noexcept) {}
16 template<bool Noexcept> using FnType = void() noexcept(Noexcept);
17 
18 template<bool ThrowNoexcept, bool CatchNoexcept>
check()19 void 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 
check_deep()38 void 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 
main()57 int main()
58 {
59     check<false, false>();
60     check<false, true>();
61     check<true, false>();
62     check<true, true>();
63     check_deep();
64 }
65