public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Deprecate std::unexpected and handler functions
@ 2021-11-03  0:18 Jonathan Wakely
  2021-11-04 20:54 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Wakely @ 2021-11-03  0:18 UTC (permalink / raw)
  To: libstdc++, gcc-patches; +Cc: Jason Merrill

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.

Tested x86_64-linux.

Are the changes to g++ tests OK for trunk?


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.
---
 .../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 +++---
 .../exception_ptr/60612-unexpected.cc         |  1 +
 .../18_support/headers/exception/synopsis.cc  |  2 +-
 .../testsuite/18_support/set_unexpected.cc    |  2 +-
 .../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 3fb50df3f01..eddd3c9dcc5 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 ad9edec796b..ea152237d54 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 de16e016ff4..dbcc23e9610 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 9e92dafb08f..51cbc8de8ba 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 cd5585face8..973ebeacd03 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 ea320451179..3c832fd2105 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 d1aa6984f9f..2f7556be44d 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 1d57df3c335..278de2ef9f4 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 e102239ed89..d5d48968ff9 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 cffb0c48cda..8d50f73a475 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 3218dd9ef3e..36512ae6ab2 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 028a2de0c23..2507cf2e48c 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 <class T> 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 428635b175d..d1902f08106 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 <class T> 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 376a4035fa6..32810788bf2 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 <code class="function">std::random_shuffle</code> algorithms are deprecated
 for C++14 and later. The C++11 <code class="function">std::shuffle</code> algorithm
 can be used instead.
+</p><p>
+The <code class="function">std::unexpected</code> function and related typedef and
+accessors for the unexpected handler are deprecated for C++11 and later.
+Dynamic exception specifications should be replaced with <code class="code">noexcept</code>.
 </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="abi.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="appendix_porting.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="backwards.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ABI Policy and Guidelines </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> Backwards Compatibility</td></tr></table></div></body></html>
\ No newline at end of file
diff --git a/libstdc++-v3/doc/xml/manual/evolution.xml b/libstdc++-v3/doc/xml/manual/evolution.xml
index 59b71b04442..9aef84a0933 100644
--- a/libstdc++-v3/doc/xml/manual/evolution.xml
+++ b/libstdc++-v3/doc/xml/manual/evolution.xml
@@ -1027,6 +1027,12 @@ for C++14 and later. The C++11 <function>std::shuffle</function> algorithm
 can be used instead.
 </para>
 
+<para>
+The <function>std::unexpected</function> function and related typedef and
+accessors for the unexpected handler are deprecated for C++11 and later.
+Dynamic exception specifications should be replaced with <code>noexcept</code>.
+</para>
+
 </section>
 
 </section>
diff --git a/libstdc++-v3/libsupc++/eh_personality.cc b/libstdc++-v3/libsupc++/eh_personality.cc
index 33c3cc32fb5..edd5f6a1a77 100644
--- a/libstdc++-v3/libsupc++/eh_personality.cc
+++ b/libstdc++-v3/libsupc++/eh_personality.cc
@@ -673,10 +673,13 @@ PERSONALITY_FUNCTION (int version,
 	std::terminate ();
       else if (handler_switch_value < 0)
 	{
-	  __try 
-	    { std::unexpected (); } 
-	  __catch(...) 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+	  __try
+	    { std::unexpected (); }
+	  __catch(...)
 	    { std::terminate (); }
+#pragma GCC diagnostic pop
 	}
     }
   else
diff --git a/libstdc++-v3/libsupc++/eh_ptr.cc b/libstdc++-v3/libsupc++/eh_ptr.cc
index 5c4685606fe..9f47b666341 100644
--- a/libstdc++-v3/libsupc++/eh_ptr.cc
+++ b/libstdc++-v3/libsupc++/eh_ptr.cc
@@ -198,7 +198,10 @@ std::rethrow_exception(std::exception_ptr ep)
   dep->primaryException = obj;
   __gnu_cxx::__eh_atomic_inc (&eh->referenceCount);
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
   dep->unexpectedHandler = get_unexpected ();
+#pragma GCC diagnostic pop
   dep->terminateHandler = get_terminate ();
   __GXX_INIT_DEPENDENT_EXCEPTION_CLASS(dep->unwindHeader.exception_class);
   dep->unwindHeader.exception_cleanup = __gxx_dependent_exception_cleanup;
