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-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <exception>
10
11// class nested_exception;
12
13// nested_exception& operator=(const nested_exception&) throw() = default;
14
15#include <exception>
16#include <cassert>
17
18#include "test_macros.h"
19
20class A
21{
22 int data_;
23public:
24 explicit A(int data) : data_(data) {}
25
26 friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;}
27};
28
29int main(int, char**)
30{
31 {
32 std::nested_exception e0;
33 std::nested_exception e;
34 e = e0;
35 assert(e.nested_ptr() == nullptr);
36 }
37#ifndef TEST_HAS_NO_EXCEPTIONS
38 {
39 try
40 {
41 throw A(2);
42 assert(false);
43 }
44 catch (const A&)
45 {
46 std::nested_exception e0;
47 std::nested_exception e;
48 e = e0;
49 assert(e.nested_ptr() != nullptr);
50 try
51 {
52 std::rethrow_exception(e.nested_ptr());
53 assert(false);
54 }
55 catch (const A& a)
56 {
57 assert(a == A(2));
58 }
59 }
60 }
61#endif
62
63 return 0;
64}
65

source code of libcxx/test/std/language.support/support.exception/except.nested/assign.pass.cpp