2021-11-17 16:25:01 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
2016-11-02 23:41:51 +00:00
|
|
|
//
|
2019-01-19 10:56:40 +00: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
|
2016-11-02 23:41:51 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Can a noexcept function pointer be caught by a non-noexcept catch clause?
|
2021-11-08 17:00:43 -05:00
|
|
|
// UNSUPPORTED: c++03, c++11, c++14
|
|
|
|
// UNSUPPORTED: no-exceptions
|
2021-07-15 09:43:47 -04:00
|
|
|
|
2016-11-02 23:41:51 +00:00
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
template<bool Noexcept> void f() noexcept(Noexcept) {}
|
|
|
|
template<bool Noexcept> using FnType = void() noexcept(Noexcept);
|
|
|
|
|
|
|
|
template<bool ThrowNoexcept, bool CatchNoexcept>
|
|
|
|
void check()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
auto *p = f<ThrowNoexcept>;
|
|
|
|
throw p;
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
catch (FnType<CatchNoexcept> *p)
|
|
|
|
{
|
|
|
|
assert(ThrowNoexcept || !CatchNoexcept);
|
|
|
|
assert(p == &f<ThrowNoexcept>);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
assert(!ThrowNoexcept && CatchNoexcept);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void check_deep() {
|
|
|
|
auto *p = f<true>;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
throw &p;
|
|
|
|
}
|
|
|
|
catch (FnType<false> **q)
|
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
catch (FnType<true> **q)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-08 13:36:33 -04:00
|
|
|
int main(int, char**)
|
2016-11-02 23:41:51 +00:00
|
|
|
{
|
|
|
|
check<false, false>();
|
|
|
|
check<false, true>();
|
|
|
|
check<true, false>();
|
|
|
|
check<true, true>();
|
|
|
|
check_deep();
|
2020-10-08 13:36:33 -04:00
|
|
|
|
|
|
|
return 0;
|
2016-11-02 23:41:51 +00:00
|
|
|
}
|