diff --git a/orc-rt/include/orc-rt/ScopeExit.h b/orc-rt/include/orc-rt/ScopeExit.h index e73ca187ddc74..afd20c193c394 100644 --- a/orc-rt/include/orc-rt/ScopeExit.h +++ b/orc-rt/include/orc-rt/ScopeExit.h @@ -21,7 +21,8 @@ namespace detail { template class ScopeExitRunner { public: - ScopeExitRunner(Fn &&F) : F(F) {} + template + ScopeExitRunner(FnInit &&F) : F(std::forward(F)) {} ScopeExitRunner(const ScopeExitRunner &) = delete; ScopeExitRunner &operator=(const ScopeExitRunner &) = delete; ScopeExitRunner(ScopeExitRunner &&) = delete; diff --git a/orc-rt/unittests/ScopeExitTest.cpp b/orc-rt/unittests/ScopeExitTest.cpp index bbd517d79793b..411bb4f97bc3d 100644 --- a/orc-rt/unittests/ScopeExitTest.cpp +++ b/orc-rt/unittests/ScopeExitTest.cpp @@ -37,3 +37,15 @@ TEST(ScopeExitTest, Release) { } EXPECT_FALSE(ScopeExitRun); } + +TEST(ScopeExitTest, MoveOnlyFunctionObject) { + struct MoveOnly { + MoveOnly() = default; + MoveOnly(MoveOnly &&) = default; + void operator()() {} + }; + + { + auto OnExit = make_scope_exit(MoveOnly()); + } +}