tst_QSpan: check QList<int> -> QSpan<const int> doesn't detach the former
It does. While std::span, does, too, and so users should be using std::as_const(), it's quite simple to avoid for QSpan, so we'll fix it in QSpan. This patch adds the reproducer. Task-number: QTBUG-132133 Change-Id: I2e416fb7344830cd5e0d945cce61491cd6f4a7a5 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 05b9a4b2deefd586356e1f36d84372b06e74cfe3) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit aff082764ae2dc6ca3c7e9c9ee6573bdd5b4a2de)
This commit is contained in:
parent
f5bd78e142
commit
cad7935b6f
@ -129,6 +129,8 @@ private Q_SLOTS:
|
||||
void fromQList() const;
|
||||
void fromInitList() const;
|
||||
|
||||
void constQSpansDontDetachQtContainers() const;
|
||||
|
||||
private:
|
||||
template <typename T, std::size_t N>
|
||||
void check_nonempty_span(QSpan<T, N>, qsizetype expectedSize) const;
|
||||
@ -440,6 +442,32 @@ void tst_QSpan::fromQList() const
|
||||
from_variable_size_container_impl(li);
|
||||
}
|
||||
|
||||
void tst_QSpan::constQSpansDontDetachQtContainers() const
|
||||
{
|
||||
QList<int> li = {42, 84, 168, 336};
|
||||
|
||||
{
|
||||
[[maybe_unused]] const QList copy = li;
|
||||
QVERIFY(!li.isDetached());
|
||||
[[maybe_unused]] QSpan<const int> cvspan = li; // should not detach (QTBUG-132133)
|
||||
QEXPECT_FAIL("", "QTBUG-132133", Continue);
|
||||
QVERIFY(!li.isDetached());
|
||||
[[maybe_unused]] QSpan<int> 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<const int, 4> cfspan = li; // should not detach (QTBUG-132133)
|
||||
QEXPECT_FAIL("", "QTBUG-132133", Continue);
|
||||
QVERIFY(!li.isDetached());
|
||||
[[maybe_unused]] QSpan<int, 4> mfspan = li; // this _has_ to detach, though
|
||||
QVERIFY(li.isDetached());
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QSpan::fromInitList() const
|
||||
{
|
||||
from_variable_size_container_impl(std::initializer_list<int>{42, 84, 168, 336});
|
||||
|
Loading…
x
Reference in New Issue
Block a user