OSDN Git Service

2011-12-06 Paolo Carlini <paolo.carlini@oracle.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 18_support / nested_exception / throw_with_nested.cc
1 // { dg-options "-std=gnu++0x" }
2 // { dg-require-atomic-builtins "" }
3
4 // Copyright (C) 2009, 2010, 2011 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
24 struct derived : std::nested_exception { };
25
26 struct not_derived { virtual ~not_derived() noexcept; };
27 inline not_derived::~not_derived() noexcept = default;
28
29 void test01() 
30 {
31   bool test __attribute__((unused)) = false;
32
33   try
34   {
35     std::throw_with_nested(derived());
36   }
37   catch (const std::nested_exception& e)
38   {
39     VERIFY( e.nested_ptr() == 0 );
40     try
41     {
42       throw;
43     }
44     catch (const derived&)
45     {
46       test = true;
47     }
48   }
49   VERIFY( test );
50 }
51
52 void test02() 
53 {
54   bool test __attribute__((unused)) = false;
55
56   try
57   {
58     std::throw_with_nested(not_derived());
59   }
60   catch (const std::nested_exception& e)
61   {
62     VERIFY( e.nested_ptr() == 0 );
63     try
64     {
65       throw;
66     }
67     catch (const not_derived&)
68     {
69       test = true;
70     }
71   }
72   VERIFY( test );
73 }
74
75 int main()
76 {
77   test01();
78   test02();
79   return 0;
80 }