diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 8c0ce2434e..50e2b352f4 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -2640,15 +2640,15 @@ QList QLocale::matchingLocales(QLocale::Language language, QLocale::Scr result.reserve(locale_data_size); quint16 index = locale_index[language]; - Q_ASSERT(filter.acceptLanguage(locale_data[index].m_language_id)); - do { + // There may be no matches, for some languages (e.g. Abkhazian at CLDR v39). + while (filter.acceptLanguage(locale_data[index].m_language_id)) { const QLocaleId id = locale_data[index].id(); if (filter.acceptScriptTerritory(id)) { result.append(QLocale(*(id.language_id == C ? c_private() : new QLocalePrivate(locale_data + index, index)))); } ++index; - } while (filter.acceptLanguage(locale_data[index].m_language_id)); + } return result; } diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 56eef7ac99..785bfdef44 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -716,6 +716,12 @@ void tst_QLocale::matchingLocales() QVERIFY(!locales.isEmpty()); QVERIFY(!locales.contains(c)); QVERIFY(locales.contains(ru_RU)); + + // Regression check for assertion failure when no locales match: + locales = QLocale::matchingLocales(QLocale::Abkhazian, QLocale::AnyScript, QLocale::AnyTerritory); + // Empty in CLDR v39, but don't require that. + QVERIFY(!locales.contains(c)); + QVERIFY(!locales.contains(ru_RU)); } void tst_QLocale::unixLocaleName_data()