]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/language.support/support.exception/except.nested/ctor_copy.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / language.support / support.exception / except.nested / ctor_copy.pass.cpp
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
21 class A
22 {
23     int data_;
24 public:
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
30 int 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 }