brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · ec40071 Raw
73 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// Can a noexcept member function pointer be caught by a non-noexcept catch clause?10// UNSUPPORTED: c++03, c++11, c++1411// UNSUPPORTED: no-exceptions12 13// GCC supports noexcept function types but this test still fails.14// This is likely a bug in their implementation. Investigation needed.15// XFAIL: gcc-14, gcc-1516 17#include <cassert>18 19struct X {20  template<bool Noexcept> void f() noexcept(Noexcept) {}21};22template<bool Noexcept> using FnType = void (X::*)() noexcept(Noexcept);23 24template<bool ThrowNoexcept, bool CatchNoexcept>25void check()26{27    try28    {29        auto p = &X::f<ThrowNoexcept>;30        throw p;31        assert(false);32    }33    catch (FnType<CatchNoexcept> p)34    {35        assert(ThrowNoexcept || !CatchNoexcept);36        assert(p == &X::f<ThrowNoexcept>);37    }38    catch (...)39    {40        assert(!ThrowNoexcept && CatchNoexcept);41    }42}43 44void check_deep() {45    FnType<true> p = &X::f<true>;46    try47    {48        throw &p;49    }50    catch (FnType<false> *q)51    {52        assert(false);53    }54    catch (FnType<true> *q)55    {56    }57    catch (...)58    {59        assert(false);60    }61}62 63int main(int, char**)64{65    check<false, false>();66    check<false, true>();67    check<true, false>();68    check<true, true>();69    check_deep();70 71    return 0;72}73