diff options
27 files changed, 198 insertions, 126 deletions
diff --git a/src/corelib/io/qstorageinfo_win.cpp b/src/corelib/io/qstorageinfo_win.cpp index 8a3db90f87..5a65b78d63 100644 --- a/src/corelib/io/qstorageinfo_win.cpp +++ b/src/corelib/io/qstorageinfo_win.cpp @@ -192,7 +192,7 @@ QList<QStorageInfo> QStorageInfoPrivate::mountedVolumes() if (!drive.rootPath().isEmpty()) // drive exists, but not mounted volumes.append(drive); } - driveName[0] = driveName[0].unicode() + 1; + driveName[0] = QChar(driveName[0].unicode() + 1); driveBits = driveBits >> 1; } diff --git a/src/corelib/text/qchar.cpp b/src/corelib/text/qchar.cpp index 14c82c7ee4..dcc36d18ce 100644 --- a/src/corelib/text/qchar.cpp +++ b/src/corelib/text/qchar.cpp @@ -158,6 +158,12 @@ QT_BEGIN_NAMESPACE to construct a QChar from an 8-bit \c char, and you will need to call toLatin1() to get the 8-bit value back. + Starting with Qt 6.0, most QChar constructors are \c explicit. This + is done to avoid dangerous mistakes when accidentally mixing + integral types and strings. You can opt-out (and make these + constructors implicit) by defining the macro \c + QT_IMPLICIT_QCHAR_CONSTRUCTION. + For more information see \l{http://www.unicode.org/ucd/}{"About the Unicode Character Database"}. @@ -2118,4 +2124,51 @@ static bool normalizationQuickCheckHelper(QString *str, QString::NormalizationFo return true; } +/*! + \macro QT_IMPLICIT_QCHAR_CONSTRUCTION + \since 6.0 + \relates QChar + + Defining this macro makes certain QChar constructors implicit + rather than explicit. This is done to enforce safe conversions: + + \badcode + + QString str = getString(); + if (str == 123) { + // Oops, meant str == "123". By default does not compile, + // *unless* this macro is defined, in which case, it's interpreted + // as `if (str == QChar(123))`, that is, `if (str == '{')`. + // Likely, not what we meant. + } + + \endcode + + This macro is provided to keep existing code working; it is + recommended to instead use explicit conversions and/or QLatin1Char. + For instance: + + \code + + QChar c1 = 'x'; // OK, unless QT_NO_CAST_FROM_ASCII is defined + QChar c2 = u'x'; // always OK, recommended + QChar c3 = QLatin1Char('x'); // always OK, recommended + + // from int to 1 UTF-16 code unit: must guarantee that the input is <= 0xFFFF + QChar c4 = 120; // compile error, unless QT_IMPLICIT_QCHAR_CONSTRUCTION is defined + QChar c5(120); // OK (direct initialization) + auto c6 = QChar(120); // ditto + + // from int/char32_t to 1/2 UTF-16 code units: + // 𝄞 'MUSICAL SYMBOL G CLEF' (U+1D11E) + auto c7 = QChar(0x1D11E); // compiles, but undefined behavior at runtime + auto c8 = QChar::fromUcs4(0x1D11E); // always OK + auto c9 = QChar::fromUcs4(U'\U0001D11E'); // always OK + // => use c8/c9 as QStringView objects + + \endcode + + \sa QLatin1Char, QChar::fromUcs4, QT_NO_CAST_FROM_ASCII +*/ + QT_END_NAMESPACE diff --git a/src/corelib/text/qchar.h b/src/corelib/text/qchar.h index 982abe9346..f66671e27c 100644 --- a/src/corelib/text/qchar.h +++ b/src/corelib/text/qchar.h @@ -101,12 +101,18 @@ public: LastValidCodePoint = 0x10ffff }; +#ifdef QT_IMPLICIT_QCHAR_CONSTRUCTION +#define QCHAR_MAYBE_IMPLICIT Q_IMPLICIT +#else +#define QCHAR_MAYBE_IMPLICIT explicit +#endif + constexpr Q_IMPLICIT QChar() noexcept : ucs(0) {} constexpr Q_IMPLICIT QChar(ushort rc) noexcept : ucs(rc) {} - constexpr Q_IMPLICIT QChar(uchar c, uchar r) noexcept : ucs(char16_t((r << 8) | c)) {} + constexpr QCHAR_MAYBE_IMPLICIT QChar(uchar c, uchar r) noexcept : ucs(char16_t((r << 8) | c)) {} constexpr Q_IMPLICIT QChar(short rc) noexcept : ucs(char16_t(rc)) {} - constexpr Q_IMPLICIT QChar(uint rc) noexcept : ucs(char16_t(rc & 0xffff)) {} - constexpr Q_IMPLICIT QChar(int rc) noexcept : ucs(char16_t(rc & 0xffff)) {} + constexpr QCHAR_MAYBE_IMPLICIT QChar(uint rc) noexcept : ucs(char16_t(rc & 0xffff)) {} + constexpr QCHAR_MAYBE_IMPLICIT QChar(int rc) noexcept : ucs(char16_t(rc & 0xffff)) {} constexpr Q_IMPLICIT QChar(SpecialCharacter s) noexcept : ucs(char16_t(s)) {} // implicit constexpr Q_IMPLICIT QChar(QLatin1Char ch) noexcept : ucs(ch.unicode()) {} // implicit constexpr Q_IMPLICIT QChar(char16_t ch) noexcept : ucs(ch) {} // implicit @@ -114,18 +120,19 @@ public: static_assert(sizeof(wchar_t) == sizeof(char16_t)); #endif #if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC) -# if !defined(_WCHAR_T_DEFINED) || defined(_NATIVE_WCHAR_T_DEFINED) constexpr Q_IMPLICIT QChar(wchar_t ch) noexcept : ucs(char16_t(ch)) {} // implicit -# endif #endif #ifndef QT_NO_CAST_FROM_ASCII + // Always implicit -- allow for 'x' => QChar conversions QT_ASCII_CAST_WARN constexpr Q_IMPLICIT QChar(char c) noexcept : ucs(uchar(c)) { } #ifndef QT_RESTRICTED_CAST_FROM_ASCII - QT_ASCII_CAST_WARN constexpr Q_IMPLICIT QChar(uchar c) noexcept : ucs(c) { } + QT_ASCII_CAST_WARN constexpr QCHAR_MAYBE_IMPLICIT QChar(uchar c) noexcept : ucs(c) { } #endif #endif +#undef QCHAR_MAYBE_IMPLICIT + static constexpr QChar fromUcs2(char16_t c) noexcept { return QChar{c}; } static constexpr inline auto fromUcs4(char32_t c) noexcept; diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 1447b5b21c..c955cb8736 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -1509,8 +1509,10 @@ inline char qToLower(char ch) /*! \macro QT_NO_CAST_FROM_ASCII \relates QString + \relates QChar - Disables automatic conversions from 8-bit strings (char *) to unicode QStrings + Disables automatic conversions from 8-bit strings (char *) to unicode QStrings, + as well as from 8-bit char types (char and unsigned char) to QChar. \sa QT_NO_CAST_TO_ASCII, QT_RESTRICTED_CAST_FROM_ASCII, QT_NO_CAST_FROM_BYTEARRAY */ diff --git a/src/gui/text/windows/qwindowsfontdatabase.cpp b/src/gui/text/windows/qwindowsfontdatabase.cpp index 9ee1c5aba6..79ea08f9b6 100644 --- a/src/gui/text/windows/qwindowsfontdatabase.cpp +++ b/src/gui/text/windows/qwindowsfontdatabase.cpp @@ -485,7 +485,7 @@ static QChar *createFontFile(const QString &faceName) const int nameLength = qMin(faceName.length(), LF_FACESIZE - 1); faceNamePtr = new QChar[nameLength + 1]; memcpy(static_cast<void *>(faceNamePtr), faceName.utf16(), sizeof(wchar_t) * nameLength); - faceNamePtr[nameLength] = 0; + faceNamePtr[nameLength] = u'\0'; } return faceNamePtr; } diff --git a/src/gui/text/windows/qwindowsfontengine.cpp b/src/gui/text/windows/qwindowsfontengine.cpp index 46774fa304..b2855d19dd 100644 --- a/src/gui/text/windows/qwindowsfontengine.cpp +++ b/src/gui/text/windows/qwindowsfontengine.cpp @@ -376,7 +376,7 @@ void QWindowsFontEngine::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::Shape oldFont = SelectObject(hdc, hfont); if (!ttf) { - QChar ch[2] = { ushort(glyph), 0 }; + QChar ch[2] = { ushort(glyph), u'\0' }; int chrLen = 1; if (QChar::requiresSurrogates(glyph)) { ch[0] = QChar::highSurrogate(glyph); diff --git a/src/plugins/platforms/cocoa/qcocoakeymapper.mm b/src/plugins/platforms/cocoa/qcocoakeymapper.mm index dca7b576f6..caa68ae694 100644 --- a/src/plugins/platforms/cocoa/qcocoakeymapper.mm +++ b/src/plugins/platforms/cocoa/qcocoakeymapper.mm @@ -121,7 +121,7 @@ static CarbonModifiers toCarbonModifiers(Qt::KeyboardModifiers qtModifiers) } // Keyboard keys (non-modifiers) -static QHash<QChar, Qt::Key> standardKeys = { +static QHash<char16_t, Qt::Key> standardKeys = { { kHomeCharCode, Qt::Key_Home }, { kEnterCharCode, Qt::Key_Enter }, { kEndCharCode, Qt::Key_End }, @@ -173,7 +173,7 @@ static QHash<QChar, Qt::Key> standardKeys = { { '^', Qt::Key_AsciiCircum } }; -static QHash<QChar, Qt::Key> virtualKeys = { +static QHash<char16_t, Qt::Key> virtualKeys = { { kVK_F1, Qt::Key_F1 }, { kVK_F2, Qt::Key_F2 }, { kVK_F3, Qt::Key_F3 }, @@ -202,7 +202,7 @@ static QHash<QChar, Qt::Key> virtualKeys = { { kVK_PageDown, Qt::Key_PageDown } }; -static QHash<QChar, Qt::Key> functionKeys = { +static QHash<char16_t, Qt::Key> functionKeys = { { NSUpArrowFunctionKey, Qt::Key_Up }, { NSDownArrowFunctionKey, Qt::Key_Down }, { NSLeftArrowFunctionKey, Qt::Key_Left }, @@ -237,7 +237,7 @@ static int toKeyCode(const QChar &key, int virtualKey, int modifiers) qCDebug(lcQpaKeyMapperKeys, "Mapping key: %d (0x%04x) / vk %d (0x%04x)", key.unicode(), key.unicode(), virtualKey, virtualKey); - if (key == kClearCharCode && virtualKey == 0x47) + if (key == QChar(kClearCharCode) && virtualKey == 0x47) return Qt::Key_Clear; if (key.isDigit()) { @@ -254,7 +254,7 @@ static int toKeyCode(const QChar &key, int virtualKey, int modifiers) return key.unicode(); } - if (auto qtKey = standardKeys.value(key)) { + if (auto qtKey = standardKeys.value(key.unicode())) { // To work like Qt for X11 we issue Backtab when Shift + Tab are pressed if (qtKey == Qt::Key_Tab && (modifiers & Qt::ShiftModifier)) { qCDebug(lcQpaKeyMapperKeys, "Got key: Qt::Key_Backtab"); @@ -272,11 +272,11 @@ static int toKeyCode(const QChar &key, int virtualKey, int modifiers) } // Check if they belong to key codes in private unicode range - if (key >= NSUpArrowFunctionKey && key <= NSModeSwitchFunctionKey) { - if (auto qtKey = functionKeys.value(key)) { + if (key >= QChar(NSUpArrowFunctionKey) && key <= QChar(NSModeSwitchFunctionKey)) { + if (auto qtKey = functionKeys.value(key.unicode())) { qCDebug(lcQpaKeyMapperKeys) << "Got" << qtKey; return qtKey; - } else if (key >= NSF1FunctionKey && key <= NSF35FunctionKey) { + } else if (key >= QChar(NSF1FunctionKey) && key <= QChar(NSF35FunctionKey)) { auto functionKey = Qt::Key_F1 + (key.unicode() - NSF1FunctionKey) ; qCDebug(lcQpaKeyMapperKeys) << "Got" << functionKey; return functionKey; @@ -291,7 +291,7 @@ static int toKeyCode(const QChar &key, int virtualKey, int modifiers) static const int NSEscapeCharacter = 27; // not defined by Cocoa headers -static const QHash<QChar, Qt::Key> cocoaKeys = { +static const QHash<char16_t, Qt::Key> cocoaKeys = { { NSEnterCharacter, Qt::Key_Enter }, { NSBackspaceCharacter, Qt::Key_Backspace }, { NSTabCharacter, Qt::Key_Tab }, @@ -357,11 +357,11 @@ QChar QCocoaKeyMapper::toCocoaKey(Qt::Key key) { // Prioritize overloaded keys if (key == Qt::Key_Return) - return NSNewlineCharacter; + return QChar(NSNewlineCharacter); if (key == Qt::Key_Backspace) - return NSBackspaceCharacter; + return QChar(NSBackspaceCharacter); - static QHash<Qt::Key, QChar> reverseCocoaKeys; + static QHash<Qt::Key, char16_t> reverseCocoaKeys; if (reverseCocoaKeys.isEmpty()) { reverseCocoaKeys.reserve(cocoaKeys.size()); for (auto it = cocoaKeys.begin(); it != cocoaKeys.end(); ++it) @@ -373,7 +373,7 @@ QChar QCocoaKeyMapper::toCocoaKey(Qt::Key key) Qt::Key QCocoaKeyMapper::fromCocoaKey(QChar keyCode) { - if (auto key = cocoaKeys.value(keyCode)) + if (auto key = cocoaKeys.value(keyCode.unicode())) return key; return Qt::Key(keyCode.toUpper().unicode()); diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm index 511c72988a..4806b244c3 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm @@ -362,7 +362,7 @@ NSMenuItem *QCocoaMenuItem::sync() // Similar to qt_mac_removePrivateUnicode change the delete key, // so the symbol is correctly seen in native menu bar. if (cocoaKey.unicode() == NSDeleteFunctionKey) - cocoaKey = NSDeleteCharacter; + cocoaKey = QChar(NSDeleteCharacter); m_native.keyEquivalent = QStringView(&cocoaKey, 1).toNSString(); m_native.keyEquivalentModifierMask = QCocoaKeyMapper::toCocoaModifiers(modifiers); diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 34568ee44a..8c3c6f4413 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -676,7 +676,7 @@ static inline bool isTreeView(const QWidget *widget) static QString qt_mac_removeMnemonics(const QString &original) { - QString returnText(original.size(), 0); + QString returnText(original.size(), QChar(0)); int finalDest = 0; int currPos = 0; int l = original.length(); diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index e5b7051997..e408cd3e48 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -3182,7 +3182,7 @@ void tst_QFile::mapResource() QCOMPARE(file.error(), error); QVERIFY((error == QFile::NoError) ? (memory != 0) : (memory == 0)); if (error == QFile::NoError) - QCOMPARE(QString(memory[0]), QString::number(offset + 1)); + QCOMPARE(QString(QChar(memory[0])), QString::number(offset + 1)); QVERIFY(file.unmap(memory)); } diff --git a/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp b/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp index da9477ca84..4b77820028 100644 --- a/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp +++ b/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp @@ -517,23 +517,23 @@ void tst_QUrlInternal::nameprep_highcodes_data() QTest::addColumn<int>("rc"); { - QChar st[] = { '-', 0xd801, 0xdc1d, 'a' }; - QChar se[] = { '-', 0xd801, 0xdc45, 'a' }; + QChar st[] = { '-', QChar(0xd801), QChar(0xdc1d), 'a' }; + QChar se[] = { '-', QChar(0xd801), QChar(0xdc45), 'a' }; QTest::newRow("highcodes (U+1041D)") << QString(st, sizeof(st)/sizeof(st[0])) << QString(se, sizeof(se)/sizeof(se[0])) << QString() << 0 << 0; } { - QChar st[] = { 0x011C, 0xd835, 0xdf6e, 0x0110 }; - QChar se[] = { 0x011D, 0x03C9, 0x0111 }; + QChar st[] = { QChar(0x011C), QChar(0xd835), QChar(0xdf6e), QChar(0x0110) }; + QChar se[] = { QChar(0x011D), QChar(0x03C9), QChar(0x0111) }; QTest::newRow("highcodes (U+1D76E)") << QString(st, sizeof(st)/sizeof(st[0])) << QString(se, sizeof(se)/sizeof(se[0])) << QString() << 0 << 0; } { - QChar st[] = { 'D', 'o', '\'', 0x2060, 'h' }; + QChar st[] = { 'D', 'o', '\'', QChar(0x2060), 'h' }; QChar se[] = { 'd', 'o', '\'', 'h' }; QTest::newRow("highcodes (D, o, ', U+2060, h)") << QString(st, sizeof(st)/sizeof(st[0])) diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp index 78749559b5..20fc5d492d 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp @@ -4794,7 +4794,7 @@ void tst_QSortFilterProxyModel::filterAndInsertColumn() model.insertRows(0, 1); for (int i = 0; i < model.rowCount(); ++i) { for (int j = 0; j < model.columnCount(); ++j) - model.setData(model.index(i, j), QString('A' + j) + QString::number(i + 1)); + model.setData(model.index(i, j), QString(QChar('A' + j)) + QString::number(i + 1)); } ColumnFilterProxy proxy(filterMode); proxy.setSourceModel(&model); @@ -5048,7 +5048,7 @@ void tst_QSortFilterProxyModel::invalidateColumnsOrRowsFilter() QStandardItemModel model(10, 4); for (int i = 0; i < model.rowCount(); ++i) { for (int j = 0; j < model.columnCount(); ++j) { - model.setItem(i, j, new QStandardItem(QString('A' + j) + QString::number(i + 1))); + model.setItem(i, j, new QStandardItem(QString(QChar('A' + j)) + QString::number(i + 1))); model.item(i, 0)->appendColumn({ new QStandardItem(QString("child col %0").arg(j)) }); } } diff --git a/tests/auto/corelib/serialization/json/tst_qtjson.cpp b/tests/auto/corelib/serialization/json/tst_qtjson.cpp index 5d4a9b15b1..04411cea63 100644 --- a/tests/auto/corelib/serialization/json/tst_qtjson.cpp +++ b/tests/auto/corelib/serialization/json/tst_qtjson.cpp @@ -3229,8 +3229,8 @@ void tst_QtJson::streamSerializationQJsonValue_data() QTest::newRow("array") << QJsonValue{QJsonArray{12,1,5,6,7}}; QTest::newRow("object") << QJsonValue{QJsonObject{{"foo", 665}, {"bar", 666}}}; // test json escape sequence - QTest::newRow("array with 0xD800") << QJsonValue(QJsonArray{QString(0xD800)}); - QTest::newRow("array with 0xDF06,0xD834") << QJsonValue(QJsonArray{QString(0xDF06).append(0xD834)}); + QTest::newRow("array with 0xD800") << QJsonValue(QJsonArray{QString(QChar(0xD800))}); + QTest::newRow("array with 0xDF06,0xD834") << QJsonValue(QJsonArray{QString(QChar(0xDF06)).append(QChar(0xD834))}); } void tst_QtJson::streamSerializationQJsonValue() @@ -3323,8 +3323,8 @@ void tst_QtJson::escapeSurrogateCodePoints_data() { QTest::addColumn<QString>("str"); QTest::addColumn<QByteArray>("escStr"); - QTest::newRow("0xD800") << QString(0xD800) << QByteArray("\\ud800"); - QTest::newRow("0xDF06,0xD834") << QString(0xDF06).append(0xD834) << QByteArray("\\udf06\\ud834"); + QTest::newRow("0xD800") << QString(QChar(0xD800)) << QByteArray("\\ud800"); + QTest::newRow("0xDF06,0xD834") << QString(QChar(0xDF06)).append(QChar(0xD834)) << QByteArray("\\udf06\\ud834"); } void tst_QtJson::escapeSurrogateCodePoints() diff --git a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp index 7249e2a6d8..b0fddf171e 100644 --- a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp @@ -2874,7 +2874,7 @@ void tst_QDataStream::status_QString_data() QString oneMbMinus1; oneMbMinus1.resize(1024 * 1024 - 1); for (int i = 0; i < oneMbMinus1.size(); ++i) - oneMbMinus1[i] = 0x1 | (8 * ((uchar)i / 9)); + oneMbMinus1[i] = QChar(0x1 | (8 * ((uchar)i / 9))); QString threeMbMinus1 = oneMbMinus1 + QChar('j') + oneMbMinus1 + QChar('k') + oneMbMinus1; QByteArray threeMbMinus1Data = qstring2qbytearray(threeMbMinus1); diff --git a/tests/auto/corelib/text/qchar/tst_qchar.cpp b/tests/auto/corelib/text/qchar/tst_qchar.cpp index b150600e36..134862f716 100644 --- a/tests/auto/corelib/text/qchar/tst_qchar.cpp +++ b/tests/auto/corelib/text/qchar/tst_qchar.cpp @@ -115,9 +115,9 @@ void tst_QChar::fromUcs4() void tst_QChar::fromWchar_t() { #if defined(Q_OS_WIN) - QChar aUmlaut = L'\u00E4'; // German small letter a-umlaut + QChar aUmlaut(L'\u00E4'); // German small letter a-umlaut QCOMPARE(aUmlaut, QChar(0xE4)); - QChar replacementCharacter = L'\uFFFD'; + QChar replacementCharacter(L'\uFFFD'); QCOMPARE(replacementCharacter, QChar(QChar::ReplacementCharacter)); #else QSKIP("This is a Windows-only test."); diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 29d794490b..99f42e2815 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -3991,7 +3991,7 @@ void tst_QString::check_QTextIOStream() void tst_QString::fromRawData() { - const QChar ptr[] = { 0x1234, 0x0000 }; + const QChar ptr[] = { QChar(0x1234), QChar(0x0000) }; QString cstr = QString::fromRawData(ptr, 1); QVERIFY(!cstr.isDetached()); QVERIFY(cstr.constData() == ptr); @@ -4008,8 +4008,8 @@ void tst_QString::fromRawData() void tst_QString::setRawData() { - const QChar ptr[] = { 0x1234, 0x0000 }; - const QChar ptr2[] = { 0x4321, 0x0000 }; + const QChar ptr[] = { QChar(0x1234), QChar(0x0000) }; + const QChar ptr2[] = { QChar(0x4321), QChar(0x0000) }; QString cstr; // This just tests the fromRawData() fallback @@ -4278,7 +4278,7 @@ void tst_QString::invalidToLocal8Bit_data() QTest::addColumn<QByteArray>("expect"); // Initial validly-converted prefix { - const QChar malformed[] = { 'A', 0xd800, 'B', 0 }; + const QChar malformed[] = { 'A', QChar(0xd800), 'B', '\0' }; const char expected[] = "A"; QTest::newRow("LoneHighSurrogate") << QString(malformed, sizeof(malformed) / sizeof(QChar)) @@ -4286,28 +4286,28 @@ void tst_QString::invalidToLocal8Bit_data() << QByteArray(expected, sizeof(expected) / sizeof(char) - 1); } { - const QChar malformed[] = { 'A', 0xdc00, 'B', 0 }; + const QChar malformed[] = { 'A', QChar(0xdc00), 'B', '\0' }; const char expected[] = "A"; QTest::newRow("LoneLowSurrogate") << QString(malformed, sizeof(malformed) / sizeof(QChar)) << QByteArray(expected, sizeof(expected) / sizeof(char) - 1); } { - const QChar malformed[] = { 'A', 0xd800, 0xd801, 'B', 0 }; + const QChar malformed[] = { 'A', QChar(0xd800), QChar(0xd801), 'B', '\0' }; const char expected[] = "A"; QTest::newRow("DoubleHighSurrogate") << QString(malformed, sizeof(malformed) / sizeof(QChar)) << QByteArray(expected, sizeof(expected) / sizeof(char) - 1); } { - const QChar malformed[] = { 'A', 0xdc00, 0xdc01, 'B', 0 }; + const QChar malformed[] = { 'A', QChar(0xdc00), QChar(0xdc01), 'B', '\0' }; const char expected[] = "A"; QTest::newRow("DoubleLowSurrogate") << QString(malformed, sizeof(malformed) / sizeof(QChar)) << QByteArray(expected, sizeof(expected) / sizeof(char) - 1); } { - const QChar malformed[] = { 'A', 0xdc00, 0xd800, 'B', 0 }; + const QChar malformed[] = { 'A', QChar(0xdc00), QChar(0xd800), 'B', '\0' }; const char expected[] = "A"; QTest::newRow("ReversedSurrogates") // low before high << QString(malformed, sizeof(malformed) / sizeof(QChar)) diff --git a/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp b/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp index c3ad151a51..a457744867 100644 --- a/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp +++ b/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp @@ -610,7 +610,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.1") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.1-1") << utf8 << str << -1; // 3.3.2 @@ -620,7 +620,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.2") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.2-1") << utf8 << str << -1; utf8.clear(); @@ -628,7 +628,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.2-2") << utf8 << str << -1; utf8 += 0x30; - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.2-3") << utf8 << str << -1; // 3.3.3 @@ -639,7 +639,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-1") << utf8 << str << -1; utf8.clear(); @@ -647,7 +647,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-2") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-3") << utf8 << str << -1; utf8.clear(); @@ -656,7 +656,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-4") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-5") << utf8 << str << -1; // 3.3.4 @@ -668,7 +668,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-1") << utf8 << str << -1; utf8.clear(); @@ -678,7 +678,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-2") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-3") << utf8 << str << -1; utf8.clear(); @@ -687,7 +687,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-4") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-5") << utf8 << str << -1; utf8.clear(); @@ -695,7 +695,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-6") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-7") << utf8 << str << -1; // 3.3.5 @@ -708,7 +708,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-1") << utf8 << str << -1; utf8.clear(); @@ -719,7 +719,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-2") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-3") << utf8 << str << -1; utf8.clear(); @@ -729,7 +729,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-4") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-5") << utf8 << str << -1; utf8.clear(); @@ -738,7 +738,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-6") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-7") << utf8 << str << -1; utf8.clear(); @@ -746,7 +746,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-8") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-9") << utf8 << str << -1; // 3.3.6 @@ -755,7 +755,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.6") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.6-1") << utf8 << str << -1; // 3.3.7 @@ -765,7 +765,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.7") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.7-1") << utf8 << str << -1; utf8.clear(); @@ -773,7 +773,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.7-2") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.7-3") << utf8 << str << -1; // 3.3.8 @@ -784,7 +784,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-1") << utf8 << str << -1; utf8.clear(); @@ -793,7 +793,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-2") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-3") << utf8 << str << -1; utf8.clear(); @@ -801,7 +801,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-4") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-5") << utf8 << str << -1; // 3.3.9 @@ -813,7 +813,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-1") << utf8 << str << -1; utf8.clear(); @@ -823,7 +823,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-2") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-3") << utf8 << str << -1; utf8.clear(); @@ -832,7 +832,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-4") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-5") << utf8 << str << -1; utf8.clear(); @@ -840,7 +840,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-6") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-7") << utf8 << str << -1; // 3.3.10 @@ -853,7 +853,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-1") << utf8 << str << -1; utf8.clear(); @@ -864,7 +864,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-2") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-3") << utf8 << str << -1; utf8.clear(); @@ -874,7 +874,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-4") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-5") << utf8 << str << -1; utf8.clear(); @@ -883,7 +883,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-6") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-7") << utf8 << str << -1; utf8.clear(); @@ -891,7 +891,7 @@ void tst_QStringConverter::utf8Codec_data() str = fromInvalidUtf8Sequence(utf8); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-8") << utf8 << str << -1; utf8 += char(0x30); - str += 0x30; + str += QChar(0x30); QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-9") << utf8 << str << -1; // 3.4 diff --git a/tests/auto/corelib/text/qstringview/tst_qstringview.cpp b/tests/auto/corelib/text/qstringview/tst_qstringview.cpp index 4cff432a2d..42b4767c50 100644 --- a/tests/auto/corelib/text/qstringview/tst_qstringview.cpp +++ b/tests/auto/corelib/text/qstringview/tst_qstringview.cpp @@ -666,7 +666,7 @@ template <typename Char> void tst_QStringView::fromLiteral(const Char *arg) const { const Char *null = nullptr; - const Char empty[] = { 0 }; + const Char empty[] = { Char{} }; QCOMPARE(QStringView(null).size(), qsizetype(0)); QCOMPARE(QStringView(null).data(), nullptr); diff --git a/tests/auto/corelib/text/qtextboundaryfinder/tst_qtextboundaryfinder.cpp b/tests/auto/corelib/text/qtextboundaryfinder/tst_qtextboundaryfinder.cpp index 9c212a6a0b..bd9d91580d 100644 --- a/tests/auto/corelib/text/qtextboundaryfinder/tst_qtextboundaryfinder.cpp +++ b/tests/auto/corelib/text/qtextboundaryfinder/tst_qtextboundaryfinder.cpp @@ -293,7 +293,7 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() QTest::addColumn<QList<int> >("expectedEndPositions"); { - QChar s[] = { 0x000D, 0x000A, 0x000A }; + QChar s[] = { QChar(0x000D), QChar(0x000A), QChar(0x000A) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 2 << 3; @@ -302,7 +302,7 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x000D, 0x0308, 0x000A, 0x000A }; + QChar s[] = { QChar(0x000D), QChar(0x0308), QChar(0x000A), QChar(0x000A) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 1 << 2 << 3 << 4; @@ -366,7 +366,7 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() // Sample Strings from WordBreakTest.html { - QChar s[] = { 0x0063, 0x0061, 0x006E, 0x0027, 0x0074 }; + QChar s[] = { QChar(0x0063), QChar(0x0061), QChar(0x006E), QChar(0x0027), QChar(0x0074) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 5; @@ -377,7 +377,7 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x0063, 0x0061, 0x006E, 0x2019, 0x0074 }; + QChar s[] = { QChar(0x0063), QChar(0x0061), QChar(0x006E), QChar(0x2019), QChar(0x0074) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 5; @@ -388,7 +388,7 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x0061, 0x0062, 0x00AD, 0x0062, 0x0061 }; + QChar s[] = { QChar(0x0061), QChar(0x0062), QChar(0x00AD), QChar(0x0062), QChar(0x0061) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 5; @@ -399,8 +399,10 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x0061, 0x0024, 0x002D, 0x0033, 0x0034, 0x002C, 0x0035, 0x0036, - 0x0037, 0x002E, 0x0031, 0x0034, 0x0025, 0x0062 }; + QChar s[] = { QChar(0x0061), QChar(0x0024), QChar(0x002D), QChar(0x0033), + QChar(0x0034), QChar(0x002C), QChar(0x0035), QChar(0x0036), + QChar(0x0037), QChar(0x002E), QChar(0x0031), QChar(0x0034), + QChar(0x0025), QChar(0x0062) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 1 << 2 << 3 << 12 << 13 << 14; @@ -411,7 +413,7 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x0033, 0x0061 }; + QChar s[] = { QChar(0x0033), QChar(0x0061) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 2; @@ -422,8 +424,9 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x2060, 0x0063, 0x2060, 0x0061, 0x2060, 0x006E, 0x2060, 0x0027, - 0x2060, 0x0074, 0x2060, 0x2060 }; + QChar s[] = { QChar(0x2060), QChar(0x0063), QChar(0x2060), QChar(0x0061), + QChar(0x2060), QChar(0x006E), QChar(0x2060), QChar(0x0027), + QChar(0x2060), QChar(0x0074), QChar(0x2060), QChar(0x2060) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 1 << 12; @@ -434,8 +437,9 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x2060, 0x0063, 0x2060, 0x0061, 0x2060, 0x006E, 0x2060, 0x2019, - 0x2060, 0x0074, 0x2060, 0x2060 }; + QChar s[] = { QChar(0x2060), QChar(0x0063), QChar(0x2060), QChar(0x0061), + QChar(0x2060), QChar(0x006E), QChar(0x2060), QChar(0x2019), + QChar(0x2060), QChar(0x0074), QChar(0x2060), QChar(0x2060) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 1 << 12; @@ -446,8 +450,9 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x2060, 0x0061, 0x2060, 0x0062, 0x2060, 0x00AD, 0x2060, 0x0062, - 0x2060, 0x0061, 0x2060, 0x2060 }; + QChar s[] = { QChar(0x2060), QChar(0x0061), QChar(0x2060), QChar(0x0062), + QChar(0x2060), QChar(0x00AD), QChar(0x2060), QChar(0x0062), + QChar(0x2060), QChar(0x0061), QChar(0x2060), QChar(0x2060) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 1 << 12; @@ -458,10 +463,14 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x2060, 0x0061, 0x2060, 0x0024, 0x2060, 0x002D, 0x2060, 0x0033, - 0x2060, 0x0034, 0x2060, 0x002C, 0x2060, 0x0035, 0x2060, 0x0036, - 0x2060, 0x0037, 0x2060, 0x002E, 0x2060, 0x0031, 0x2060, 0x0034, - 0x2060, 0x0025, 0x2060, 0x0062, 0x2060, 0x2060 }; + QChar s[] = { QChar(0x2060), QChar(0x0061), QChar(0x2060), QChar(0x0024), + QChar(0x2060), QChar(0x002D), QChar(0x2060), QChar(0x0033), + QChar(0x2060), QChar(0x0034), QChar(0x2060), QChar(0x002C), + QChar(0x2060), QChar(0x0035), QChar(0x2060), QChar(0x0036), + QChar(0x2060), QChar(0x0037), QChar(0x2060), QChar(0x002E), + QChar(0x2060), QChar(0x0031), QChar(0x2060), QChar(0x0034), + QChar(0x2060), QChar(0x0025), QChar(0x2060), QChar(0x0062), + QChar(0x2060), QChar(0x2060) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 1 << 3 << 5 << 7 << 25 << 27 << 30; @@ -472,7 +481,8 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x2060, 0x0033, 0x2060, 0x0061, 0x2060, 0x2060 }; + QChar s[] = { QChar(0x2060), QChar(0x0033), QChar(0x2060), QChar(0x0061), + QChar(0x2060), QChar(0x2060) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 1 << 6; @@ -502,7 +512,7 @@ void tst_QTextBoundaryFinder::sentenceBoundaries_manual_data() QTest::addColumn<QList<int> >("expectedBreakPositions"); { - QChar s[] = { 0x000D, 0x000A, 0x000A }; + QChar s[] = { QChar(0x000D), QChar(0x000A), QChar(0x000A) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions; expectedBreakPositions << 0 << 2 << 3; @@ -510,7 +520,7 @@ void tst_QTextBoundaryFinder::sentenceBoundaries_manual_data() QTest::newRow("+CRxLF+LF+") << testString << expectedBreakPositions; } { - QChar s[] = { 0x000D, 0x0308, 0x000A, 0x000A }; + QChar s[] = { QChar(0x000D), QChar(0x0308), QChar(0x000A), QChar(0x000A) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions; expectedBreakPositions << 0 << 1 << 3 << 4; @@ -587,7 +597,7 @@ void tst_QTextBoundaryFinder::lineBoundaries_manual_data() } { - QChar s[] = { 0x000D, 0x0308, 0x000A, 0x000A, 0x0020 }; + QChar s[] = { QChar(0x000D), QChar(0x0308), QChar(0x000A), QChar(0x000A), QChar(0x0020) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedMandatoryBreakPositions; expectedBreakPositions << 0 << 1 << 3 << 4 << 5; @@ -597,7 +607,7 @@ void tst_QTextBoundaryFinder::lineBoundaries_manual_data() << expectedMandatoryBreakPositions; } { - QChar s[] = { 0x000A, 0x2E80, 0x0308, 0x0023, 0x0023 }; + QChar s[] = { QChar(0x000A), QChar(0x2E80), QChar(0x0308), QChar(0x0023), QChar(0x0023) }; QString testString(s, sizeof(s)/sizeof(QChar)); QList<int> expectedBreakPositions, expectedMandatoryBreakPositions; expectedBreakPositions << 0 << 1 << 3 << 5; @@ -607,7 +617,7 @@ void tst_QTextBoundaryFinder::lineBoundaries_manual_data() << expectedMandatoryBreakPositions; } { - QChar s[] = { 0x000A, 0x0308, 0x0023, 0x0023 }; + QChar s[] = { QChar(0x000A), QChar(0x0308), QChar(0x0023), QChar(0x0023) }; QString testString(s, sizeof(s)/sizeof(QChar)); QList<int> expectedBreakPositions, expectedMandatoryBreakPositions; expectedBreakPositions << 0 << 1 << 4; @@ -618,7 +628,7 @@ void tst_QTextBoundaryFinder::lineBoundaries_manual_data() } { - QChar s[] = { 0x0061, 0x00AD, 0x0062, 0x0009, 0x0063, 0x0064 }; + QChar s[] = { QChar(0x0061), QChar(0x00AD), QChar(0x0062), QChar(0x0009), QChar(0x0063), QChar(0x0064) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedMandatoryBreakPositions; expectedBreakPositions << 0 << 2 << 4 << 6; diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp index 85c6f7e6e1..50f9f155d0 100644 --- a/tests/auto/corelib/tools/collections/tst_collections.cpp +++ b/tests/auto/corelib/tools/collections/tst_collections.cpp @@ -1121,17 +1121,17 @@ void tst_Collections::hash() Hash hash; QString key = QLatin1String(" "); for (int i = 0; i < 10; ++i) { - key[0] = i + '0'; + key[0] = QChar(i + '0'); for (int j = 0; j < 10; ++j) { - key[1] = j + '0'; + key[1] = QChar(j + '0'); hash.insert(key, "V" + key); } } for (int i = 0; i < 10; ++i) { - key[0] = i + '0'; + key[0] = QChar(i + '0'); for (int j = 0; j < 10; ++j) { - key[1] = j + '0'; + key[1] = QChar(j + '0'); hash.remove(key); } } diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index 359095c3d0..f61dfda720 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -309,17 +309,17 @@ void tst_QHash::insert1() Hash hash; QString key = QLatin1String(" "); for (int i = 0; i < 10; ++i) { - key[0] = i + '0'; + key[0] = QChar(i + '0'); for (int j = 0; j < 10; ++j) { - key[1] = j + '0'; + key[1] = QChar(j + '0'); hash.insert(key, "V" + key); } } for (int i = 0; i < 10; ++i) { - key[0] = i + '0'; + key[0] = QChar(i + '0'); for (int j = 0; j < 10; ++j) { - key[1] = j + '0'; + key[1] = QChar(j + '0'); hash.remove(key); } } diff --git a/tests/auto/dbus/qdbustype/tst_qdbustype.cpp b/tests/auto/dbus/qdbustype/tst_qdbustype.cpp index f475e87a2b..d7e4b9edcf 100644 --- a/tests/auto/dbus/qdbustype/tst_qdbustype.cpp +++ b/tests/auto/dbus/qdbustype/tst_qdbustype.cpp @@ -105,7 +105,7 @@ static void addFixedTypes() static void addInvalidSingleLetterTypes() { - QChar nulString[] = { 0 }; + QChar nulString[] = { '\0' }; QTest::newRow("nul") << QString(nulString, 1) << false << false; QTest::newRow("tilde") << "~" << false << false; QTest::newRow("struct-begin") << "(" << false << false; diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp index f00d6215c3..7433d2c534 100644 --- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp @@ -1149,8 +1149,8 @@ void tst_QTextLayout::graphemeBoundaryForSurrogatePairs() { QString txt; txt.append(QLatin1Char('a')); - txt.append(0xd87e); - txt.append(0xdc25); + txt.append(QChar(0xd87e)); + txt.append(QChar(0xdc25)); txt.append(QLatin1Char('b')); QTextLayout layout(txt); QTextEngine *engine = layout.engine(); diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index 9b11bcdec1..83c6ed1c9f 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -2861,7 +2861,7 @@ void tst_QHeaderView::additionalInit() model->setData(model->index(i, 0), QVariant(i)); s.setNum(i); s += QLatin1Char('.'); - s += 'a' + (i % 25); + s += QChar('a' + (i % 25)); model->setData(model->index(i, 1), QVariant(s)); } m_tableview->setUpdatesEnabled(updates_enabled); diff --git a/tests/auto/xml/dom/qdom/tst_qdom.cpp b/tests/auto/xml/dom/qdom/tst_qdom.cpp index 5bf0384cca..4bdcc42682 100644 --- a/tests/auto/xml/dom/qdom/tst_qdom.cpp +++ b/tests/auto/xml/dom/qdom/tst_qdom.cpp @@ -1833,7 +1833,7 @@ void tst_QDom::appendDocumentNode() const static const QChar umlautName[] = { - 'a', 0xfc, 'b' + 'a', '\xfc', 'b' }; /*! diff --git a/tests/benchmarks/gui/image/qpixmapcache/tst_qpixmapcache.cpp b/tests/benchmarks/gui/image/qpixmapcache/tst_qpixmapcache.cpp index 2ded426cdd..b1f1a4c083 100644 --- a/tests/benchmarks/gui/image/qpixmapcache/tst_qpixmapcache.cpp +++ b/tests/benchmarks/gui/image/qpixmapcache/tst_qpixmapcache.cpp @@ -164,12 +164,12 @@ void tst_QPixmapCache::styleUseCaseComplexKey() { styleStruct myStruct; myStruct.key = QString("my-progressbar-%1").arg(i); - myStruct.key = 5; - myStruct.key = 4; - myStruct.key = 3; + myStruct.key = QChar(5); + myStruct.key = QChar(4); + myStruct.key = QChar(3); myStruct.palette = 358; myStruct.width = 100; - myStruct.key = 200; + myStruct.key = QChar(200); QPixmapCache::Key key = QPixmapCache::insert(p); hash.insert(myStruct, key); } @@ -177,12 +177,12 @@ void tst_QPixmapCache::styleUseCaseComplexKey() { styleStruct myStruct; myStruct.key = QString("my-progressbar-%1").arg(i); - myStruct.key = 5; - myStruct.key = 4; - myStruct.key = 3; + myStruct.key = QChar(5); + myStruct.key = QChar(4); + myStruct.key = QChar(3); myStruct.palette = 358; myStruct.width = 100; - myStruct.key = 200; + myStruct.key = QChar(200); QPixmapCache::Key key = hash.value(myStruct); QPixmapCache::find(key, &p); } diff --git a/tests/benchmarks/widgets/itemviews/qheaderview/qheaderviewbench.cpp b/tests/benchmarks/widgets/itemviews/qheaderview/qheaderviewbench.cpp index 49ce060580..65d467d345 100644 --- a/tests/benchmarks/widgets/itemviews/qheaderview/qheaderviewbench.cpp +++ b/tests/benchmarks/widgets/itemviews/qheaderview/qheaderviewbench.cpp @@ -126,7 +126,7 @@ void BenchQHeaderView::init() m_model->setData(m_model->index(i, 0), QVariant(i)); s.setNum(i); s += QLatin1Char('.'); - s += 'a' + (i % 25); + s += QLatin1Char('a' + (i % 25)); m_model->setData(m_model->index(i, 1), QVariant(s)); } m_tv->setUpdatesEnabled(m_updatesEnabled); |