| 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() throw(); |
| 14 | |
| 15 | #include <exception> |
| 16 | #include <cassert> |
| 17 | |
| 18 | #include "test_macros.h" |
| 19 | |
| 20 | class A |
| 21 | { |
| 22 | int data_; |
| 23 | public: |
| 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 | |
| 29 | int main(int, char**) |
| 30 | { |
| 31 | { |
| 32 | std::nested_exception e; |
| 33 | assert(e.nested_ptr() == nullptr); |
| 34 | } |
| 35 | #ifndef TEST_HAS_NO_EXCEPTIONS |
| 36 | { |
| 37 | try |
| 38 | { |
| 39 | throw A(2); |
| 40 | assert(false); |
| 41 | } |
| 42 | catch (const A&) |
| 43 | { |
| 44 | std::nested_exception e; |
| 45 | assert(e.nested_ptr() != nullptr); |
| 46 | try |
| 47 | { |
| 48 | std::rethrow_exception(e.nested_ptr()); |
| 49 | assert(false); |
| 50 | } |
| 51 | catch (const A& a) |
| 52 | { |
| 53 | assert(a == A(2)); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | #endif |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |