From b2df824e02849864c3d8b0e3b855e67919119b5f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 27 Aug 2024 17:31:04 +0200 Subject: [PATCH] QLocale: mark c_locale Q_CONSTINIT and c_private() noexcept Add Q_CONSTINIT to the c_locale variable to statically assert that it cannot fail (no runtime initialization = no failure). The QLocalePrivate ctor is already constexpr, so Q_CONSTINIT works out of the box here. Because c_locale construction is now known not to fail, c_private() cannot fail, either, and can and should be noexcept. Change-Id: Ibe94cb4bcd990fbd0b440dd98509eb39447a94b7 Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira (cherry picked from commit c745b59e36b421039e71779fd9e5db8c619163f2) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qlocale.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 75bbe4c7722..bcd72e7f5e4 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -686,9 +686,9 @@ qsizetype qt_repeatCount(QStringView s) Q_CONSTINIT static const QLocaleData *default_data = nullptr; Q_CONSTINIT QBasicAtomicInt QLocalePrivate::s_generation = Q_BASIC_ATOMIC_INITIALIZER(0); -static QLocalePrivate *c_private() +static QLocalePrivate *c_private() noexcept { - static QLocalePrivate c_locale(locale_data, 0, QLocale::OmitGroupSeparator, 1); + Q_CONSTINIT static QLocalePrivate c_locale(locale_data, 0, QLocale::OmitGroupSeparator, 1); return &c_locale; }