Howard Hinnant | ed2c291 | 2010-05-27 17:06:52 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | ed2c291 | 2010-05-27 17:06:52 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Howard Hinnant | ed2c291 | 2010-05-27 17:06:52 +0000 | [diff] [blame] | 10 | // <exception> |
| 11 | |
| 12 | // class nested_exception; |
| 13 | |
| 14 | // nested_exception(const nested_exception&) throw() = default; |
| 15 | |
| 16 | #include <exception> |
| 17 | #include <cassert> |
| 18 | |
| 19 | class A |
| 20 | { |
| 21 | int data_; |
| 22 | public: |
| 23 | explicit A(int data) : data_(data) {} |
| 24 | |
| 25 | friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;} |
| 26 | }; |
| 27 | |
| 28 | int main() |
| 29 | { |
| 30 | { |
| 31 | std::nested_exception e0; |
| 32 | std::nested_exception e = e0; |
| 33 | assert(e.nested_ptr() == nullptr); |
| 34 | } |
| 35 | { |
| 36 | try |
| 37 | { |
| 38 | throw A(2); |
| 39 | assert(false); |
| 40 | } |
| 41 | catch (const A&) |
| 42 | { |
| 43 | std::nested_exception e0; |
| 44 | std::nested_exception e = e0; |
| 45 | assert(e.nested_ptr() != nullptr); |
| 46 | try |
| 47 | { |
| 48 | rethrow_exception(e.nested_ptr()); |
| 49 | assert(false); |
| 50 | } |
| 51 | catch (const A& a) |
| 52 | { |
| 53 | assert(a == A(2)); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | } |