diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h index 1311452a17bb3..12a2dc36e1af0 100644 --- a/llvm/include/llvm/ADT/FunctionExtras.h +++ b/llvm/include/llvm/ADT/FunctionExtras.h @@ -58,10 +58,6 @@ template class unique_function; namespace detail { -template -using EnableIfTrivial = - std::enable_if_t::value && - std::is_trivially_destructible::value>; template using EnableUnlessSameType = std::enable_if_t, ThisT>::value>; @@ -236,17 +232,17 @@ template class UniqueFunctionBase { // type erased behaviors needed. Create a static instance of the struct type // here and each instance will contain a pointer to it. // Wrap in a struct to avoid https://gcc.gnu.org/PR71954 - template - struct CallbacksHolder { - 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> { - inline static TrivialCallback Callbacks = {&CallImpl}; + template struct CallbacksHolder { + inline static auto Callbacks = []() constexpr { + // For trivial callables, we don't need to store move and destroy + // callbacks. + if constexpr (std::is_trivially_move_constructible_v && + std::is_trivially_destructible_v) + return TrivialCallback{&CallImpl}; + else + return NonTrivialCallbacks{&CallImpl, &MoveImpl, + &DestroyImpl}; + }(); }; // A simple tag type so the call-as type to be passed to the constructor.