1 // Copyright 2018 Peter Dimov
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 //
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7
8 #if defined(_MSC_VER)
9 # pragma warning(disable: 4702) // unreachable code
10 #endif
11
12 #if defined(__clang__)
13 # pragma clang diagnostic ignored "-Wunknown-pragmas"
14 # pragma clang diagnostic ignored "-Wunknown-warning-option"
15 # pragma clang diagnostic ignored "-Wpotentially-evaluated-expression"
16 # pragma clang diagnostic ignored "-Wdelete-non-abstract-non-virtual-dtor"
17 # pragma clang diagnostic ignored "-Wunused-parameter"
18 #endif
19
20 #include <boost/throw_exception.hpp>
21 #include <boost/exception_ptr.hpp>
22 #include <boost/core/lightweight_test.hpp>
23
24 class my_exception: public std::exception
25 {
26 };
27
28 class my_exception2: public std::exception, public boost::exception
29 {
30 };
31
32 class my_exception3: public std::exception, public virtual boost::exception
33 {
34 };
35
main()36 int main()
37 {
38 try
39 {
40 boost::throw_exception( my_exception() );
41 }
42 catch( ... )
43 {
44 boost::exception_ptr p = boost::current_exception();
45
46 BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception );
47 BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
48 }
49
50 try
51 {
52 boost::throw_exception( my_exception2() );
53 }
54 catch( ... )
55 {
56 boost::exception_ptr p = boost::current_exception();
57
58 BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception2 );
59 BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
60 }
61
62 try
63 {
64 boost::throw_exception( my_exception3() );
65 }
66 catch( ... )
67 {
68 boost::exception_ptr p = boost::current_exception();
69
70 BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception3 );
71 BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
72 }
73
74 try
75 {
76 BOOST_THROW_EXCEPTION( my_exception() );
77 }
78 catch( ... )
79 {
80 boost::exception_ptr p = boost::current_exception();
81
82 BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception );
83 BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
84 }
85
86 try
87 {
88 BOOST_THROW_EXCEPTION( my_exception2() );
89 }
90 catch( ... )
91 {
92 boost::exception_ptr p = boost::current_exception();
93
94 BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception2 );
95 BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
96 }
97
98 try
99 {
100 BOOST_THROW_EXCEPTION( my_exception3() );
101 }
102 catch( ... )
103 {
104 boost::exception_ptr p = boost::current_exception();
105
106 BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception3 );
107 BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
108 }
109
110 return boost::report_errors();
111 }
112