f4130a3eb5
These functions have been deprecated since C++11, and were removed in C++17. The proposal P0323 wants to reuse the name std::unexpected for a class template, so we will need to stop defining the current function for C++23 anyway. This marks them as deprecated for C++11 and up, to warn users they won't continue to be available. It disables them for C++17 and up, unless the _GLIBCXX_USE_DEPRECATED macro is defined. The <unwind-cxx.h> header uses std::unexpected_handler in the public API, but since that type is the same as std::terminate_handler we can just use that instead, to avoid warnings about it being deprecated. libstdc++-v3/ChangeLog: * doc/xml/manual/evolution.xml: Document deprecations. * doc/html/*: Regenerate. * libsupc++/exception (unexpected_handler, unexpected) (get_unexpected, set_unexpected): Add deprecated attribute. Do not define without _GLIBCXX_USE_DEPRECATED for C++17 and up. * libsupc++/eh_personality.cc (PERSONALITY_FUNCTION): Disable deprecated warnings. * libsupc++/eh_ptr.cc (std::rethrow_exception): Likewise. * libsupc++/eh_terminate.cc: Likewise. * libsupc++/eh_throw.cc (__cxa_init_primary_exception): Likewise. * libsupc++/unwind-cxx.h (struct __cxa_exception): Use terminate_handler instead of unexpected_handler. (struct __cxa_dependent_exception): Likewise. (__unexpected): Likewise. * testsuite/18_support/headers/exception/synopsis.cc: Add dg-warning for deprecated warning. * testsuite/18_support/exception_ptr/60612-unexpected.cc: Disable deprecated warnings. * testsuite/18_support/set_unexpected.cc: Likewise. * testsuite/18_support/unexpected_handler.cc: Likewise. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/lambda/lambda-eh2.C: Add dg-warning for new deprecation warnings. * g++.dg/cpp0x/noexcept06.C: Likewise. * g++.dg/cpp0x/noexcept07.C: Likewise. * g++.dg/eh/forced3.C: Likewise. * g++.dg/eh/unexpected1.C: Likewise. * g++.old-deja/g++.eh/spec1.C: Likewise. * g++.old-deja/g++.eh/spec2.C: Likewise. * g++.old-deja/g++.eh/spec3.C: Likewise. * g++.old-deja/g++.eh/spec4.C: Likewise. * g++.old-deja/g++.mike/eh33.C: Likewise. * g++.old-deja/g++.mike/eh34.C: Likewise. * g++.old-deja/g++.mike/eh50.C: Likewise. * g++.old-deja/g++.mike/eh51.C: Likewise.
134 lines
3.2 KiB
C++
134 lines
3.2 KiB
C++
// -*- C++ -*- std::terminate, std::unexpected and friends.
|
|
// Copyright (C) 1994-2021 Free Software Foundation, Inc.
|
|
//
|
|
// This file is part of GCC.
|
|
//
|
|
// GCC is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation; either version 3, or (at your option)
|
|
// any later version.
|
|
//
|
|
// GCC is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// Under Section 7 of GPL version 3, you are granted additional
|
|
// permissions described in the GCC Runtime Library Exception, version
|
|
// 3.1, as published by the Free Software Foundation.
|
|
|
|
// You should have received a copy of the GNU General Public License and
|
|
// a copy of the GCC Runtime Library Exception along with this program;
|
|
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
#include "typeinfo"
|
|
#include "exception"
|
|
#include <cstdlib>
|
|
#include "unwind-cxx.h"
|
|
#include "eh_term_handler.h"
|
|
#include <bits/exception_defines.h>
|
|
#include <bits/atomic_lockfree_defines.h>
|
|
|
|
#if ATOMIC_POINTER_LOCK_FREE < 2
|
|
#include <ext/concurrence.h>
|
|
namespace
|
|
{
|
|
__gnu_cxx::__mutex mx;
|
|
}
|
|
#endif
|
|
|
|
using namespace __cxxabiv1;
|
|
|
|
void
|
|
__cxxabiv1::__terminate (std::terminate_handler handler) throw ()
|
|
{
|
|
__try
|
|
{
|
|
handler ();
|
|
std::abort ();
|
|
}
|
|
__catch(...)
|
|
{ std::abort (); }
|
|
}
|
|
|
|
void
|
|
std::terminate () throw()
|
|
{
|
|
__cxxabiv1::__terminate (get_terminate ());
|
|
}
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
void
|
|
__cxxabiv1::__unexpected (std::unexpected_handler handler)
|
|
{
|
|
handler();
|
|
std::terminate ();
|
|
}
|
|
|
|
void
|
|
std::unexpected ()
|
|
{
|
|
__unexpected (get_unexpected ());
|
|
}
|
|
|
|
std::terminate_handler
|
|
std::set_terminate (std::terminate_handler func) throw()
|
|
{
|
|
if (!func)
|
|
func = _GLIBCXX_DEFAULT_TERM_HANDLER;
|
|
|
|
std::terminate_handler old;
|
|
#if ATOMIC_POINTER_LOCK_FREE > 1
|
|
__atomic_exchange (&__terminate_handler, &func, &old, __ATOMIC_ACQ_REL);
|
|
#else
|
|
__gnu_cxx::__scoped_lock l(mx);
|
|
old = __terminate_handler;
|
|
__terminate_handler = func;
|
|
#endif
|
|
return old;
|
|
}
|
|
|
|
std::terminate_handler
|
|
std::get_terminate () noexcept
|
|
{
|
|
std::terminate_handler func;
|
|
#if ATOMIC_POINTER_LOCK_FREE > 1
|
|
__atomic_load (&__terminate_handler, &func, __ATOMIC_ACQUIRE);
|
|
#else
|
|
__gnu_cxx::__scoped_lock l(mx);
|
|
func = __terminate_handler;
|
|
#endif
|
|
return func;
|
|
}
|
|
|
|
std::unexpected_handler
|
|
std::set_unexpected (std::unexpected_handler func) throw()
|
|
{
|
|
if (!func)
|
|
func = std::terminate;
|
|
|
|
std::unexpected_handler old;
|
|
#if ATOMIC_POINTER_LOCK_FREE > 1
|
|
__atomic_exchange (&__unexpected_handler, &func, &old, __ATOMIC_ACQ_REL);
|
|
#else
|
|
__gnu_cxx::__scoped_lock l(mx);
|
|
old = __unexpected_handler;
|
|
__unexpected_handler = func;
|
|
#endif
|
|
return old;
|
|
}
|
|
|
|
std::unexpected_handler
|
|
std::get_unexpected () noexcept
|
|
{
|
|
std::unexpected_handler func;
|
|
#if ATOMIC_POINTER_LOCK_FREE > 1
|
|
__atomic_load (&__unexpected_handler, &func, __ATOMIC_ACQUIRE);
|
|
#else
|
|
__gnu_cxx::__scoped_lock l(mx);
|
|
func = __unexpected_handler;
|
|
#endif
|
|
return func;
|
|
}
|