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