2012-02-02 03:42:45 +08:00
|
|
|
//===----------------------- catch_function_01.cpp ------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|