1 //===----------------------- catch_function_01.cpp ------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // Can you have a catch clause of array type that catches anything? 10 11 // GCC incorrectly allows function pointer to be caught by reference. 12 // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69372 13 // XFAIL: gcc 14 // UNSUPPORTED: no-exceptions 15 16 #include <cassert> 17 18 template <class Tp> can_convert(Tp)19bool can_convert(Tp) { return true; } 20 21 template <class> can_convert(...)22bool can_convert(...) { return false; } 23 f()24void f() {} 25 main(int,char **)26int main(int, char**) 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 return 0; 53 } 54