Skip to content

Commit 224cad6

Browse files
authored
[orc-rt] Use perfect forwarding for scope-exit initialization. (#157786)
Allows the use of move-only types with make_scope_exit.
1 parent d077c84 commit 224cad6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

orc-rt/include/orc-rt/ScopeExit.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ namespace detail {
2121

2222
template <typename Fn> class ScopeExitRunner {
2323
public:
24-
ScopeExitRunner(Fn &&F) : F(F) {}
24+
template <typename FnInit>
25+
ScopeExitRunner(FnInit &&F) : F(std::forward<FnInit>(F)) {}
2526
ScopeExitRunner(const ScopeExitRunner &) = delete;
2627
ScopeExitRunner &operator=(const ScopeExitRunner &) = delete;
2728
ScopeExitRunner(ScopeExitRunner &&) = delete;

orc-rt/unittests/ScopeExitTest.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,15 @@ TEST(ScopeExitTest, Release) {
3737
}
3838
EXPECT_FALSE(ScopeExitRun);
3939
}
40+
41+
TEST(ScopeExitTest, MoveOnlyFunctionObject) {
42+
struct MoveOnly {
43+
MoveOnly() = default;
44+
MoveOnly(MoveOnly &&) = default;
45+
void operator()() {}
46+
};
47+
48+
{
49+
auto OnExit = make_scope_exit(MoveOnly());
50+
}
51+
}

0 commit comments

Comments
 (0)