mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Fix horrible sneaky use-of-temporary-after-destruction in SWIFT_DEFER. (#7851)
Caught by ASan's new use-after-scope checking!
This commit is contained in:
@@ -23,10 +23,10 @@
|
||||
namespace swift {
|
||||
template <typename F>
|
||||
class DoAtScopeExit {
|
||||
F &Fn;
|
||||
F Fn;
|
||||
void operator=(DoAtScopeExit&) = delete;
|
||||
public:
|
||||
DoAtScopeExit(F &Fn) : Fn(Fn){}
|
||||
DoAtScopeExit(F &&Fn) : Fn(std::move(Fn)) {}
|
||||
~DoAtScopeExit() {
|
||||
Fn();
|
||||
}
|
||||
@@ -36,7 +36,7 @@ namespace swift {
|
||||
struct DeferTask {};
|
||||
template<typename F>
|
||||
DoAtScopeExit<typename std::decay<F>::type> operator+(DeferTask, F&& fn) {
|
||||
return DoAtScopeExit<typename std::decay<F>::type>(fn);
|
||||
return DoAtScopeExit<typename std::decay<F>::type>(std::move(fn));
|
||||
}
|
||||
}
|
||||
} // end namespace swift
|
||||
|
||||
Reference in New Issue
Block a user