From 0c716c687a8c65e7907912d6d5d6beb891238a95 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 11 Aug 2022 16:32:59 +0200 Subject: QUnicodeTools: mark a test-only flag constexpr/constinit For QT_BUILD_INTERNAL, mark the flag constinit, because tests may want to set it (which they better do before Qt spins up threads, because otherwise this non-atomic flag runs into UB (data races)). For non-QT_BUILD_INTERNAL, mark the flag constexpr, so dead code elimination can do its job. Inconsistently, of the two readers of the flag, one was ifdef'ed on QT_BUILD_INTERNAL, while the other wasn't. Settle on exposing both, which increases the compiler coverage of the code. Pick-to: 6.4 Task-number: QTBUG-100486 Task-number: QTBUG-100485 Change-Id: I6e041359b8214b40d80eefa92c26422aada3eb59 Reviewed-by: Thiago Macieira --- src/corelib/text/qunicodetools.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/corelib/text/qunicodetools.cpp b/src/corelib/text/qunicodetools.cpp index 46e9740f3b..32e791563f 100644 --- a/src/corelib/text/qunicodetools.cpp +++ b/src/corelib/text/qunicodetools.cpp @@ -20,7 +20,12 @@ QT_BEGIN_NAMESPACE using namespace Qt::StringLiterals; -Q_AUTOTEST_EXPORT int qt_initcharattributes_default_algorithm_only = 0; +#ifdef QT_BUILD_INTERNAL +Q_CONSTINIT Q_AUTOTEST_EXPORT +#else +constexpr +#endif +int qt_initcharattributes_default_algorithm_only = 0; namespace QUnicodeTools { @@ -257,7 +262,6 @@ static void getWordBreaks(const char16_t *string, qsizetype len, QCharAttributes const QUnicodeTables::Properties *prop = QUnicodeTables::properties(ucs4); QUnicodeTables::WordBreakClass ncls = (QUnicodeTables::WordBreakClass) prop->wordBreakClass; -#ifdef QT_BUILD_INTERNAL if (qt_initcharattributes_default_algorithm_only) { // as of Unicode 5.1, some punctuation marks were mapped to MidLetter and MidNumLet // which caused "hi.there" to be treated like if it were just a single word; @@ -268,7 +272,6 @@ static void getWordBreaks(const char16_t *string, qsizetype len, QCharAttributes else if (ucs4 == 0x003A) // COLON ncls = QUnicodeTables::WordBreak_MidLetter; } -#endif uchar action = WB::breakTable[cls][ncls]; switch (action) { -- cgit v1.2.3