diff options
author | Marc Mutz <marc.mutz@qt.io> | 2024-05-22 13:43:44 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-05-22 23:37:17 +0000 |
commit | 78974f8219629f463b5e4b370be2fb574061760b (patch) | |
tree | 3412e086d9390d6ee02b1da222daf19d71fa69a7 | |
parent | tst_QByteArrayView: (re)fix GCC ubsan build (diff) | |
download | qtbase-78974f8219629f463b5e4b370be2fb574061760b.tar.xz qtbase-78974f8219629f463b5e4b370be2fb574061760b.zip |
tst_QStringView: (re)fix GCC ubsan build
Move the constexpr fromArray() check from fromArray() to constExpr()
and there add the protection necessary to work around
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71962, copied from
tst_QByteArrayView.
As a drive-by, add the test for constexpr construction from a char16_t
array, which was missing here (probably because of the GCC bug) while
the corresponding test was already in tst_QByteArrayView.
Amends 107ff4c1d6b5da2cb11c65b2bd9106817f7fdb02(!).
(iow: 6.0, and no, I don't know why it became a problem only now)
Pick-to: 6.5 6.2
Change-Id: Id9d2a08175709f8bf85b3b192e7aa49783b9e715
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 3f3be9d7745dc6a6b16efdd940ccd12f6622c467)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | tests/auto/corelib/text/qstringview/CMakeLists.txt | 7 | ||||
-rw-r--r-- | tests/auto/corelib/text/qstringview/tst_qstringview.cpp | 26 |
2 files changed, 32 insertions, 1 deletions
diff --git a/tests/auto/corelib/text/qstringview/CMakeLists.txt b/tests/auto/corelib/text/qstringview/CMakeLists.txt index ba5f540838..b541cdd0ed 100644 --- a/tests/auto/corelib/text/qstringview/CMakeLists.txt +++ b/tests/auto/corelib/text/qstringview/CMakeLists.txt @@ -18,5 +18,12 @@ qt_internal_add_test(tst_qstringview Qt::CorePrivate ) +if(QT_FEATURE_sanitize_undefined) + qt_internal_extend_target(tst_qstringview + DEFINES + QT_SANITIZE_UNDEFINED # GCC (in)famously doesn't provide a predefined macro for this + ) +endif() + ## Scopes: ##################################################################### diff --git a/tests/auto/corelib/text/qstringview/tst_qstringview.cpp b/tests/auto/corelib/text/qstringview/tst_qstringview.cpp index df3ef94371..3f87ffc9fc 100644 --- a/tests/auto/corelib/text/qstringview/tst_qstringview.cpp +++ b/tests/auto/corelib/text/qstringview/tst_qstringview.cpp @@ -359,6 +359,30 @@ void tst_QStringView::constExpr() const static_assert(sv3.isEmpty()); static_assert(sv3.size() == 0); } +#if !defined(Q_CC_GNU_ONLY) || !defined(QT_SANITIZE_UNDEFINED) + // Below checks are disabled because of a compilation issue with GCC and + // -fsanitize=undefined. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71962. + { + static constexpr char16_t hello[] = u"Hello"; + constexpr QStringView sv(hello); + static_assert(sv.size() == 5); + static_assert(!sv.empty()); + static_assert(!sv.isEmpty()); + static_assert(!sv.isNull()); + static_assert(*sv.utf16() == 'H'); + static_assert(sv[0] == QLatin1Char('H')); + static_assert(sv.at(0) == QLatin1Char('H')); + static_assert(sv.front() == QLatin1Char('H')); + static_assert(sv.first() == QLatin1Char('H')); + static_assert(sv[4] == QLatin1Char('o')); + static_assert(sv.at(4) == QLatin1Char('o')); + static_assert(sv.back() == QLatin1Char('o')); + static_assert(sv.last() == QLatin1Char('o')); + + constexpr auto sv2 = QStringView::fromArray(hello); + QCOMPARE_EQ(sv, sv2.chopped(1)); + } +#endif // -fsanitize=undefined } void tst_QStringView::basics() const @@ -430,7 +454,7 @@ void tst_QStringView::fromArray() const { static constexpr char16_t hello[] = u"Hello\0abc\0\0."; - constexpr QStringView sv = QStringView::fromArray(hello); + const QStringView sv = QStringView::fromArray(hello); QCOMPARE(sv.size(), 13); QVERIFY(!sv.empty()); QVERIFY(!sv.isEmpty()); |