Howard Hinnant | a21f8c2 | 2012-02-01 19:42:45 | [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 | |
Eric Fiselier | 3f7c207 | 2016-01-20 04:06:46 | [diff] [blame] | 12 | // GCC incorrectly allows function pointer to be caught by reference. |
| 13 | // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69372 |
| 14 | // XFAIL: gcc |
Asiri Rathnayake | 57e446d | 2016-05-31 12:01:32 | [diff] [blame] | 15 | // UNSUPPORTED: libcxxabi-no-exceptions |
Eric Fiselier | 3f7c207 | 2016-01-20 04:06:46 | [diff] [blame] | 16 | |
Howard Hinnant | a21f8c2 | 2012-02-01 19:42:45 | [diff] [blame] | 17 | #include <cassert> |
| 18 | |
Eric Fiselier | 65ace9d | 2015-05-01 01:49:37 | [diff] [blame] | 19 | template <class Tp> |
| 20 | bool can_convert(Tp) { return true; } |
| 21 | |
| 22 | template <class> |
| 23 | bool can_convert(...) { return false; } |
| 24 | |
Howard Hinnant | a21f8c2 | 2012-02-01 19:42:45 | [diff] [blame] | 25 | void f() {} |
| 26 | |
| 27 | int main() |
| 28 | { |
| 29 | typedef void Function(); |
Eric Fiselier | 65ace9d | 2015-05-01 01:49:37 | [diff] [blame] | 30 | assert(!can_convert<Function&>(&f)); |
| 31 | assert(!can_convert<void*>(&f)); |
Howard Hinnant | a21f8c2 | 2012-02-01 19:42:45 | [diff] [blame] | 32 | try |
| 33 | { |
| 34 | throw f; // converts to void (*)() |
| 35 | assert(false); |
| 36 | } |
| 37 | catch (Function& b) // can't catch void (*)() |
| 38 | { |
| 39 | assert(false); |
| 40 | } |
Eric Fiselier | 65ace9d | 2015-05-01 01:49:37 | [diff] [blame] | 41 | catch (void*) // can't catch as void* |
| 42 | { |
| 43 | assert(false); |
| 44 | } |
| 45 | catch(Function*) |
| 46 | { |
| 47 | } |
Howard Hinnant | a21f8c2 | 2012-02-01 19:42:45 | [diff] [blame] | 48 | catch (...) |
| 49 | { |
Eric Fiselier | 65ace9d | 2015-05-01 01:49:37 | [diff] [blame] | 50 | assert(false); |
Howard Hinnant | a21f8c2 | 2012-02-01 19:42:45 | [diff] [blame] | 51 | } |
| 52 | } |