diff options
Diffstat (limited to 'src/corelib/kernel/qtmochelpers.h')
-rw-r--r-- | src/corelib/kernel/qtmochelpers.h | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/src/corelib/kernel/qtmochelpers.h b/src/corelib/kernel/qtmochelpers.h index 7bdaaf276b..9d75177645 100644 --- a/src/corelib/kernel/qtmochelpers.h +++ b/src/corelib/kernel/qtmochelpers.h @@ -17,43 +17,47 @@ #include <QtCore/qglobal.h> +#include <algorithm> // std::min +#include <limits> + #if 0 #pragma qt_no_master_include #endif QT_BEGIN_NAMESPACE namespace QtMocHelpers { -template <uint... Nx> struct StringData -{ - 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; - } +// 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<uint>::max)()), + size_t((std::numeric_limits<qsizetype>::max)())); - // 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<uint>::max)()), - size_t((std::numeric_limits<qsizetype>::max)())); +template <uint... Nx> constexpr size_t stringDataSizeHelper(std::integer_sequence<uint, Nx...>) +{ + // 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; +} - static constexpr size_t StringSize = calculateStringSize(); +template <int Count, size_t StringSize> 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 <uint... Nx> constexpr auto stringData(const char (&...strings)[Nx]) { - StringData<Nx...> result; + constexpr size_t StringSize = stringDataSizeHelper<Nx...>({}); + constexpr size_t Count = 2 * sizeof...(Nx); + + StringData<Count, StringSize> result; const char *inputs[] = { strings... }; uint sizes[] = { Nx... }; @@ -72,10 +76,7 @@ template <uint... Nx> constexpr auto stringData(const char (&...strings)[Nx]) return result; } -#if !defined(Q_CC_GNU_ONLY) || Q_CC_GNU_ONLY >= 1000 -// It looks like there's a bug in GCC 9 # define QT_MOC_HAS_STRINGDATA 1 -#endif } // namespace QtMocHelpers QT_END_NAMESPACE |