From f4130a3eb545ab1aaf3ecb44f3d06b43e3751e04 Mon Sep 17 00:00:00 2001
From: Jonathan Wakely
Date: Wed, 29 Sep 2021 21:18:42 +0100
Subject: [PATCH] libstdc++: Deprecate std::unexpected and handler functions
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 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.
---
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-eh2.C | 2 +-
gcc/testsuite/g++.dg/cpp0x/noexcept06.C | 2 +-
gcc/testsuite/g++.dg/cpp0x/noexcept07.C | 2 +-
gcc/testsuite/g++.dg/eh/forced3.C | 2 +-
gcc/testsuite/g++.dg/eh/unexpected1.C | 2 +-
gcc/testsuite/g++.old-deja/g++.eh/spec1.C | 2 +-
gcc/testsuite/g++.old-deja/g++.eh/spec2.C | 2 +-
gcc/testsuite/g++.old-deja/g++.eh/spec3.C | 2 +-
gcc/testsuite/g++.old-deja/g++.eh/spec4.C | 2 +-
gcc/testsuite/g++.old-deja/g++.mike/eh33.C | 2 +-
gcc/testsuite/g++.old-deja/g++.mike/eh34.C | 2 +-
gcc/testsuite/g++.old-deja/g++.mike/eh50.C | 2 +-
gcc/testsuite/g++.old-deja/g++.mike/eh51.C | 2 +-
libstdc++-v3/doc/html/manual/api.html | 4 ++++
libstdc++-v3/doc/xml/manual/evolution.xml | 6 +++++
libstdc++-v3/libsupc++/eh_personality.cc | 9 +++++---
libstdc++-v3/libsupc++/eh_ptr.cc | 3 +++
libstdc++-v3/libsupc++/eh_terminate.cc | 1 +
libstdc++-v3/libsupc++/eh_throw.cc | 3 +++
libstdc++-v3/libsupc++/exception | 27 +++++++++++++++++-----
libstdc++-v3/libsupc++/unwind-cxx.h | 8 +++----
.../18_support/exception_ptr/60612-unexpected.cc | 1 +
.../18_support/headers/exception/synopsis.cc | 2 +-
.../testsuite/18_support/set_unexpected.cc | 2 +-
.../testsuite/18_support/unexpected_handler.cc | 1 +
25 files changed, 65 insertions(+), 28 deletions(-)
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-eh2.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-eh2.C
index 3fb50df..eddd3c9 100644
--- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-eh2.C
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-eh2.C
@@ -7,7 +7,7 @@
int main( void )
{
- std::set_unexpected( []{ throw 0; } );
+ std::set_unexpected( []{ throw 0; } ); // { dg-warning "deprecated" }
try
{
[]() throw( int ) { throw nullptr; }(); // { dg-warning "deprecated" }
diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept06.C b/gcc/testsuite/g++.dg/cpp0x/noexcept06.C
index ad9edec..ea15223 100644
--- a/gcc/testsuite/g++.dg/cpp0x/noexcept06.C
+++ b/gcc/testsuite/g++.dg/cpp0x/noexcept06.C
@@ -23,7 +23,7 @@ void f() noexcept
int main()
{
- std::set_unexpected (my_unexpected);
+ std::set_unexpected (my_unexpected); // { dg-warning "deprecated" }
std::set_terminate (my_terminate);
f();
return 1;
diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept07.C b/gcc/testsuite/g++.dg/cpp0x/noexcept07.C
index de16e01..dbcc23e 100644
--- a/gcc/testsuite/g++.dg/cpp0x/noexcept07.C
+++ b/gcc/testsuite/g++.dg/cpp0x/noexcept07.C
@@ -18,7 +18,7 @@ void f() throw()
int main()
{
- std::set_unexpected (my_unexpected);
+ std::set_unexpected (my_unexpected); // { dg-warning "deprecated" }
f();
return 1;
}
diff --git a/gcc/testsuite/g++.dg/eh/forced3.C b/gcc/testsuite/g++.dg/eh/forced3.C
index 9e92daf..51cbc8d 100644
--- a/gcc/testsuite/g++.dg/eh/forced3.C
+++ b/gcc/testsuite/g++.dg/eh/forced3.C
@@ -53,7 +53,7 @@ doit () throw()
int main()
{
- std::set_unexpected (handle_unexpected);
+ std::set_unexpected (handle_unexpected); // { dg-warning "deprecated" "" { target c++11 } }
doit ();
abort ();
}
diff --git a/gcc/testsuite/g++.dg/eh/unexpected1.C b/gcc/testsuite/g++.dg/eh/unexpected1.C
index cd5585f..973ebea 100644
--- a/gcc/testsuite/g++.dg/eh/unexpected1.C
+++ b/gcc/testsuite/g++.dg/eh/unexpected1.C
@@ -30,7 +30,7 @@ doit () throw (Two) // { dg-warning "deprecated" "" { target { c++11 } } }
int main ()
{
- std::set_unexpected (handle_unexpected);
+ std::set_unexpected (handle_unexpected); // { dg-warning "deprecated" "" { target { c++11 } } }
try
{
diff --git a/gcc/testsuite/g++.old-deja/g++.eh/spec1.C b/gcc/testsuite/g++.old-deja/g++.eh/spec1.C
index ea32045..3c832fd 100644
--- a/gcc/testsuite/g++.old-deja/g++.eh/spec1.C
+++ b/gcc/testsuite/g++.old-deja/g++.eh/spec1.C
@@ -17,7 +17,7 @@ f () throw (char, int, std::bad_exception) // { dg-warning "deprecated" "" { tar
int main ()
{
std::set_terminate (my_term);
- std::set_unexpected (my_unexp);
+ std::set_unexpected (my_unexp); // { dg-warning "deprecated" "" { target c++11 } }
try
{
diff --git a/gcc/testsuite/g++.old-deja/g++.eh/spec2.C b/gcc/testsuite/g++.old-deja/g++.eh/spec2.C
index d1aa698..2f7556b 100644
--- a/gcc/testsuite/g++.old-deja/g++.eh/spec2.C
+++ b/gcc/testsuite/g++.old-deja/g++.eh/spec2.C
@@ -17,7 +17,7 @@ f () throw (int, std::bad_exception) // { dg-warning "deprecated" "" { target c+
int main ()
{
std::set_terminate (my_term);
- std::set_unexpected (my_unexp);
+ std::set_unexpected (my_unexp); // { dg-warning "deprecated" "" { target c++11 } }
try
{
diff --git a/gcc/testsuite/g++.old-deja/g++.eh/spec3.C b/gcc/testsuite/g++.old-deja/g++.eh/spec3.C
index 1d57df3..278de2e 100644
--- a/gcc/testsuite/g++.old-deja/g++.eh/spec3.C
+++ b/gcc/testsuite/g++.old-deja/g++.eh/spec3.C
@@ -17,7 +17,7 @@ f () throw (std::bad_exception) // { dg-warning "deprecated" "" { target c++11
int main ()
{
std::set_terminate (my_term);
- std::set_unexpected (my_unexp);
+ std::set_unexpected (my_unexp); // { dg-warning "deprecated" "" { target c++11 } }
try
{
diff --git a/gcc/testsuite/g++.old-deja/g++.eh/spec4.C b/gcc/testsuite/g++.old-deja/g++.eh/spec4.C
index e102239..d5d4896 100644
--- a/gcc/testsuite/g++.old-deja/g++.eh/spec4.C
+++ b/gcc/testsuite/g++.old-deja/g++.eh/spec4.C
@@ -17,7 +17,7 @@ f () throw (short) // { dg-warning "deprecated" "" { target c++11 } }
int main ()
{
std::set_terminate (my_term);
- std::set_unexpected (my_unexp);
+ std::set_unexpected (my_unexp); // { dg-warning "deprecated" "" { target c++11 } }
try
{
diff --git a/gcc/testsuite/g++.old-deja/g++.mike/eh33.C b/gcc/testsuite/g++.old-deja/g++.mike/eh33.C
index cffb0c4..8d50f73 100644
--- a/gcc/testsuite/g++.old-deja/g++.mike/eh33.C
+++ b/gcc/testsuite/g++.old-deja/g++.mike/eh33.C
@@ -11,7 +11,7 @@ void my_unexpected() {
void foo() throw (int) { throw "Hi"; } // { dg-warning "deprecated" "" { target c++11 } }
int main() {
- std::set_unexpected (my_unexpected);
+ std::set_unexpected (my_unexpected); // { dg-warning "deprecated" "" { target c++11 } }
try {
foo();
} catch (int i) {
diff --git a/gcc/testsuite/g++.old-deja/g++.mike/eh34.C b/gcc/testsuite/g++.old-deja/g++.mike/eh34.C
index 3218dd9..36512ae 100644
--- a/gcc/testsuite/g++.old-deja/g++.mike/eh34.C
+++ b/gcc/testsuite/g++.old-deja/g++.mike/eh34.C
@@ -11,7 +11,7 @@ void my_unexpected() {
void foo() throw () { throw "Hi"; }
int main() {
- std::set_unexpected (my_unexpected);
+ std::set_unexpected (my_unexpected); // { dg-warning "deprecated" "" { target c++11 } }
foo();
return 1;
}
diff --git a/gcc/testsuite/g++.old-deja/g++.mike/eh50.C b/gcc/testsuite/g++.old-deja/g++.mike/eh50.C
index 028a2de..2507cf2 100644
--- a/gcc/testsuite/g++.old-deja/g++.mike/eh50.C
+++ b/gcc/testsuite/g++.old-deja/g++.mike/eh50.C
@@ -12,7 +12,7 @@ template void foo(T) throw (int) { throw "Hi"; } // { dg-warning "depr
int
main() {
- std::set_unexpected (my_unexpected);
+ std::set_unexpected (my_unexpected); // { dg-warning "deprecated" "" { target c++11 } }
try {
foo(1);
} catch (int i) {
diff --git a/gcc/testsuite/g++.old-deja/g++.mike/eh51.C b/gcc/testsuite/g++.old-deja/g++.mike/eh51.C
index 428635b..d1902f0 100644
--- a/gcc/testsuite/g++.old-deja/g++.mike/eh51.C
+++ b/gcc/testsuite/g++.old-deja/g++.mike/eh51.C
@@ -12,7 +12,7 @@ template void foo(T) throw (T) { throw "Hi"; } // { dg-warning "deprec
int
main() {
- std::set_unexpected (my_unexpected);
+ std::set_unexpected (my_unexpected); // { dg-warning "deprecated" "" { target c++11 } }
try {
foo(1);
} catch (int i) {
diff --git a/libstdc++-v3/doc/html/manual/api.html b/libstdc++-v3/doc/html/manual/api.html
index 376a403..3281078 100644
--- a/libstdc++-v3/doc/html/manual/api.html
+++ b/libstdc++-v3/doc/html/manual/api.html
@@ -440,4 +440,8 @@ now defaults to zero.
The std::random_shuffle
algorithms are deprecated
for C++14 and later. The C++11 std::shuffle
algorithm
can be used instead.
+
+The std::unexpected
function and related typedef and
+accessors for the unexpected handler are deprecated for C++11 and later.
+Dynamic exception specifications should be replaced with noexcept
.