2012-02-02 03:42:45 +08:00
|
|
|
//===----------------------- catch_function_01.cpp ------------------------===//
|
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-02-02 03:42:45 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Can you have a catch clause of array type that catches anything?
|
|
|
|
|
2016-01-20 12:06:46 +08:00
|
|
|
// GCC incorrectly allows function pointer to be caught by reference.
|
|
|
|
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69372
|
|
|
|
// XFAIL: gcc
|
2020-04-17 22:29:15 +08:00
|
|
|
// UNSUPPORTED: no-exceptions
|
2016-01-20 12:06:46 +08:00
|
|
|
|
2012-02-02 03:42:45 +08:00
|
|
|
#include <cassert>
|
|
|
|
|
2015-05-01 09:49:37 +08:00
|
|
|
template <class Tp>
|
|
|
|
bool can_convert(Tp) { return true; }
|
|
|
|
|
|
|
|
template <class>
|
|
|
|
bool can_convert(...) { return false; }
|
|
|
|
|
2012-02-02 03:42:45 +08:00
|
|
|
void f() {}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
typedef void Function();
|
2015-05-01 09:49:37 +08:00
|
|
|
assert(!can_convert<Function&>(&f));
|
|
|
|
assert(!can_convert<void*>(&f));
|
2012-02-02 03:42:45 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
throw f; // converts to void (*)()
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
catch (Function& b) // can't catch void (*)()
|
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
}
|
2015-05-01 09:49:37 +08:00
|
|
|
catch (void*) // can't catch as void*
|
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
catch(Function*)
|
|
|
|
{
|
|
|
|
}
|
2012-02-02 03:42:45 +08:00
|
|
|
catch (...)
|
|
|
|
{
|
2015-05-01 09:49:37 +08:00
|
|
|
assert(false);
|
2012-02-02 03:42:45 +08:00
|
|
|
}
|
|
|
|
}
|