Skip to content

Commit 12ce7d9

Browse files
kazutakahiratamahesh-attarde
authored andcommitted
[Support] Consolidate runOnNewStack (NFC) (llvm#160816)
This patch consolidates two implementations of runOnNewStack with "if constexpr".
1 parent cc5ea2a commit 12ce7d9

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

llvm/include/llvm/Support/ProgramStack.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,15 @@ LLVM_ABI unsigned getDefaultStackSize();
4646
LLVM_ABI void runOnNewStack(unsigned StackSize, function_ref<void()> Fn);
4747

4848
template <typename R, typename... Ts>
49-
std::enable_if_t<!std::is_same_v<R, void>, R>
50-
runOnNewStack(unsigned StackSize, function_ref<R(Ts...)> Fn, Ts &&...Args) {
51-
std::optional<R> Ret;
52-
runOnNewStack(StackSize, [&]() { Ret = Fn(std::forward<Ts>(Args)...); });
53-
return std::move(*Ret);
54-
}
55-
56-
template <typename... Ts>
57-
void runOnNewStack(unsigned StackSize, function_ref<void(Ts...)> Fn,
49+
auto runOnNewStack(unsigned StackSize, function_ref<R(Ts...)> Fn,
5850
Ts &&...Args) {
59-
runOnNewStack(StackSize, [&]() { Fn(std::forward<Ts>(Args)...); });
51+
if constexpr (std::is_same_v<R, void>) {
52+
runOnNewStack(StackSize, [&]() { Fn(std::forward<Ts>(Args)...); });
53+
} else {
54+
std::optional<R> Ret;
55+
runOnNewStack(StackSize, [&]() { Ret = Fn(std::forward<Ts>(Args)...); });
56+
return std::move(*Ret);
57+
}
6058
}
6159

6260
} // namespace llvm

0 commit comments

Comments
 (0)