Add documentation for musttail attribute
[official-gcc.git] / libstdc++-v3 / testsuite / 18_support / set_terminate.cc
blob9eccc4cc802882b219c3b83a4de021ea52d4a2ab
1 // Copyright (C) 2019-2024 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-std=gnu++11" }
19 // { dg-do run { target c++11 } }
21 #include <exception>
22 #include <testsuite_hooks.h>
24 void term_handler() { __builtin_abort(); }
26 void
27 test01()
29 const std::terminate_handler orig = std::get_terminate();
30 VERIFY( orig != 0 ); // GNU-specific behaviour
32 std::terminate_handler prev = std::set_terminate(term_handler);
33 VERIFY( std::get_terminate() == term_handler );
34 VERIFY( prev == orig );
36 prev = std::set_terminate(orig);
37 VERIFY( std::get_terminate() == orig );
38 VERIFY( prev == term_handler );
41 void
42 test02()
44 // PR libstdc++/90682
45 std::set_terminate(0); // Undefined in C++98, unspecified in C++11 and later
46 const std::terminate_handler dfault = std::get_terminate();
47 VERIFY( dfault != 0 ); // GNU-specific behaviour
48 const std::terminate_handler prev = std::set_terminate(0);
49 VERIFY( prev == dfault );
52 int
53 main()
55 test01();
56 test02();