blob: 1bdda69f1afe455e82cf8ee3dad463514d781912 [file] [log] [blame]
Howard Hinnanta21f8c22012-02-01 19:42:451//===----------------------- catch_function_01.cpp ------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// Can you have a catch clause of array type that catches anything?
11
Eric Fiselier3f7c2072016-01-20 04:06:4612// GCC incorrectly allows function pointer to be caught by reference.
13// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69372
14// XFAIL: gcc
15
Howard Hinnanta21f8c22012-02-01 19:42:4516#include <cassert>
17
Eric Fiselier65ace9d2015-05-01 01:49:3718template <class Tp>
19bool can_convert(Tp) { return true; }
20
21template <class>
22bool can_convert(...) { return false; }
23
Howard Hinnanta21f8c22012-02-01 19:42:4524void f() {}
25
26int main()
27{
28 typedef void Function();
Eric Fiselier65ace9d2015-05-01 01:49:3729 assert(!can_convert<Function&>(&f));
30 assert(!can_convert<void*>(&f));
Howard Hinnanta21f8c22012-02-01 19:42:4531 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:3740 catch (void*) // can't catch as void*
41 {
42 assert(false);
43 }
44 catch(Function*)
45 {
46 }
Howard Hinnanta21f8c22012-02-01 19:42:4547 catch (...)
48 {
Eric Fiselier65ace9d2015-05-01 01:49:3749 assert(false);
Howard Hinnanta21f8c22012-02-01 19:42:4550 }
51}