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 // 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 15 16 #include <cassert> 17 18 template <class Tp> 19 bool can_convert(Tp) { return true; } 20 21 template <class> 22 bool can_convert(...) { return false; } 23 24 void f() {} 25 26 int main() 27 { 28 typedef void Function(); 29 assert(!can_convert<Function&>(&f)); 30 assert(!can_convert<void*>(&f)); 31 try 32 { 33 throw f; // converts to void (*)() 34 assert(false); 35 } 36 catch (Function& b) // can't catch void (*)() 37 { 38 assert(false); 39 } 40 catch (void*) // can't catch as void* 41 { 42 assert(false); 43 } 44 catch(Function*) 45 { 46 } 47 catch (...) 48 { 49 assert(false); 50 } 51 } 52