1// { dg-options "-std=gnu++0x" }
2// { dg-require-atomic-builtins "" }
3
4// 2008-05-25  Sebastian Redl  <sebastian.redl@getdesigned.at>
5
6// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
7//
8// This file is part of the GNU ISO C++ Library.  This library is free
9// software; you can redistribute it and/or modify it under the
10// terms of the GNU General Public License as published by the
11// Free Software Foundation; either version 3, or (at your option)
12// any later version.
13
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17// GNU General Public License for more details.
18
19// You should have received a copy of the GNU General Public License along
20// with this library; see the file COPYING3.  If not see
21// <http://www.gnu.org/licenses/>.
22
23// rethrow_exception() and preservation of data
24
25#include <exception>
26#include <typeinfo>
27#include <cstring>
28#include <stdexcept>
29#include <testsuite_hooks.h>
30
31void test01()
32{
33  bool test __attribute__((unused)) = true;
34  using namespace std;
35
36  try {
37    rethrow_exception(copy_exception(0));
38  } catch(...) {
39  }
40}
41
42void test02()
43{
44  bool test __attribute__((unused)) = true;
45  using namespace std;
46
47  try {
48    rethrow_exception(copy_exception(runtime_error("test")));
49  } catch(exception &e) {
50    VERIFY( typeid(e) == typeid(runtime_error) );
51    VERIFY( strcmp(e.what(), "test") == 0 );
52  }
53}
54
55void test03()
56{
57  bool test __attribute__((unused)) = true;
58  using namespace std;
59
60  exception_ptr ep;
61  try {
62    throw 0;
63  } catch(...) {
64    ep = current_exception();
65  }
66  try {
67    rethrow_exception(ep);
68  } catch(...) {
69  }
70}
71
72void test04()
73{
74  bool test __attribute__((unused)) = true;
75  using namespace std;
76
77  // Weave the exceptions in an attempt to confuse the machinery.
78  try {
79    throw 0;
80  } catch(...) {
81    exception_ptr ep1 = current_exception();
82    try {
83      throw 1;
84    } catch(...) {
85      exception_ptr ep2 = current_exception();
86      try {
87        rethrow_exception(ep1);
88      } catch(...) {
89        try {
90          rethrow_exception(ep2);
91        } catch(...) {
92          try {
93            rethrow_exception(ep1);
94          } catch(...) {
95          }
96          try {
97            rethrow_exception(ep2);
98          } catch(...) {
99          }
100        }
101      }
102    }
103  }
104}
105
106int main()
107{
108  test01();
109  test02();
110  test03();
111  test04();
112
113  return 0;
114}
115