1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 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#include "test_macros.h" 20 21class A 22{ 23 int data_; 24public: 25 explicit A(int data) : data_(data) {} 26 27 friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;} 28}; 29 30int main() 31{ 32 { 33 std::nested_exception e0; 34 std::nested_exception 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 = e0; 48 assert(e.nested_ptr() != nullptr); 49 try 50 { 51 rethrow_exception(e.nested_ptr()); 52 assert(false); 53 } 54 catch (const A& a) 55 { 56 assert(a == A(2)); 57 } 58 } 59 } 60#endif 61} 62