1e434b34fSJonathan Roelofs //===----------------------- catch_function_01.cpp ------------------------===//
2e434b34fSJonathan Roelofs //
3e434b34fSJonathan Roelofs //                     The LLVM Compiler Infrastructure
4e434b34fSJonathan Roelofs //
5e434b34fSJonathan Roelofs // This file is dual licensed under the MIT and the University of Illinois Open
6e434b34fSJonathan Roelofs // Source Licenses. See LICENSE.TXT for details.
7e434b34fSJonathan Roelofs //
8e434b34fSJonathan Roelofs //===----------------------------------------------------------------------===//
9e434b34fSJonathan Roelofs 
10e434b34fSJonathan Roelofs // Can you have a catch clause of array type that catches anything?
11e434b34fSJonathan Roelofs 
123f7c2074SEric Fiselier // GCC incorrectly allows function pointer to be caught by reference.
133f7c2074SEric Fiselier // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69372
143f7c2074SEric Fiselier // XFAIL: gcc
15*57e446daSAsiri Rathnayake // UNSUPPORTED: libcxxabi-no-exceptions
163f7c2074SEric Fiselier 
17e434b34fSJonathan Roelofs #include <cassert>
18e434b34fSJonathan Roelofs 
1965ace9daSEric Fiselier template <class Tp>
2065ace9daSEric Fiselier bool can_convert(Tp) { return true; }
2165ace9daSEric Fiselier 
2265ace9daSEric Fiselier template <class>
2365ace9daSEric Fiselier bool can_convert(...) { return false; }
2465ace9daSEric Fiselier 
25e434b34fSJonathan Roelofs void f() {}
26e434b34fSJonathan Roelofs 
27e434b34fSJonathan Roelofs int main()
28e434b34fSJonathan Roelofs {
29e434b34fSJonathan Roelofs     typedef void Function();
3065ace9daSEric Fiselier     assert(!can_convert<Function&>(&f));
3165ace9daSEric Fiselier     assert(!can_convert<void*>(&f));
32e434b34fSJonathan Roelofs     try
33e434b34fSJonathan Roelofs     {
34e434b34fSJonathan Roelofs         throw f;     // converts to void (*)()
35e434b34fSJonathan Roelofs         assert(false);
36e434b34fSJonathan Roelofs     }
37e434b34fSJonathan Roelofs     catch (Function& b)  // can't catch void (*)()
38e434b34fSJonathan Roelofs     {
39e434b34fSJonathan Roelofs         assert(false);
40e434b34fSJonathan Roelofs     }
4165ace9daSEric Fiselier     catch (void*) // can't catch as void*
4265ace9daSEric Fiselier     {
4365ace9daSEric Fiselier         assert(false);
4465ace9daSEric Fiselier     }
4565ace9daSEric Fiselier     catch(Function*)
4665ace9daSEric Fiselier     {
4765ace9daSEric Fiselier     }
48e434b34fSJonathan Roelofs     catch (...)
49e434b34fSJonathan Roelofs     {
5065ace9daSEric Fiselier         assert(false);
51e434b34fSJonathan Roelofs     }
52e434b34fSJonathan Roelofs }
53