diff --git a/libstdc++-v3/libsupc++/eh_terminate.cc b/libstdc++-v3/libsupc++/eh_terminate.cc
index af257b63369..a94f173bb2e 100644
--- a/libstdc++-v3/libsupc++/eh_terminate.cc
+++ b/libstdc++-v3/libsupc++/eh_terminate.cc
@@ -58,6 +58,7 @@ std::terminate () throw()
   __cxxabiv1::__terminate (get_terminate ());
 }
 
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 void
 __cxxabiv1::__unexpected (std::unexpected_handler handler)
 {
diff --git a/libstdc++-v3/libsupc++/eh_throw.cc b/libstdc++-v3/libsupc++/eh_throw.cc
index 765a6c18cca..51cbbc902c2 100644
--- a/libstdc++-v3/libsupc++/eh_throw.cc
+++ b/libstdc++-v3/libsupc++/eh_throw.cc
@@ -63,7 +63,10 @@ _GLIBCXX_NOTHROW
   header->referenceCount = 0;
   header->exc.exceptionType = tinfo;
   header->exc.exceptionDestructor = dest;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
   header->exc.unexpectedHandler = std::get_unexpected ();
+#pragma GCC diagnostic pop
   header->exc.terminateHandler = std::get_terminate ();
   __GXX_INIT_PRIMARY_EXCEPTION_CLASS(header->exc.unwindHeader.exception_class);
   header->exc.unwindHeader.exception_cleanup = __gxx_exception_cleanup;
diff --git a/libstdc++-v3/libsupc++/exception b/libstdc++-v3/libsupc++/exception
index a023e22ea89..5088681e1eb 100644
--- a/libstdc++-v3/libsupc++/exception
+++ b/libstdc++-v3/libsupc++/exception
@@ -67,9 +67,6 @@ namespace std
   /// If you write a replacement %terminate handler, it must be of this type.
   typedef void (*terminate_handler) ();
 
-  /// If you write a replacement %unexpected handler, it must be of this type.
-  typedef void (*unexpected_handler) ();
-
   /// Takes a new handler function as an argument, returns the old function.
   terminate_handler set_terminate(terminate_handler) _GLIBCXX_USE_NOEXCEPT;
 
@@ -82,17 +79,35 @@ namespace std
    *  abandoned for any reason.  It can also be called by the user.  */
   void terminate() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__noreturn__));
 
-  /// Takes a new handler function as an argument, returns the old function.
+#if __cplusplus < 201703L || _GLIBCXX_USE_DEPRECATED
+  /// If you write a replacement %unexpected handler, it must be of this type.
+  typedef void (*_GLIBCXX11_DEPRECATED unexpected_handler) ();
+
+  /** Takes a new handler function as an argument, returns the old function.
+   *
+   * @deprecated Removed from the C++ standard in C++17
+   */
+  _GLIBCXX11_DEPRECATED
   unexpected_handler set_unexpected(unexpected_handler) _GLIBCXX_USE_NOEXCEPT;
 
 #if __cplusplus >= 201103L
-  /// Return the current unexpected handler.
+  /** Return the current unexpected handler.
+   *
+   * @since C++11
+   * @deprecated Removed from the C++ standard in C++17
+   */
+  _GLIBCXX11_DEPRECATED
   unexpected_handler get_unexpected() noexcept;
 #endif
 
   /** The runtime will call this function if an %exception is thrown which
-   *  violates the function's %exception specification.  */
+   *  violates the function's %exception specification.
+   *
+   * @deprecated Removed from the C++ standard in C++17
+   */
+  _GLIBCXX11_DEPRECATED
   void unexpected() __attribute__ ((__noreturn__));
