Skip to content

Commit 92e343e

Browse files
authored
[LLVM][ADT] Make scope-exit CTAD-capable (#173131)
This enables using it like ```cpp llvm::scope_exit Cleanup([] { ... }); ``` instead of ```cpp auto Cleanup = llvm::make_scope_exit([] { ... }); ```
1 parent e69fb42 commit 92e343e

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,14 +776,13 @@ uint32_t PlatformPOSIX::DoLoadImage(lldb_private::Process *process,
776776
// This will be the address of the storage for paths, if we are using them,
777777
// or nullptr to signal we aren't.
778778
lldb::addr_t path_array_addr = 0x0;
779-
std::optional<llvm::detail::scope_exit<std::function<void()>>>
780-
path_array_cleanup;
779+
std::optional<llvm::scope_exit<std::function<void()>>> path_array_cleanup;
781780

782781
// This is the address to a buffer large enough to hold the largest path
783782
// conjoined with the library name we're passing in. This is a convenience
784783
// to avoid having to call malloc in the dlopen function.
785784
lldb::addr_t buffer_addr = 0x0;
786-
std::optional<llvm::detail::scope_exit<std::function<void()>>> buffer_cleanup;
785+
std::optional<llvm::scope_exit<std::function<void()>>> buffer_cleanup;
787786

788787
// Set the values into our args and write them to the target:
789788
if (paths != nullptr) {

lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ uint32_t PlatformWindows::DoLoadImage(Process *process,
231231

232232
/* Inject paths parameter into inferior */
233233
lldb::addr_t injected_paths{0x0};
234-
std::optional<llvm::detail::scope_exit<std::function<void()>>> paths_cleanup;
234+
std::optional<llvm::scope_exit<std::function<void()>>> paths_cleanup;
235235
if (paths) {
236236
llvm::SmallVector<llvm::UTF16, 261> search_paths;
237237

llvm/include/llvm/ADT/ScopeExit.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@
1515
#ifndef LLVM_ADT_SCOPEEXIT_H
1616
#define LLVM_ADT_SCOPEEXIT_H
1717

18-
#include "llvm/Support/Compiler.h"
19-
20-
#include <type_traits>
2118
#include <utility>
2219

2320
namespace llvm {
24-
namespace detail {
2521

2622
template <typename Callable> class scope_exit {
2723
Callable ExitFunction;
@@ -47,17 +43,15 @@ template <typename Callable> class scope_exit {
4743
}
4844
};
4945

50-
} // end namespace detail
46+
template <typename Callable> scope_exit(Callable) -> scope_exit<Callable>;
5147

5248
// Keeps the callable object that is passed in, and execute it at the
5349
// destruction of the returned object (usually at the scope exit where the
5450
// returned object is kept).
5551
//
5652
// Interface is specified by p0052r2.
57-
template <typename Callable>
58-
[[nodiscard]] detail::scope_exit<std::decay_t<Callable>>
59-
make_scope_exit(Callable &&F) {
60-
return detail::scope_exit<std::decay_t<Callable>>(std::forward<Callable>(F));
53+
template <typename Callable> [[nodiscard]] auto make_scope_exit(Callable &&F) {
54+
return scope_exit(std::forward<Callable>(F));
6155
}
6256

6357
} // end namespace llvm

0 commit comments

Comments
 (0)