From 2b0ea4825859fd8a5cee0d2c34e4494d82cd63cd Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Sat, 24 Jun 2023 19:41:15 +0300 Subject: [PATCH] Handle a couple of GCC 13 warnings about dangling references MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are two temporaries, reply.arguments() returns a temporary QList and list.at(0) returns a temporary reference to the first element. The local reference variable would only extend the lifetime of the temporary object it's bound to, list.at(0), but not the temporary list itself. Even though this a false positive in this case because QList is implicilty shared, the compiler can't tell the difference and the fix is simple. tests/auto/dbus/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp:1845:21: warning: possibly dangling reference to a temporary [-Wdangling-reference] 1845 | const QVariant &retval = reply.arguments().at(0); | ^~~~~~ tests/auto/dbus/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp:1845:50: note: the temporary was destroyed at the end of the full expression ‘QDBusMessage::arguments() const().QList::at(0)’ 1845 | const QVariant &retval = reply.arguments().at(0); | ~~~~~~~~~~~~~~~~~~~~^~~ Change-Id: I03d54b56769cbd0f9f1165e4679ec4947267181a Reviewed-by: Thiago Macieira (cherry picked from commit 3a9526468c134b68b64b9a3bb6278d47c266e381) Reviewed-by: Qt Cherry-pick Bot --- .../thread/qfuturesynchronizer/tst_qfuturesynchronizer.cpp | 5 +++++ .../dbus/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/auto/corelib/thread/qfuturesynchronizer/tst_qfuturesynchronizer.cpp b/tests/auto/corelib/thread/qfuturesynchronizer/tst_qfuturesynchronizer.cpp index e198bb931e2..0602afc9706 100644 --- a/tests/auto/corelib/thread/qfuturesynchronizer/tst_qfuturesynchronizer.cpp +++ b/tests/auto/corelib/thread/qfuturesynchronizer/tst_qfuturesynchronizer.cpp @@ -50,7 +50,12 @@ void tst_QFutureSynchronizer::setFutureAliasingExistingMember() // around to avoid the warning, as the extra copy would cause a detach() // of m_futures inside setFuture() with the consequence that `f` no longer // aliases an element in m_futures, which is the goal of this test. +QT_WARNING_PUSH +#if defined(Q_CC_GNU_ONLY) && Q_CC_GNU >= 1301 +QT_WARNING_DISABLE_GCC("-Wdangling-reference") +#endif const auto &f = synchronizer.futures().constFirst(); +QT_WARNING_POP synchronizer.setFuture(f); } diff --git a/tests/auto/dbus/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp b/tests/auto/dbus/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp index d1b220127c7..78610fd2d29 100644 --- a/tests/auto/dbus/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp +++ b/tests/auto/dbus/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp @@ -1842,8 +1842,7 @@ void tst_QDBusAbstractAdaptor::typeMatching() QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); QCOMPARE(reply.arguments().size(), 1); - const QVariant &retval = reply.arguments().at(0); - QVERIFY(compare(retval, value)); + QVERIFY(compare(reply.arguments().at(0), value)); } void tst_QDBusAbstractAdaptor::methodWithMoreThanOneReturnValue()