Skip to content

v0.10.0

Latest

Choose a tag to compare

@Neargye Neargye released this 26 Oct 12:32
· 3 commits to master since this release

Scope Guard & Defer C++ v0.10.0

scope_guard is a header-only C++11 library for running cleanup and rollback code when a scope exits. It provides SCOPE_EXIT, SCOPE_FAIL, SCOPE_SUCCESS, DEFER and the make_scope_* factories.

This release focuses on correctness, exception safety and compiler compatibility.

Highlights

  • WITH_SCOPE_* creates the guard before the block. Actions now run on break, continue, return and exceptions, and WITH_SCOPE_FAIL works. Actions may contain commas.
  • If moving the action into a new guard throws, scope_exit and scope_fail still run the action. scope_success does not.
  • Actions with throwing destructors are handled correctly. SCOPE_GUARD_NO_THROW_ACTION and SCOPE_GUARD_SUPPRESS_THROW_ACTION require non-throwing action destructors.
  • SCOPE_GUARD_SUPPRESS_THROW_ACTION builds with Clang -fexceptions -fno-cxx-exceptions.
  • C++11/14 builds with Clang no longer conflict with <cxxabi.h>.
  • Clear compile errors for unsupported actions, such as lvalues, const rvalues and non-movable callables. Use std::move or std::ref for named callables.
  • Clean strict-warning builds on GCC, Clang 22/23 and MSVC. MSVC no longer hides warnings inside actions.
  • Guards cannot be allocated with new or new[].

Compatibility

  • Requires C++11 or newer, with GCC 9+, Clang 9+ or Visual Studio 2019+ (v142). CMake 3.15+ is required.
  • On Clang 22 with -pedantic, unnamed guards inside another macro's arguments warn about __COUNTER__. Use a named guard, a factory or Clang 23.