[llvm] 591e60b - [ADT] Use "inline static" to initialize CallbacksHolder (NFC) (#160003)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 21 19:16:39 PDT 2025
Author: Kazu Hirata
Date: 2025-09-21T19:16:35-07:00
New Revision: 591e60b0a458d63abf8da8c794eac1678b55e172
URL: https://github.com/llvm/llvm-project/commit/591e60b0a458d63abf8da8c794eac1678b55e172
DIFF: https://github.com/llvm/llvm-project/commit/591e60b0a458d63abf8da8c794eac1678b55e172.diff
LOG: [ADT] Use "inline static" to initialize CallbacksHolder (NFC) (#160003)
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.
Added:
Modified:
llvm/include/llvm/ADT/FunctionExtras.h
Removed:
################################################################################
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
diff erent
// 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>
More information about the llvm-commits
mailing list