Richard Smith | 80b64f0 | 2016-11-02 23:41:51 | [diff] [blame] | 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? |
Richard Smith | 366bb54 | 2016-12-02 22:14:59 | [diff] [blame] | 11 | // UNSUPPORTED: libcxxabi-no-exceptions, libcxxabi-no-noexcept-function-type |
Richard Smith | 80b64f0 | 2016-11-02 23:41:51 | [diff] [blame] | 12 | |
| 13 | #include <cassert> |
| 14 | |
| 15 | template<bool Noexcept> void f() noexcept(Noexcept) {} |
| 16 | template<bool Noexcept> using FnType = void() noexcept(Noexcept); |
| 17 | |
| 18 | template<bool ThrowNoexcept, bool CatchNoexcept> |
| 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 | |
| 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 | |
| 57 | int main() |
| 58 | { |
| 59 | check<false, false>(); |
| 60 | check<false, true>(); |
| 61 | check<true, false>(); |
| 62 | check<true, true>(); |
| 63 | check_deep(); |
Richard Smith | 80b64f0 | 2016-11-02 23:41:51 | [diff] [blame] | 64 | } |