From 052490a93eea097abaed649248124774ee18227f Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 21 Sep 2025 11:37:03 -0700 Subject: [PATCH] [ADT] Use "inline static" to initialize CallbacksHolder (NFC) 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. --- llvm/include/llvm/ADT/FunctionExtras.h | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) 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 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 class UniqueFunctionBase { // Wrap in a struct to avoid https://gcc.gnu.org/PR71954 template struct CallbacksHolder { - static NonTrivialCallbacks Callbacks; + inline static NonTrivialCallbacks Callbacks = { + &CallImpl, &MoveImpl, &DestroyImpl}; }; // 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 struct CallbacksHolder> { - static TrivialCallback Callbacks; + inline static TrivialCallback Callbacks = {&CallImpl}; }; // A simple tag type so the call-as type to be passed to the constructor. @@ -344,19 +344,6 @@ template class UniqueFunctionBase { } }; -template -template -typename UniqueFunctionBase::NonTrivialCallbacks UniqueFunctionBase< - R, P...>::CallbacksHolder::Callbacks = { - &CallImpl, &MoveImpl, &DestroyImpl}; - -template -template -typename UniqueFunctionBase::TrivialCallback - UniqueFunctionBase::CallbacksHolder< - CallableT, CalledAsT, EnableIfTrivial>::Callbacks{ - &CallImpl}; - } // namespace detail template