+#endif
 
   /** [18.6.4]/1:  'Returns true after completing evaluation of a
    *  throw-expression until either completing initialization of the
diff --git a/libstdc++-v3/libsupc++/unwind-cxx.h b/libstdc++-v3/libsupc++/unwind-cxx.h
index 65fd5303b2b..96d50eae412 100644
--- a/libstdc++-v3/libsupc++/unwind-cxx.h
+++ b/libstdc++-v3/libsupc++/unwind-cxx.h
@@ -67,7 +67,7 @@ struct __cxa_exception
 
   // The C++ standard has entertaining rules wrt calling set_terminate
   // and set_unexpected in the middle of the exception cleanup process.
-  std::unexpected_handler unexpectedHandler;
+  std::terminate_handler unexpectedHandler;
   std::terminate_handler terminateHandler;
 
   // The caught exception stack threads through here.
@@ -121,7 +121,7 @@ struct __cxa_dependent_exception
 
   // The C++ standard has entertaining rules wrt calling set_terminate
   // and set_unexpected in the middle of the exception cleanup process.
-  std::unexpected_handler unexpectedHandler;
+  std::terminate_handler unexpectedHandler;
   std::terminate_handler terminateHandler;
 
   // The caught exception stack threads through here.
@@ -191,12 +191,12 @@ extern "C" void __cxa_tm_cleanup (void *, void *, unsigned int) throw();
 // so inconsiderate as to return.
 extern void __terminate(std::terminate_handler) throw () 
   __attribute__((__noreturn__));
-extern void __unexpected(std::unexpected_handler)
+extern void __unexpected(std::terminate_handler)
   __attribute__((__noreturn__));
 
 // The current installed user handlers.
 extern std::terminate_handler __terminate_handler;
-extern std::unexpected_handler __unexpected_handler;
+extern std::terminate_handler __unexpected_handler;
 
 // These are explicitly GNU C++ specific.
 
diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/60612-unexpected.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/60612-unexpected.cc
index 600ccb5698f..18bd1fe4f0d 100644
--- a/libstdc++-v3/testsuite/18_support/exception_ptr/60612-unexpected.cc
+++ b/libstdc++-v3/testsuite/18_support/exception_ptr/60612-unexpected.cc
@@ -1,3 +1,4 @@
+// { dg-options "-Wno-deprecated-declarations" }
 // { dg-do run { target { c++11_only || c++14_only } } }
 
 // Copyright (C) 2014-2021 Free Software Foundation, Inc.
diff --git a/libstdc++-v3/testsuite/18_support/headers/exception/synopsis.cc b/libstdc++-v3/testsuite/18_support/headers/exception/synopsis.cc
index 2f0bae4be0a..de35ec4c0e0 100644
--- a/libstdc++-v3/testsuite/18_support/headers/exception/synopsis.cc
+++ b/libstdc++-v3/testsuite/18_support/headers/exception/synopsis.cc
@@ -24,7 +24,7 @@ namespace std {
   class bad_exception;
 
   typedef void (*unexpected_handler)();
-  unexpected_handler set_unexpected(unexpected_handler  f ) throw();
+  unexpected_handler set_unexpected(unexpected_handler  f ) throw(); // { dg-warning "deprecated" { target c++11 } }
   unexpected_handler get_unexpected() noexcept;
   void unexpected();
 
diff --git a/libstdc++-v3/testsuite/18_support/set_unexpected.cc b/libstdc++-v3/testsuite/18_support/set_unexpected.cc
index 3f38431626d..6cedc7d6cd1 100644
--- a/libstdc++-v3/testsuite/18_support/set_unexpected.cc
+++ b/libstdc++-v3/testsuite/18_support/set_unexpected.cc
@@ -15,7 +15,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// { dg-options "-std=gnu++11" }
+// { dg-options "-std=gnu++11 -Wno-deprecated-declarations" }
 // { dg-do run { target { c++11_only || c++14_only } } }
 
 #include <exception>
diff --git a/libstdc++-v3/testsuite/18_support/unexpected_handler.cc b/libstdc++-v3/testsuite/18_support/unexpected_handler.cc
index 509bb5c31cd..551b0e7f371 100644
--- a/libstdc++-v3/testsuite/18_support/unexpected_handler.cc
+++ b/libstdc++-v3/testsuite/18_support/unexpected_handler.cc
@@ -15,6 +15,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
+// { dg-options "-Wno-deprecated-declarations" }
 // { dg-do run { target c++11 } }
 
 // D.11 Violating exception-specifications
-- 
2.31.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] libstdc++: Deprecate std::unexpected and handler functions
  2021-11-03  0:18 [PATCH] libstdc++: Deprecate std::unexpected and handler functions Jonathan Wakely
@ 2021-11-04 20:54 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2021-11-04 20:54 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, gcc Patches, Jason Merrill

On Wed, 3 Nov 2021 at 00:20, Jonathan Wakely via Libstdc++ <
libstdc++@gcc.gnu.org> wrote:

> 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.
>
> Tested x86_64-linux.
>
> Are the changes to g++ tests OK for trunk?
>

Jason acked the test changes off the list, so I've pushed this now.




>
>
> 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.
> ---
>  .../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 +++---
>  .../exception_ptr/60612-unexpected.cc         |  1 +
>  .../18_support/headers/exception/synopsis.cc  |  2 +-
>  .../testsuite/18_support/set_unexpected.cc    |  2 +-
>  .../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 3fb50df3f01..eddd3c9dcc5 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 ad9edec796b..ea152237d54 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 de16e016ff4..dbcc23e9610 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 9e92dafb08f..51cbc8de8ba 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 cd5585face8..973ebeacd03 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 ea320451179..3c832fd2105 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 d1aa6984f9f..2f7556be44d 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 1d57df3c335..278de2ef9f4 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 e102239ed89..d5d48968ff9 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 cffb0c48cda..8d50f73a475 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 3218dd9ef3e..36512ae6ab2 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 028a2de0c23..2507cf2e48c 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 <class T> 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 428635b175d..d1902f08106 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 <class T> 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 376a4035fa6..32810788bf2 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 <code class="function">std::random_shuffle</code> algorithms are
> deprecated
>  for C++14 and later. The C++11 <code class="function">std::shuffle</code>
> algorithm
>  can be used instead.
> +</p><p>
> +The <code class="function">std::unexpected</code> function and related
> typedef and
> +accessors for the unexpected handler are deprecated for C++11 and later.
> +Dynamic exception specifications should be replaced with <code
> class="code">noexcept</code>.
>  </p></div></div><div class="navfooter"><hr /><table width="100%"
> summary="Navigation footer"><tr><td width="40%" align="left"><a
> accesskey="p" href="abi.html">Prev</a> </td><td width="20%"
> align="center"><a accesskey="u" href="appendix_porting.html">Up</a></td><td
> width="40%" align="right"> <a accesskey="n"
> href="backwards.html">Next</a></td></tr><tr><td width="40%" align="left"
> valign="top">ABI Policy and Guidelines </td><td width="20%"
> align="center"><a accesskey="h" href="../index.html">Home</a></td><td
> width="40%" align="right" valign="top"> Backwards
> Compatibility</td></tr></table></div></body></html>
> \ No newline at end of file
> diff --git a/libstdc++-v3/doc/xml/manual/evolution.xml
> b/libstdc++-v3/doc/xml/manual/evolution.xml
> index 59b71b04442..9aef84a0933 100644
> --- a/libstdc++-v3/doc/xml/manual/evolution.xml
> +++ b/libstdc++-v3/doc/xml/manual/evolution.xml
> @@ -1027,6 +1027,12 @@ for C++14 and later. The C++11
> <function>std::shuffle</function> algorithm
>  can be used instead.
>  </para>
>
> +<para>
> +The <function>std::unexpected</function> function and related typedef and
> +accessors for the unexpected handler are deprecated for C++11 and later.
> +Dynamic exception specifications should be replaced with
> <code>noexcept</code>.
> +</para>
> +
>  </section>
>
>  </section>
> diff --git a/libstdc++-v3/libsupc++/eh_personality.cc
> b/libstdc++-v3/libsupc++/eh_personality.cc
> index 33c3cc32fb5..edd5f6a1a77 100644
> --- a/libstdc++-v3/libsupc++/eh_personality.cc
> +++ b/libstdc++-v3/libsupc++/eh_personality.cc
> @@ -673,10 +673,13 @@ PERSONALITY_FUNCTION (int version,
>         std::terminate ();
>        else if (handler_switch_value < 0)
>         {
> -         __try
> -           { std::unexpected (); }
> -         __catch(...)
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
> +         __try
> +           { std::unexpected (); }
> +         __catch(...)
>             { std::terminate (); }
> +#pragma GCC diagnostic pop
>         }
>      }
>    else
> diff --git a/libstdc++-v3/libsupc++/eh_ptr.cc
> b/libstdc++-v3/libsupc++/eh_ptr.cc
> index 5c4685606fe..9f47b666341 100644
> --- a/libstdc++-v3/libsupc++/eh_ptr.cc
> +++ b/libstdc++-v3/libsupc++/eh_ptr.cc
> @@ -198,7 +198,10 @@ std::rethrow_exception(std::exception_ptr ep)
>    dep->primaryException = obj;
>    __gnu_cxx::__eh_atomic_inc (&eh->referenceCount);
>
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
>    dep->unexpectedHandler = get_unexpected ();
> +#pragma GCC diagnostic pop
>    dep->terminateHandler = get_terminate ();
>    __GXX_INIT_DEPENDENT_EXCEPTION_CLASS(dep->unwindHeader.exception_class);
>    dep->unwindHeader.exception_cleanup = __gxx_dependent_exception_cleanup;
> diff --git a/libstdc++-v3/libsupc++/eh_terminate.cc
> b/libstdc++-v3/libsupc++/eh_terminate.cc
> index af257b63369..a94f173bb2e 100644
> --- a/libstdc++-v3/libsupc++/eh_terminate.cc
> +++ b/libstdc++-v3/libsupc++/eh_terminate.cc
> @@ -58,6 +58,7 @@ std::terminate () throw()
>    __cxxabiv1::__terminate (get_terminate ());
>  }
>
> +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
>  void
>  __cxxabiv1::__unexpected (std::unexpected_handler handler)
>  {
> diff --git a/libstdc++-v3/libsupc++/eh_throw.cc
> b/libstdc++-v3/libsupc++/eh_throw.cc
> index 765a6c18cca..51cbbc902c2 100644
> --- a/libstdc++-v3/libsupc++/eh_throw.cc
> +++ b/libstdc++-v3/libsupc++/eh_throw.cc
> @@ -63,7 +63,10 @@ _GLIBCXX_NOTHROW
>    header->referenceCount = 0;
>    header->exc.exceptionType = tinfo;
>    header->exc.exceptionDestructor = dest;
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
>    header->exc.unexpectedHandler = std::get_unexpected ();
> +#pragma GCC diagnostic pop
>    header->exc.terminateHandler = std::get_terminate ();
>
>  __GXX_INIT_PRIMARY_EXCEPTION_CLASS(header->exc.unwindHeader.exception_class);
>    header->exc.unwindHeader.exception_cleanup = __gxx_exception_cleanup;
> diff --git a/libstdc++-v3/libsupc++/exception
> b/libstdc++-v3/libsupc++/exception
> index a023e22ea89..5088681e1eb 100644
> --- a/libstdc++-v3/libsupc++/exception
> +++ b/libstdc++-v3/libsupc++/exception
> @@ -67,9 +67,6 @@ namespace std
>    /// If you write a replacement %terminate handler, it must be of this
> type.
>    typedef void (*terminate_handler) ();
>
> -  /// If you write a replacement %unexpected handler, it must be of this
> type.
> -  typedef void (*unexpected_handler) ();
> -
>    /// Takes a new handler function as an argument, returns the old
> function.
>    terminate_handler set_terminate(terminate_handler)
> _GLIBCXX_USE_NOEXCEPT;
>
> @@ -82,17 +79,35 @@ namespace std
>     *  abandoned for any reason.  It can also be called by the user.  */
>    void terminate() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__noreturn__));
>
> -  /// Takes a new handler function as an argument, returns the old
> function.
> +#if __cplusplus < 201703L || _GLIBCXX_USE_DEPRECATED
> +  /// If you write a replacement %unexpected handler, it must be of this
> type.
> +  typedef void (*_GLIBCXX11_DEPRECATED unexpected_handler) ();
> +
> +  /** Takes a new handler function as an argument, returns the old
> function.
> +   *
> +   * @deprecated Removed from the C++ standard in C++17
> +   */
> +  _GLIBCXX11_DEPRECATED
>    unexpected_handler set_unexpected(unexpected_handler)
> _GLIBCXX_USE_NOEXCEPT;
>
>  #if __cplusplus >= 201103L
> -  /// Return the current unexpected handler.
> +  /** Return the current unexpected handler.
> +   *
> +   * @since C++11
> +   * @deprecated Removed from the C++ standard in C++17
> +   */
> +  _GLIBCXX11_DEPRECATED
>    unexpected_handler get_unexpected() noexcept;
>  #endif
>
>    /** The runtime will call this function if an %exception is thrown which
> -   *  violates the function's %exception specification.  */
> +   *  violates the function's %exception specification.
> +   *
> +   * @deprecated Removed from the C++ standard in C++17
> +   */
> +  _GLIBCXX11_DEPRECATED
>    void unexpected() __attribute__ ((__noreturn__));
> +#endif
>
>    /** [18.6.4]/1:  'Returns true after completing evaluation of a
>     *  throw-expression until either completing initialization of the
> diff --git a/libstdc++-v3/libsupc++/unwind-cxx.h
> b/libstdc++-v3/libsupc++/unwind-cxx.h
> index 65fd5303b2b..96d50eae412 100644
> --- a/libstdc++-v3/libsupc++/unwind-cxx.h
> +++ b/libstdc++-v3/libsupc++/unwind-cxx.h
> @@ -67,7 +67,7 @@ struct __cxa_exception
>
>    // The C++ standard has entertaining rules wrt calling set_terminate
>    // and set_unexpected in the middle of the exception cleanup process.
> -  std::unexpected_handler unexpectedHandler;
> +  std::terminate_handler unexpectedHandler;
>    std::terminate_handler terminateHandler;
>
>    // The caught exception stack threads through here.
> @@ -121,7 +121,7 @@ struct __cxa_dependent_exception
>
>    // The C++ standard has entertaining rules wrt calling set_terminate
>    // and set_unexpected in the middle of the exception cleanup process.
> -  std::unexpected_handler unexpectedHandler;
> +  std::terminate_handler unexpectedHandler;
>    std::terminate_handler terminateHandler;
>
>    // The caught exception stack threads through here.
> @@ -191,12 +191,12 @@ extern "C" void __cxa_tm_cleanup (void *, void *,
> unsigned int) throw();
>  // so inconsiderate as to return.
>  extern void __terminate(std::terminate_handler) throw ()
>    __attribute__((__noreturn__));
> -extern void __unexpected(std::unexpected_handler)
> +extern void __unexpected(std::terminate_handler)
>    __attribute__((__noreturn__));
>
>  // The current installed user handlers.
>  extern std::terminate_handler __terminate_handler;
> -extern std::unexpected_handler __unexpected_handler;
> +extern std::terminate_handler __unexpected_handler;
>
>  // These are explicitly GNU C++ specific.
>
> diff --git
> a/libstdc++-v3/testsuite/18_support/exception_ptr/60612-unexpected.cc
> b/libstdc++-v3/testsuite/18_support/exception_ptr/60612-unexpected.cc
> index 600ccb5698f..18bd1fe4f0d 100644
> --- a/libstdc++-v3/testsuite/18_support/exception_ptr/60612-unexpected.cc
> +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/60612-unexpected.cc
> @@ -1,3 +1,4 @@
> +// { dg-options "-Wno-deprecated-declarations" }
>  // { dg-do run { target { c++11_only || c++14_only } } }
>
>  // Copyright (C) 2014-2021 Free Software Foundation, Inc.
> diff --git
> a/libstdc++-v3/testsuite/18_support/headers/exception/synopsis.cc
> b/libstdc++-v3/testsuite/18_support/headers/exception/synopsis.cc
> index 2f0bae4be0a..de35ec4c0e0 100644
> --- a/libstdc++-v3/testsuite/18_support/headers/exception/synopsis.cc
> +++ b/libstdc++-v3/testsuite/18_support/headers/exception/synopsis.cc
> @@ -24,7 +24,7 @@ namespace std {
>    class bad_exception;
>
>    typedef void (*unexpected_handler)();
> -  unexpected_handler set_unexpected(unexpected_handler  f ) throw();
> +  unexpected_handler set_unexpected(unexpected_handler  f ) throw(); // {
> dg-warning "deprecated" { target c++11 } }
>    unexpected_handler get_unexpected() noexcept;
>    void unexpected();
>
> diff --git a/libstdc++-v3/testsuite/18_support/set_unexpected.cc
> b/libstdc++-v3/testsuite/18_support/set_unexpected.cc
> index 3f38431626d..6cedc7d6cd1 100644
> --- a/libstdc++-v3/testsuite/18_support/set_unexpected.cc
> +++ b/libstdc++-v3/testsuite/18_support/set_unexpected.cc
> @@ -15,7 +15,7 @@
>  // with this library; see the file COPYING3.  If not see
>  // <http://www.gnu.org/licenses/>.
>
> -// { dg-options "-std=gnu++11" }
> +// { dg-options "-std=gnu++11 -Wno-deprecated-declarations" }
>  // { dg-do run { target { c++11_only || c++14_only } } }
>
>  #include <exception>
> diff --git a/libstdc++-v3/testsuite/18_support/unexpected_handler.cc
> b/libstdc++-v3/testsuite/18_support/unexpected_handler.cc
> index 509bb5c31cd..551b0e7f371 100644
> --- a/libstdc++-v3/testsuite/18_support/unexpected_handler.cc
> +++ b/libstdc++-v3/testsuite/18_support/unexpected_handler.cc
> @@ -15,6 +15,7 @@
>  // with this library; see the file COPYING3.  If not see
>  // <http://www.gnu.org/licenses/>.
>
> +// { dg-options "-Wno-deprecated-declarations" }
>  // { dg-do run { target c++11 } }
>
>  // D.11 Violating exception-specifications
> --
> 2.31.1
>
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-04 20:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-03  0:18 [PATCH] libstdc++: Deprecate std::unexpected and handler functions Jonathan Wakely
2021-11-04 20:54 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).