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