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 | |
Asiri Rathnayake | cc2e93c | 2015-11-10 11:41:22 +0000 | [diff] [blame] | 10 | // XFAIL: libcpp-no-exceptions |
Howard Hinnant | ed2c291 | 2010-05-27 17:06:52 +0000 | [diff] [blame] | 11 | // <exception> |
| 12 | |
| 13 | // class nested_exception; |
| 14 | |
| 15 | // nested_exception() throw(); |
| 16 | |
| 17 | #include <exception> |
| 18 | #include <cassert> |
| 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() |
| 30 | { |
| 31 | { |
| 32 | std::nested_exception e; |
| 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 e; |
| 44 | assert(e.nested_ptr() != nullptr); |
| 45 | try |
| 46 | { |
| 47 | rethrow_exception(e.nested_ptr()); |
| 48 | assert(false); |
| 49 | } |
| 50 | catch (const A& a) |
| 51 | { |
| 52 | assert(a == A(2)); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | } |