blob: bbc94ad84d05fb5f1015b62da8e5aa8926a4c1be [file] [log] [blame]
Howard Hinnanta21f8c22012-02-01 19:42:45 +00001//===----------------------- catch_function_01.cpp ------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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
Howard Hinnanta21f8c22012-02-01 19:42:45 +00006//
7//===----------------------------------------------------------------------===//
8
9// Can you have a catch clause of array type that catches anything?
10
Eric Fiselier3f7c2072016-01-20 04:06:46 +000011// 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
Louis Dionne8c611142020-04-17 10:29:15 -040014// UNSUPPORTED: no-exceptions
Eric Fiselier3f7c2072016-01-20 04:06:46 +000015
Howard Hinnanta21f8c22012-02-01 19:42:45 +000016#include <cassert>
17
Eric Fiselier65ace9d2015-05-01 01:49:37 +000018template <class Tp>
19bool can_convert(Tp) { return true; }
20
21template <class>
22bool can_convert(...) { return false; }
23
Howard Hinnanta21f8c22012-02-01 19:42:45 +000024void f() {}
25
Louis Dionne504bc072020-10-08 13:36:33 -040026int main(int, char**)
Howard Hinnanta21f8c22012-02-01 19:42:45 +000027{
28 typedef void Function();
Eric Fiselier65ace9d2015-05-01 01:49:37 +000029 assert(!can_convert<Function&>(&f));
30 assert(!can_convert<void*>(&f));
Howard Hinnanta21f8c22012-02-01 19:42:45 +000031 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 }
Eric Fiselier65ace9d2015-05-01 01:49:37 +000040 catch (void*) // can't catch as void*
41 {
42 assert(false);
43 }
44 catch(Function*)
45 {
46 }
Howard Hinnanta21f8c22012-02-01 19:42:45 +000047 catch (...)
48 {
Eric Fiselier65ace9d2015-05-01 01:49:37 +000049 assert(false);
Howard Hinnanta21f8c22012-02-01 19:42:45 +000050 }
Louis Dionne504bc072020-10-08 13:36:33 -040051
52 return 0;
Howard Hinnanta21f8c22012-02-01 19:42:45 +000053}