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: c++98, c++03, c++11, c++14 12 // UNSUPPORTED: libcxxabi-no-exceptions, libcxxabi-no-qualified-function-types 13 14 #include <cassert> 15 16 template<bool Noexcept> void f() noexcept(Noexcept) {} 17 template<bool Noexcept> using FnType = void() noexcept(Noexcept); 18 19 template<bool ThrowNoexcept, bool CatchNoexcept> 20 void check() 21 { 22 try 23 { 24 auto *p = f<ThrowNoexcept>; 25 throw p; 26 assert(false); 27 } 28 catch (FnType<CatchNoexcept> *p) 29 { 30 assert(ThrowNoexcept || !CatchNoexcept); 31 assert(p == &f<ThrowNoexcept>); 32 } 33 catch (...) 34 { 35 assert(!ThrowNoexcept && CatchNoexcept); 36 } 37 } 38 39 void check_deep() { 40 auto *p = f<true>; 41 try 42 { 43 throw &p; 44 } 45 catch (FnType<false> **q) 46 { 47 assert(false); 48 } 49 catch (FnType<true> **q) 50 { 51 } 52 catch (...) 53 { 54 assert(false); 55 } 56 } 57 58 int main() 59 { 60 check<false, false>(); 61 check<false, true>(); 62 check<true, false>(); 63 check<true, true>(); 64 check_deep(); 65 } 66