This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Introduce forward_scope_exit

*** TEST RESULTS FOR COMMIT 5b9b3e53a68f4568dc0b6907e34e763a6c3dd145 ***

Author: Pedro Alves <>
Branch: master
Commit: 5b9b3e53a68f4568dc0b6907e34e763a6c3dd145

Introduce forward_scope_exit

This adds a template that can be used to automatically instantiate
scope_exit-like types that wrap some cleanup function.  The
instantiated type has a ctor that has the same interface as the
wrapped function.  While the "magic" is just straight C++11, the
intended use is via the FORWARD_SCOPE_EXIT macro, which is a minimal
macro that avoids spelling out the wrapped function name more than

 void some_function (int foo, object *bar);
 using some_function_fce = FORWARD_SCOPE_EXIT (some_function);
 some_function_fce cleanup (some_int, some_obj_ptr);

The above runs:
  some_function (some_int, some_obj_ptr);
at scope exit.

This is mainly useful as opposed to a simpler SCOPE_EXIT when you need
  - cancel the scope_exit, in which case you need the object's name
  - wrap the scope_exit in a gdb::optional, in which case you need the
    scope_exit's type in advance.

More details in the code comments.

2019-01-23  Pedro Alves  <>
	    Andrew Burgess  <>

	* common/forward-scope-exit.h: New file.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]