xref: /llvm-project/libcxxabi/test/catch_function_01.pass.cpp (revision 3497500946c9b6a1b2e1452312a24c41ee412b34)
1eb8650a7SLouis Dionne //===----------------------------------------------------------------------===//
2e434b34fSJonathan Roelofs //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e434b34fSJonathan Roelofs //
7e434b34fSJonathan Roelofs //===----------------------------------------------------------------------===//
8e434b34fSJonathan Roelofs 
9e434b34fSJonathan Roelofs // Can you have a catch clause of array type that catches anything?
10e434b34fSJonathan Roelofs 
11*34975009SLouis Dionne // UNSUPPORTED: no-exceptions
12*34975009SLouis Dionne 
133f7c2074SEric Fiselier // GCC incorrectly allows function pointer to be caught by reference.
143f7c2074SEric Fiselier // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69372
153f7c2074SEric Fiselier // XFAIL: gcc
1660ba1fefSLouis Dionne 
17e434b34fSJonathan Roelofs #include <cassert>
18e434b34fSJonathan Roelofs 
1965ace9daSEric Fiselier template <class Tp>
can_convert(Tp)2065ace9daSEric Fiselier bool can_convert(Tp) { return true; }
2165ace9daSEric Fiselier 
2265ace9daSEric Fiselier template <class>
can_convert(...)2365ace9daSEric Fiselier bool can_convert(...) { return false; }
2465ace9daSEric Fiselier 
f()25e434b34fSJonathan Roelofs void f() {}
26e434b34fSJonathan Roelofs 
main(int,char **)27504bc07dSLouis Dionne int main(int, char**)
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     }
52504bc07dSLouis Dionne 
53504bc07dSLouis Dionne     return 0;
54e434b34fSJonathan Roelofs }
55