[gdb/build,c++17] Fix use of deprecated std::uncaught_exception
authorTom de Vries <tdevries@suse.de>
Sun, 5 Jul 2020 21:47:20 +0000 (23:47 +0200)
committerTom de Vries <tdevries@suse.de>
Sun, 5 Jul 2020 21:47:20 +0000 (23:47 +0200)
When compiling gdb with -std=gnu++17, we run into:
...
../../gdb/inferior.h: In member function ‘void \
  infcall_suspend_state_deleter::operator()(infcall_suspend_state*) const’:
../../gdb/inferior.h:83:12: error: ‘bool std::uncaught_exception()’ is \
  deprecated [-Werror=deprecated-declarations]
   83 |  if (!std::uncaught_exception ())
...

Fix this by rewriting using std::uncaught_exceptions.

Tested on x86_64-linux with gcc 9.3.1 and -std=gnu17/gnu++17.

Tested with test-case from RFC patch
https://sourceware.org/pipermail/gdb-patches/2020-June/169970.html.

gdb/ChangeLog:

2020-07-05  Tom de Vries  <tdevries@suse.de>

PR build/26187
* inferior.h (struct infcall_suspend_state_deleter): If available, use
std::uncaught_exceptions instead of deprecated
std::uncaught_exception.

gdb/ChangeLog
gdb/inferior.h

index 8178e1673b1c4f63e835898be1efc87721c6169a..21dc3e2b2f9409090f9d9e7be321bd2de3f5d502 100644 (file)
@@ -1,3 +1,10 @@
+2020-07-05  Tom de Vries  <tdevries@suse.de>
+
+       PR build/26187
+       * inferior.h (struct infcall_suspend_state_deleter): If available, use
+       std::uncaught_exceptions instead of deprecated
+       std::uncaught_exception.
+
 2020-07-02  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * macroexp.h (macro_stringify): Return
index 572c5f3ae72dcf5e571a7a1433f668846b29e961..606cece6c0b33a017d9cfb759a88a8cf007309fb 100644 (file)
@@ -21,6 +21,8 @@
 #if !defined (INFERIOR_H)
 #define INFERIOR_H 1
 
+#include <exception>
+
 struct target_waitstatus;
 struct frame_info;
 struct ui_file;
@@ -80,7 +82,13 @@ struct infcall_suspend_state_deleter
        /* If we are restoring the inferior state due to an exception,
           some error message will be printed.  So, only warn the user
           when we cannot restore during normal execution.  */
-       if (!std::uncaught_exception ())
+       bool unwinding;
+#if __cpp_lib_uncaught_exceptions
+       unwinding = std::uncaught_exceptions () > 0;
+#else
+       unwinding = std::uncaught_exception ();
+#endif
+       if (!unwinding)
          warning (_("Failed to restore inferior state: %s"), e.what ());
       }
   }