[llvm] [ADT] Use "inline static" to initialize CallbacksHolder (NFC) (PR #160003)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 21 13:06:17 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
In C++17, we can initialize a static member variable with
"inline static" as part of the class definition. With this, we can
eliminate the out-of-line static initializers that are a bit hard to
decipher.
---
Full diff: https://github.com/llvm/llvm-project/pull/160003.diff
1 Files Affected:
- (modified) llvm/include/llvm/ADT/FunctionExtras.h (+3-16)
``````````diff
diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
index e45d507bfd4bf..1311452a17bb3 100644
--- a/llvm/include/llvm/ADT/FunctionExtras.h
+++ b/llvm/include/llvm/ADT/FunctionExtras.h
@@ -231,7 +231,6 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
// The pointers to call/move/destroy functions are determined for each
// callable type (and called-as type, which determines the overload chosen).
- // (definitions are out-of-line).
// By default, we need an object that contains all the different
// type erased behaviors needed. Create a static instance of the struct type
@@ -239,14 +238,15 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
// Wrap in a struct to avoid https://gcc.gnu.org/PR71954
template <typename CallableT, typename CalledAs, typename Enable = void>
struct CallbacksHolder {
- static NonTrivialCallbacks Callbacks;
+ inline static NonTrivialCallbacks Callbacks = {
+ &CallImpl<CalledAs>, &MoveImpl<CallableT>, &DestroyImpl<CallableT>};
};
// See if we can create a trivial callback. We need the callable to be
// trivially moved and trivially destroyed so that we don't have to store
// type erased callbacks for those operations.
template <typename CallableT, typename CalledAs>
struct CallbacksHolder<CallableT, CalledAs, EnableIfTrivial<CallableT>> {
- static TrivialCallback Callbacks;
+ inline static TrivialCallback Callbacks = {&CallImpl<CalledAs>};
};
// A simple tag type so the call-as type to be passed to the constructor.
@@ -344,19 +344,6 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
}
};
-template <typename R, typename... P>
-template <typename CallableT, typename CalledAsT, typename Enable>
-typename UniqueFunctionBase<R, P...>::NonTrivialCallbacks UniqueFunctionBase<
- R, P...>::CallbacksHolder<CallableT, CalledAsT, Enable>::Callbacks = {
- &CallImpl<CalledAsT>, &MoveImpl<CallableT>, &DestroyImpl<CallableT>};
-
-template <typename R, typename... P>
-template <typename CallableT, typename CalledAsT>
-typename UniqueFunctionBase<R, P...>::TrivialCallback
- UniqueFunctionBase<R, P...>::CallbacksHolder<
- CallableT, CalledAsT, EnableIfTrivial<CallableT>>::Callbacks{
- &CallImpl<CalledAsT>};
-
} // namespace detail
template <typename R, typename... P>
``````````
</details>
https://github.com/llvm/llvm-project/pull/160003
More information about the llvm-commits
mailing list