]> gcc.gnu.org Git - gcc.git/blame - libstdc++-v3/testsuite/18_support/set_terminate.cc
libstdc++: Ensure c++NN effective-target present in more tests
[gcc.git] / libstdc++-v3 / testsuite / 18_support / set_terminate.cc
CommitLineData
8d9254fc 1// Copyright (C) 2019-2020 Free Software Foundation, Inc.
3228289e
JW
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.
8
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.
13
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/>.
17
061a7450 18// { dg-options "-std=gnu++11" }
9d613af2 19// { dg-do run { target c++11 } }
3228289e
JW
20
21#include <exception>
22#include <testsuite_hooks.h>
23
24void term_handler() { __builtin_abort(); }
25
26void
27test01()
28{
29 const std::terminate_handler orig = std::get_terminate();
30 VERIFY( orig != 0 ); // GNU-specific behaviour
31
32 std::terminate_handler prev = std::set_terminate(term_handler);
33 VERIFY( std::get_terminate() == term_handler );
34 VERIFY( prev == orig );
35
36 prev = std::set_terminate(orig);
37 VERIFY( std::get_terminate() == orig );
38 VERIFY( prev == term_handler );
39}
40
41void
42test02()
43{
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 );
50}
51
52int
53main()
54{
55 test01();
56 test02();
57}
This page took 0.176932 seconds and 5 git commands to generate.