From 32602bef7c40261cbe61d72e8cf043feb3734d3e Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 20 Jun 2025 11:57:49 +0200 Subject: QmlCompiler: Sharpen side effect detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stack-created lists of primitives or pointers cannot be affected by side effects. We cannot write a value affected by side effects to a list that isn't, though. Pick-to: 6.10 6.9 6.8 6.5 Task-number: QTBUG-137540 Change-Id: I99ab4337cabc6111a81b8164fd94962edc0db25e Reviewed-by: Olivier De Cannière --- tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp') diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index b322f870fa..5ec98cbdaf 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -5670,8 +5670,16 @@ void tst_QmlCppCodegen::valueTypeBehavior() void tst_QmlCppCodegen::valueTypeLists() { QQmlEngine engine; - QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/valueTypeLists.qml"_s)); + const QUrl url(u"qrc:/qt/qml/TestTypes/valueTypeLists.qml"_s); + QQmlComponent c(&engine, url); QVERIFY2(c.isReady(), qPrintable(c.errorString())); + + const QString bindingLoop = url.toString() + + uR"(:3:1: QML QObject*: Binding loop detected for property "rectList2": +qrc:/qt/qml/TestTypes/valueTypeLists.qml:19:5)"_s; + for (int i = 0; i < 2; ++i) + QTest::ignoreMessage(QtWarningMsg, qPrintable(bindingLoop)); + QScopedPointer o(c.create()); QCOMPARE(qvariant_cast(o->property("rectInBounds")), QRectF(1, 2, 3, 4)); @@ -5689,6 +5697,10 @@ void tst_QmlCppCodegen::valueTypeLists() QCOMPARE(qvariant_cast(o->property("charInBounds")), QStringLiteral("d")); QVERIFY(o->metaObject()->indexOfProperty("charOutOfBounds") > 0); QVERIFY(!o->property("charOutOfBounds").isValid()); + + const QList rectList = o->property("rectList2").value>(); + QCOMPARE(rectList.length(), 1); + QCOMPARE(rectList[0], QRectF(666, 13, 14, 15)); } void tst_QmlCppCodegen::valueTypeProperty() @@ -5851,6 +5863,13 @@ void tst_QmlCppCodegen::writeAndReturnTempArray() const QVariant nnn = object->property("nnn"); QCOMPARE(nnn.metaType(), QMetaType::fromType>()); QCOMPARE(nnn.value>(), QList{10}); + + const QVariant numbers = object->property("numbers"); + QCOMPARE(numbers.metaType(), QMetaType::fromType>()); + const QList numbersContent = numbers.value>(); + QCOMPARE(numbersContent.length(), 32); + for (double number: std::as_const(numbersContent)) + QVERIFY(number >= 0 && number < double(0xf0f0f0)); } QTEST_MAIN(tst_QmlCppCodegen) -- cgit v1.2.3