[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / libcxx / test / std / language.support / support.exception / except.nested / rethrow_if_nested.pass.cpp
blob01ef7ade7c2b6d649daa21158c68562c848569b1
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 // UNSUPPORTED: libcpp-no-exceptions
11 // This test fails due to a stack overflow
12 // XFAIL: LIBCXX-WINDOWS-FIXME
14 // <exception>
16 // class nested_exception;
18 // template <class E> void rethrow_if_nested(const E& e);
20 #include <exception>
21 #include <cstdlib>
22 #include <cassert>
24 #include "test_macros.h"
26 class A
28 int data_;
29 public:
30 explicit A(int data) : data_(data) {}
31 virtual ~A() TEST_NOEXCEPT {}
33 friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;}
36 class B
37 : public std::nested_exception,
38 public A
40 public:
41 explicit B(int data) : A(data) {}
42 B(const B& b) : A(b) {}
45 class C
47 public:
48 virtual ~C() {}
49 C * operator&() const { assert(false); return nullptr; } // should not be called
52 class D : private std::nested_exception {};
55 class E1 : public std::nested_exception {};
56 class E2 : public std::nested_exception {};
57 class E : public E1, public E2 {};
59 int main(int, char**)
62 try
64 A a(3); // not a polymorphic type --> no effect
65 std::rethrow_if_nested(a);
66 assert(true);
68 catch (...)
70 assert(false);
74 try
76 D s; // inaccessible base class --> no effect
77 std::rethrow_if_nested(s);
78 assert(true);
80 catch (...)
82 assert(false);
86 try
88 E s; // ambiguous base class --> no effect
89 std::rethrow_if_nested(s);
90 assert(true);
92 catch (...)
94 assert(false);
98 try
100 throw B(5);
102 catch (const B& b)
106 throw b;
108 catch (const A& a)
112 std::rethrow_if_nested(a);
113 assert(false);
115 catch (const B& b2)
117 assert(b2 == B(5));
125 std::rethrow_if_nested(C());
126 assert(true);
128 catch (...)
130 assert(false);
135 return 0;