Howard Hinnant | 4b3cb1c | 2012-02-01 19:42:45 +0000 | [diff] [blame] | 1 | //===----------------------- catch_function_01.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 you have a catch clause of array type that catches anything? |
| 11 | |
| 12 | #include <cassert> |
| 13 | |
Eric Fiselier | b979db1 | 2015-05-01 01:49:37 +0000 | [diff] [blame] | 14 | template <class Tp> |
| 15 | bool can_convert(Tp) { return true; } |
| 16 | |
| 17 | template <class> |
| 18 | bool can_convert(...) { return false; } |
| 19 | |
Howard Hinnant | 4b3cb1c | 2012-02-01 19:42:45 +0000 | [diff] [blame] | 20 | void f() {} |
| 21 | |
| 22 | int main() |
| 23 | { |
| 24 | typedef void Function(); |
Eric Fiselier | b979db1 | 2015-05-01 01:49:37 +0000 | [diff] [blame] | 25 | assert(!can_convert<Function&>(&f)); |
| 26 | assert(!can_convert<void*>(&f)); |
Howard Hinnant | 4b3cb1c | 2012-02-01 19:42:45 +0000 | [diff] [blame] | 27 | try |
| 28 | { |
| 29 | throw f; // converts to void (*)() |
| 30 | assert(false); |
| 31 | } |
| 32 | catch (Function& b) // can't catch void (*)() |
| 33 | { |
| 34 | assert(false); |
| 35 | } |
Eric Fiselier | b979db1 | 2015-05-01 01:49:37 +0000 | [diff] [blame] | 36 | catch (void*) // can't catch as void* |
| 37 | { |
| 38 | assert(false); |
| 39 | } |
| 40 | catch(Function*) |
| 41 | { |
| 42 | } |
Howard Hinnant | 4b3cb1c | 2012-02-01 19:42:45 +0000 | [diff] [blame] | 43 | catch (...) |
| 44 | { |
Eric Fiselier | b979db1 | 2015-05-01 01:49:37 +0000 | [diff] [blame] | 45 | assert(false); |
Howard Hinnant | 4b3cb1c | 2012-02-01 19:42:45 +0000 | [diff] [blame] | 46 | } |
| 47 | } |