diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h index 80f7734b86907..9d75b31a0ac04 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -1122,12 +1122,10 @@ template struct alignas(T) SmallVectorStorage {}; /// `sizeof(SmallVector)`. template class LLVM_GSL_OWNER SmallVector; -/// Helper class for calculating the default number of inline elements for +/// Helper function for calculating the default number of inline elements for /// `SmallVector`. -/// -/// This should be migrated to a constexpr function when our minimum -/// compiler support is enough for multi-statement constexpr functions. -template struct CalculateSmallVectorDefaultInlinedElements { +template +constexpr size_t calculateSmallVectorDefaultInlinedElements() { // Parameter controlling the default number of inlined elements // for `SmallVector`. // @@ -1135,7 +1133,7 @@ template struct CalculateSmallVectorDefaultInlinedElements { // 1. There is at least one inlined element. // 2. `sizeof(SmallVector) <= kPreferredSmallVectorSizeof` unless // it contradicts 1. - static constexpr size_t kPreferredSmallVectorSizeof = 64; + constexpr size_t kPreferredSmallVectorSizeof = 64; // static_assert that sizeof(T) is not "too big". // @@ -1168,12 +1166,11 @@ template struct CalculateSmallVectorDefaultInlinedElements { // Discount the size of the header itself when calculating the maximum inline // bytes. - static constexpr size_t PreferredInlineBytes = + constexpr size_t PreferredInlineBytes = kPreferredSmallVectorSizeof - sizeof(SmallVector); - static constexpr size_t NumElementsThatFit = PreferredInlineBytes / sizeof(T); - static constexpr size_t value = - NumElementsThatFit == 0 ? 1 : NumElementsThatFit; -}; + constexpr size_t NumElementsThatFit = PreferredInlineBytes / sizeof(T); + return NumElementsThatFit == 0 ? 1 : NumElementsThatFit; +} /// This is a 'vector' (really, a variable-sized array), optimized /// for the case when the array is small. It contains some number of elements @@ -1192,7 +1189,7 @@ template struct CalculateSmallVectorDefaultInlinedElements { /// /// \see https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallvector-h template ::value> + unsigned N = calculateSmallVectorDefaultInlinedElements()> class LLVM_GSL_OWNER SmallVector : public SmallVectorImpl, SmallVectorStorage { public: