blob: 1bdda69f1afe455e82cf8ee3dad463514d781912 [file] [log] [blame]
Howard Hinnant4b3cb1c2012-02-01 19:42:45 +00001//===----------------------- 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 Fiseliere65dd842016-01-20 04:06:46 +000012// 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 Hinnant4b3cb1c2012-02-01 19:42:45 +000016#include <cassert>
17
Eric Fiselierb979db12015-05-01 01:49:37 +000018template <class Tp>
19bool can_convert(Tp) { return true; }
20
21template <class>
22bool can_convert(...) { return false; }
23
Howard Hinnant4b3cb1c2012-02-01 19:42:45 +000024void f() {}
25
26int main()
27{
28 typedef void Function();
Eric Fiselierb979db12015-05-01 01:49:37 +000029 assert(!can_convert<Function&>(&f));
30 assert(!can_convert<void*>(&f));
Howard Hinnant4b3cb1c2012-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 Fiselierb979db12015-05-01 01:49:37 +000040 catch (void*) // can't catch as void*
41 {
42 assert(false);
43 }
44 catch(Function*)
45 {
46 }
Howard Hinnant4b3cb1c2012-02-01 19:42:45 +000047 catch (...)
48 {
Eric Fiselierb979db12015-05-01 01:49:37 +000049 assert(false);
Howard Hinnant4b3cb1c2012-02-01 19:42:45 +000050 }
51}