From fd308819891fdc3c4296050193e97f5d9259501f Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Wed, 7 Jul 2021 13:14:34 +0200 Subject: [PATCH] QProperty: Downgrade assert in noSelfDependencies to warning We call evaluateRecursive_inline in setBinding, which in turns runs the noSelfDependecies check. However, creating a binding resuting in a binding loop must not crash, but instead result in the binding entering an error state. To prevent a crash caused by the assert in debug builds of Qt, we replace the assert with a warning for now. A better approach in the future would be to ensure that we only run the check in cases where we are sure that a self-dependency is really a fatal error. Pick-to: 6.2 Change-Id: I58158864ed81fa907132a4e7d6667c9b529e7e64 Reviewed-by: Maximilian Goldstein --- src/corelib/kernel/qproperty.cpp | 5 ++++- tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp index 965939a1fc..f1c8adb8a0 100644 --- a/src/corelib/kernel/qproperty.cpp +++ b/src/corelib/kernel/qproperty.cpp @@ -744,7 +744,10 @@ void QPropertyObserverPointer::noSelfDependencies(QPropertyBindingPrivate *bindi // See also comment in notify() while (observer) { if (QPropertyObserver::ObserverTag(observer->next.tag()) == QPropertyObserver::ObserverNotifiesBinding) - Q_ASSERT(observer->binding != binding); + if (observer->binding == binding) { + qCritical("Property depends on itself!"); + break; + } observer = observer->next.data(); } diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp index fb99ed1880..6e63792a11 100644 --- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp +++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp @@ -113,6 +113,8 @@ private slots: void notify(); void bindableInterfaceOfCompatPropertyUsesSetter(); + + void selfBindingShouldNotCrash(); }; void tst_QProperty::functorBinding() @@ -1847,6 +1849,13 @@ void tst_QProperty::bindableInterfaceOfCompatPropertyUsesSetter() QCOMPARE(obj.setCompatCalled, 1); } +void tst_QProperty::selfBindingShouldNotCrash() +{ + QProperty i; + i.setBinding([&](){ return i+1; }); + QVERIFY(i.binding().error().hasError()); +} + QTEST_MAIN(tst_QProperty); #undef QT_SOURCE_LOCATION_NAMESPACE