Handle a couple of GCC 13 warnings about dangling references

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<QVariant>::at(0)’
 1845 |     const QVariant &retval = reply.arguments().at(0);
      |                              ~~~~~~~~~~~~~~~~~~~~^~~

Pick-to: 6.6 6.5 5.15
Change-Id: I03d54b56769cbd0f9f1165e4679ec4947267181a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Ahmad Samir 2023-06-24 19:41:15 +03:00
parent 70a7a695fd
commit 3a9526468c
2 changed files with 6 additions and 2 deletions

View File

@ -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);
}

View File

@ -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()