Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
scope_guard: fix silly mistake in ON_SCOPE_EXIT.
Browse files Browse the repository at this point in the history
The previous implementation worked when used once per function, which
happened to be enough to pass the tests.  Macro token pasting is now
fixed.
  • Loading branch information
cbiffle committed Nov 16, 2014
1 parent 2fc1ae8 commit 4cb01c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions concatenate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef _ETL_CONCATENATE_H_INCLUDED
#define _ETL_CONCATENATE_H_INCLUDED

/*
* A macro for concatenating text tokens. Doing this is surprisingly involved
* with the C preprocessor.
*/
#define ETL_CONCATENATE(a, b) _ETL_CONCATENATE(a, b)
#define _ETL_CONCATENATE(a, b) a ## b

#endif // _ETL_CONCATENATE_H_INCLUDED
3 changes: 2 additions & 1 deletion scope_guard.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <type_traits>

#include "etl/concatenate.h"
#include "etl/implicit.h"
#include "etl/utility.h"

Expand Down Expand Up @@ -211,7 +212,7 @@ ScopeGuard<typename std::decay<F>::type> operator<<(GuardTag const &,
}

#define ETL_ON_SCOPE_EXIT \
auto on_scope_exit_ ## __COUNTER__ = ::etl::GuardTag() << [&]()
auto ETL_CONCATENATE(on_scope_exit, __COUNTER__) = ::etl::GuardTag() << [&]()

} // namespace etl

Expand Down

0 comments on commit 4cb01c6

Please sign in to comment.