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 // 65ace9daa360 made it in the dylib in macOS 10.11 17 // XFAIL: with_system_cxx_lib=macosx10.10 18 // XFAIL: with_system_cxx_lib=macosx10.9 19 20 #include <cassert> 21 22 template <class Tp> 23 bool can_convert(Tp) { return true; } 24 25 template <class> 26 bool can_convert(...) { return false; } 27 28 void f() {} 29 30 int main(int, char**) 31 { 32 typedef void Function(); 33 assert(!can_convert<Function&>(&f)); 34 assert(!can_convert<void*>(&f)); 35 try 36 { 37 throw f; // converts to void (*)() 38 assert(false); 39 } 40 catch (Function& b) // can't catch void (*)() 41 { 42 assert(false); 43 } 44 catch (void*) // can't catch as void* 45 { 46 assert(false); 47 } 48 catch(Function*) 49 { 50 } 51 catch (...) 52 { 53 assert(false); 54 } 55 56 return 0; 57 } 58