Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / language.support / support.exception / except.nested / assign.pass.cpp
blobc37a6226c879b066464148a50c8a906faf0d7c2b
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 //===----------------------------------------------------------------------===//
9 // <exception>
11 // class nested_exception;
13 // nested_exception& operator=(const nested_exception&) throw() = default;
15 #include <exception>
16 #include <cassert>
18 #include "test_macros.h"
20 class A
22 int data_;
23 public:
24 explicit A(int data) : data_(data) {}
26 friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;}
29 int main(int, char**)
32 std::nested_exception e0;
33 std::nested_exception e;
34 e = e0;
35 assert(e.nested_ptr() == nullptr);
37 #ifndef TEST_HAS_NO_EXCEPTIONS
39 try
41 throw A(2);
42 assert(false);
44 catch (const A&)
46 std::nested_exception e0;
47 std::nested_exception e;
48 e = e0;
49 assert(e.nested_ptr() != nullptr);
50 try
52 std::rethrow_exception(e.nested_ptr());
53 assert(false);
55 catch (const A& a)
57 assert(a == A(2));
61 #endif
63 return 0;