blob: 087fce44c704c56b2d808064ab9cb0bc7e9a6310 [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
12#include <cassert>
13
Eric Fiselierb979db12015-05-01 01:49:37 +000014template <class Tp>
15bool can_convert(Tp) { return true; }
16
17template <class>
18bool can_convert(...) { return false; }
19
Howard Hinnant4b3cb1c2012-02-01 19:42:45 +000020void f() {}
21
22int main()
23{
24 typedef void Function();
Eric Fiselierb979db12015-05-01 01:49:37 +000025 assert(!can_convert<Function&>(&f));
26 assert(!can_convert<void*>(&f));
Howard Hinnant4b3cb1c2012-02-01 19:42:45 +000027 try
28 {
29 throw f; // converts to void (*)()
30 assert(false);
31 }
32 catch (Function& b) // can't catch void (*)()
33 {
34 assert(false);
35 }
Eric Fiselierb979db12015-05-01 01:49:37 +000036 catch (void*) // can't catch as void*
37 {
38 assert(false);
39 }
40 catch(Function*)
41 {
42 }
Howard Hinnant4b3cb1c2012-02-01 19:42:45 +000043 catch (...)
44 {
Eric Fiselierb979db12015-05-01 01:49:37 +000045 assert(false);
Howard Hinnant4b3cb1c2012-02-01 19:42:45 +000046 }
47}