]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/language.support/support.exception/except.nested/ctor_default.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / language.support / support.exception / except.nested / ctor_default.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() throw();
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 e;
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 e;
46             assert(e.nested_ptr() != nullptr);
47             try
48             {
49                 rethrow_exception(e.nested_ptr());
50                 assert(false);
51             }
52             catch (const A& a)
53             {
54                 assert(a == A(2));
55             }
56         }
57     }
58 #endif
59 }