75 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// UNSUPPORTED: no-exceptions10// <exception>11 12// class nested_exception;13 14// void rethrow_nested [[noreturn]] () const;15 16#include <exception>17#include <cstdlib>18#include <cassert>19 20#include "test_macros.h"21 22class A23{24 int data_;25public:26 explicit A(int data) : data_(data) {}27 28 friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;}29};30 31void go_quietly()32{33 std::exit(0);34}35 36int main(int, char**)37{38 {39 try40 {41 throw A(2);42 assert(false);43 }44 catch (const A&)45 {46 const std::nested_exception e;47 assert(e.nested_ptr() != nullptr);48 try49 {50 e.rethrow_nested();51 assert(false);52 }53 catch (const A& a)54 {55 assert(a == A(2));56 }57 }58 }59 {60 try61 {62 std::set_terminate(go_quietly);63 const std::nested_exception e;64 e.rethrow_nested();65 assert(false);66 }67 catch (...)68 {69 assert(false);70 }71 }72 73 return 0;74}75