Add testcase of PR c++/92542, already fixed.
[official-gcc.git] / libstdc++-v3 / testsuite / 18_support / set_unexpected.cc
blob7e330afe48adf3e54cb565ed936850ac1543fa32
1 // Copyright (C) 2019-2020 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_only || c++14_only } } }
21 #include <exception>
22 #include <testsuite_hooks.h>
24 void unex_handler() { __builtin_abort(); }
26 void
27 test01()
29 const std::unexpected_handler orig = std::get_unexpected();
30 VERIFY( orig == std::terminate ); // GNU-specific behaviour
32 std::unexpected_handler prev = std::set_unexpected(unex_handler);
33 VERIFY( std::get_unexpected() == unex_handler );
34 VERIFY( prev == orig );
36 prev = std::set_unexpected(orig);
37 VERIFY( std::get_unexpected() == orig );
38 VERIFY( prev == unex_handler );
41 void
42 test02()
44 // PR libstdc++/90682
45 std::set_unexpected(0); // Undefined in C++98, unspecified in C++11 and C++14
46 const std::unexpected_handler dfault = std::get_unexpected();
47 VERIFY( dfault == std::terminate ); // GNU-specific behaviour
48 const std::unexpected_handler prev = std::set_unexpected(0);
49 VERIFY( prev == dfault );
52 int
53 main()
55 test01();
56 test02();