diff --git a/src/corelib/kernel/qtmochelpers.h b/src/corelib/kernel/qtmochelpers.h index b6b7ca6cbde..9e905ace20c 100644 --- a/src/corelib/kernel/qtmochelpers.h +++ b/src/corelib/kernel/qtmochelpers.h @@ -26,37 +26,38 @@ QT_BEGIN_NAMESPACE namespace QtMocHelpers { -template struct StringData +// The maximum Size of a string literal is 2 GB on 32-bit and 4 GB on 64-bit +// (but the compiler is likely to give up before you get anywhere near that much) +static constexpr size_t MaxStringSize = + (std::min)(size_t((std::numeric_limits::max)()), + size_t((std::numeric_limits::max)())); + +template constexpr size_t stringDataSizeHelper(std::integer_sequence) { - static constexpr size_t calculateStringSize() - { - // same as: - // return (0 + ... + Nx); - // but not using the fold expression to avoid exceeding compiler limits - size_t total = 0; - uint sizes[] = { Nx... }; - for (uint n : sizes) - total += n; - return total; - } + // same as: + // return (0 + ... + Nx); + // but not using the fold expression to avoid exceeding compiler limits + size_t total = 0; + uint sizes[] = { Nx... }; + for (uint n : sizes) + total += n; + return total; +} - // The maximum Size of a string literal is 2 GB on 32-bit and 4 GB on 64-bit - // (but the compiler is likely to give up before you get anywhere near that much) - static constexpr size_t MaxStringSize = - (std::min)(size_t((std::numeric_limits::max)()), - size_t((std::numeric_limits::max)())); - - static constexpr size_t StringSize = calculateStringSize(); +template struct StringData +{ static_assert(StringSize <= MaxStringSize, "Meta Object data is too big"); - - uint offsetsAndSizes[2 * sizeof...(Nx)] = {}; + uint offsetsAndSizes[Count] = {}; char stringdata0[StringSize] = {}; constexpr StringData() = default; }; template constexpr auto stringData(const char (&...strings)[Nx]) { - StringData result; + constexpr size_t StringSize = stringDataSizeHelper({}); + constexpr size_t Count = 2 * sizeof...(Nx); + + StringData result; const char *inputs[] = { strings... }; uint sizes[] = { Nx... };