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.7 6.5 6.2 Change-Id: Id9d2a08175709f8bf85b3b192e7aa49783b9e715 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
6d28744e43
commit
3f3be9d774
@ -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:
|
||||
#####################################################################
|
||||
|
@ -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());
|
||||
|
Loading…
x
Reference in New Issue
Block a user