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 14 template <class Tp> 15 bool can_convert(Tp) { return true; } 16 17 template <class> 18 bool can_convert(...) { return false; } 19 20 void f() {} 21 22 int main() 23 { 24 typedef void Function(); 25 assert(!can_convert<Function&>(&f)); 26 assert(!can_convert<void*>(&f)); 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 } 36 catch (void*) // can't catch as void* 37 { 38 assert(false); 39 } 40 catch(Function*) 41 { 42 } 43 catch (...) 44 { 45 assert(false); 46 } 47 } 48