1// { dg-options "-std=gnu++11" }
2// { dg-require-atomic-builtins "" }
3
4// Copyright (C) 2009-2015 Free Software Foundation, Inc.
5//
6// This file is part of the GNU ISO C++ Library.  This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 3, or (at your option)
10// any later version.
11
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16
17// You should have received a copy of the GNU General Public License along
18// with this library; see the file COPYING3.  If not see
19// <http://www.gnu.org/licenses/>.
20
21#include <exception>
22#include <testsuite_hooks.h>
23
24struct derived : std::nested_exception { };
25
26struct not_derived { virtual ~not_derived() noexcept; };
27inline not_derived::~not_derived() noexcept = default;
28
29struct uninheritable final { };
30
31void test01()
32{
33  bool test __attribute__((unused)) = false;
34
35  try
36  {
37    std::throw_with_nested(derived());
38  }
39  catch (const std::nested_exception& e)
40  {
41    VERIFY( e.nested_ptr() == 0 );
42    try
43    {
44      throw;
45    }
46    catch (const derived&)
47    {
48      test = true;
49    }
50  }
51  VERIFY( test );
52}
53
54void test02()
55{
56  bool test __attribute__((unused)) = false;
57
58  try
59  {
60    std::throw_with_nested(not_derived());
61  }
62  catch (const std::nested_exception& e)
63  {
64    VERIFY( e.nested_ptr() == 0 );
65    try
66    {
67      throw;
68    }
69    catch (const not_derived&)
70    {
71      test = true;
72    }
73  }
74  VERIFY( test );
75}
76
77void test03()
78{
79  bool test __attribute__((unused)) = false;
80
81  try
82  {
83    std::throw_with_nested(uninheritable());
84  }
85  catch (const std::nested_exception&)
86  {
87    VERIFY( false );
88  }
89  catch(const uninheritable&)
90  {
91    test = true;
92  }
93  VERIFY( test );
94}
95
96int main()
97{
98  test01();
99  test02();
100  test03();
101  return 0;
102}
103