diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-08-11 16:32:59 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-08-12 07:55:23 +0200 |
commit | 0c716c687a8c65e7907912d6d5d6beb891238a95 (patch) | |
tree | 49e116432bdef6855adf4e7327a2f56dda95100a /src/corelib | |
parent | bd9c7048233e570fbda256fc903684c379421cd6 (diff) |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/text/qunicodetools.cpp | 9 |
1 files 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) { |