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