]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb] Make scope_exit constructor throw
authorTom de Vries <tdevries@suse.de>
Tue, 24 Sep 2024 11:47:56 +0000 (13:47 +0200)
committerTom de Vries <tdevries@suse.de>
Tue, 24 Sep 2024 11:47:56 +0000 (13:47 +0200)
While reviewing "catch (...)" uses I came across:
...
  scope_exit (EFP &&f)
    try : m_exit_function ((!std::is_lvalue_reference<EFP>::value
    && std::is_nothrow_constructible<EF, EFP>::value)
   ? std::move (f)
   : f)
  {
  }
  catch (...)
    {
      /* "If the initialization of exit_function throws an exception,
 calls f()."  */
      f ();
    }

...
and while looking up the origin of the comment here [1] I saw right after:
...
throws: Nothing, unless the initialization of exit_function throws
...

I think that means that the exception should be rethrown, so fix this by doing
so.

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
[1] https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0052r5.pdf

gdbsupport/scope-exit.h

index 86b2969f81728233e5b7e9302c4992c1c38e341c..2871a59c0020a2b1442f837c8e42eab9385ec879 100644 (file)
@@ -109,6 +109,9 @@ public:
       /* "If the initialization of exit_function throws an exception,
         calls f()."  */
       f ();
+      /* "throws: Nothing, unless the initialization of exit_function
+        throws."  */
+      throw;
     }
 
   template<typename EFP,