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// UNSUPPORTED: no-exceptions
12
13// GCC incorrectly allows function pointer to be caught by reference.
14// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69372
15// XFAIL: gcc
16
17#include <cassert>
18
19template <class Tp>
20bool can_convert(Tp) { return true; }
21
22template <class>
23bool can_convert(...) { return false; }
24
25void f() {}
26
27int main(int, char**)
28{
29 typedef void Function();
30 assert(!can_convert<Function&>(&f));
31 assert(!can_convert<void*>(&f));
32 try
33 {
34 throw f; // converts to void (*)()
35 assert(false);
36 }
37 catch (Function& b) // can't catch void (*)()
38 {
39 assert(false);
40 }
41 catch (void*) // can't catch as void*
42 {
43 assert(false);
44 }
45 catch(Function*)
46 {
47 }
48 catch (...)
49 {
50 assert(false);
51 }
52
53 return 0;
54}
55

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of libcxxabi/test/catch_function_01.pass.cpp