diff --git a/tests/auto/corelib/tools/qspan/tst_qspan.cpp b/tests/auto/corelib/tools/qspan/tst_qspan.cpp index 95c60ee9532..3c496b00a8d 100644 --- a/tests/auto/corelib/tools/qspan/tst_qspan.cpp +++ b/tests/auto/corelib/tools/qspan/tst_qspan.cpp @@ -129,6 +129,8 @@ private Q_SLOTS: void fromQList() const; void fromInitList() const; + void constQSpansDontDetachQtContainers() const; + private: template void check_nonempty_span(QSpan, qsizetype expectedSize) const; @@ -440,6 +442,32 @@ void tst_QSpan::fromQList() const from_variable_size_container_impl(li); } +void tst_QSpan::constQSpansDontDetachQtContainers() const +{ + QList li = {42, 84, 168, 336}; + + { + [[maybe_unused]] const QList copy = li; + QVERIFY(!li.isDetached()); + [[maybe_unused]] QSpan cvspan = li; // should not detach (QTBUG-132133) + QEXPECT_FAIL("", "QTBUG-132133", Continue); + QVERIFY(!li.isDetached()); + [[maybe_unused]] QSpan mvspan = li; // this _has_ to detach, though + QVERIFY(li.isDetached()); + } + + // same check for fixed-size spans + { + [[maybe_unused]] const QList copy = li; + QVERIFY(!li.isDetached()); + [[maybe_unused]] QSpan cfspan = li; // should not detach (QTBUG-132133) + QEXPECT_FAIL("", "QTBUG-132133", Continue); + QVERIFY(!li.isDetached()); + [[maybe_unused]] QSpan mfspan = li; // this _has_ to detach, though + QVERIFY(li.isDetached()); + } +} + void tst_QSpan::fromInitList() const { from_variable_size_container_impl(std::initializer_list{42, 84, 168, 336});