qt6-bb10/tests/auto/corelib
Edward Welbourne 2e9d33e534 Use correct index for QLocale::system()'s static
Nothing prevents client code from calling QLocale::setDefault() before
we ever instantiate QLocale::system() - aside from some quirks that
mean setDefault(), currently, does instantiate QLocale::system() to
force initialization of defaultLocalePrivate - so using defaultIndex()
could set the system QLocalePrivate instance's index incorrectly.

In any case, even if the index is initially set correctly, a
subsequent change to the system locale would change the correct index;
and nothing outside QLocale::system() has access to the instance that
would then be remembering an out-of-date index.

Actually tripping over that inconsistency took some deviousness, but
was possible. The index is (currently) only used for month name
lookups and those special-case, for the Roman-derived calendars, the
system locale, to only use the index if the system locale offers no
name for a month. Meanwhile, updateSystemPrivate() uses the fallback
locale's index for its look-up of which CLDR data to copy into the
fallback QLocaleData for the system locale.

None the less, a non-Roman calendar's lookup will go via the index to
get at the CLDR data for that calendar, thereby exposing the system
locale's index to use; and, sure enough, a setDefault() could lead
that to produce wrong answers.

In QLocale::system() there's a cached QLocalePrivate, whose index we
need to ensure stays in sync with the active system locale. So pass
its &m_index to systemData(), which will now (when passed this) ensure
it's up to date. Since we always have called systemData(), to ensure
it is up to date, we can skip that update in the initialization of the
cached private and use m_index = -1 to let systemData() know when it's
in the initial call, thereby making the static cache constinit.

Amended a test to what proved the issue was present.

Change-Id: I8d7ab5830cf0bbb9265c2af2a1edc9396ddef79f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-07-31 17:16:14 +02:00
..
animation tst_QParallelAnimationGroup: fix memleak 2023-07-14 14:56:03 +02:00
global Make qYieldCpu() public API 2023-07-25 07:21:56 -07:00
io Socketpair is not supported on Vxworks 2023-07-27 08:46:18 +02:00
ipc QNativeIpcKey: add qHash() function 2023-07-25 12:31:04 +02:00
itemmodels tst_QSortFilterProxyModel: fix mem-leaks II: sortStable() 2023-07-19 04:51:26 +00:00
kernel Correct feature test in tst_qtranslator's CMake config 2023-07-27 15:09:24 +02:00
mimetypes Skip tst_QMimeDatabase::mimeTypeForUnixSpecials_data when AT_FDCWD is not defined 2023-07-28 23:13:09 +02:00
platform CMake: Make corelib tests standalone projects 2023-07-05 15:09:32 +02:00
plugin QUuid: handle quint128 and Id128Bytes data in the same way 2023-07-17 18:49:16 +02:00
serialization tst_QXmlStream: Remove stray comment 2023-07-25 09:31:17 +02:00
text Use correct index for QLocale::system()'s static 2023-07-31 17:16:14 +02:00
thread Revert "Fix signed integer overflows in tst_QAtomicInteger" 2023-07-28 11:20:35 -07:00
time QDTP: match local-time by preference to its zone 2023-07-21 18:22:01 +02:00
tools tst_QExplicitlySharedDataPointer: Remove stray comment 2023-07-25 12:31:04 +02:00
CMakeLists.txt tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00