1 // Copyright (C) 2019-2021 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. 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 18 // { dg-options "-std=gnu++11" } 19 // { dg-do run { target c++11 } } 20 21 #include <exception> 22 #include <testsuite_hooks.h> 23 term_handler()24void term_handler() { __builtin_abort(); } 25 26 void test01()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 41 void test02()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 52 int main()53main() 54 { 55 test01(); 56 test02(); 57 } 58