[2/7] Make scope_exit constructor throw

Message ID 20240827140021.32660-2-tdevries@suse.de
State Committed
Headers
Series [1/7] Handle ^C in gnu_source_highlight_test |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Tom de Vries Aug. 27, 2024, 2 p.m. UTC
  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.

[1] https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0052r5.pdf
---
 gdbsupport/scope-exit.h | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Tom Tromey Sept. 23, 2024, 5:47 p.m. UTC | #1
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

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

I agree.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  

Patch

diff --git a/gdbsupport/scope-exit.h b/gdbsupport/scope-exit.h
index 86b2969f817..2871a59c002 100644
--- a/gdbsupport/scope-exit.h
+++ b/gdbsupport/scope-exit.h
@@ -109,6 +109,9 @@  class scope_exit : public scope_exit_base<scope_exit<EF>>
       /* "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,