| 1 |
// Copyright (C) 2019-2025 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 -Wno-deprecated-declarations" } |
| 19 |
// { dg-do run { target { c++11_only || c++14_only } } } |
| 20 |
|
| 21 |
#include <exception> |
| 22 |
#include <testsuite_hooks.h> |
| 23 |
|
| 24 |
void unex_handler() { __builtin_abort(); } |
| 25 |
|
| 26 |
void |
| 27 |
test01() |
| 28 |
{ |
| 29 |
const std::unexpected_handler orig = std::get_unexpected(); |
| 30 |
VERIFY( orig == std::terminate ); // GNU-specific behaviour |
| 31 |
|
| 32 |
std::unexpected_handler prev = std::set_unexpected(unex_handler); |
| 33 |
VERIFY( std::get_unexpected() == unex_handler ); |
| 34 |
VERIFY( prev == orig ); |
| 35 |
|
| 36 |
prev = std::set_unexpected(orig); |
| 37 |
VERIFY( std::get_unexpected() == orig ); |
| 38 |
VERIFY( prev == unex_handler ); |
| 39 |
} |
| 40 |
|
| 41 |
void |
| 42 |
test02() |
| 43 |
{ |
| 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 ); |
| 50 |
} |
| 51 |
|
| 52 |
int |
| 53 |
main() |
| 54 |
{ |
| 55 |
test01(); |
| 56 |
test02(); |
| 57 |
} |