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); | ~~~~~~~~~~~~~~~~~~~~^~~ Change-Id: I03d54b56769cbd0f9f1165e4679ec4947267181a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 3a9526468c134b68b64b9a3bb6278d47c266e381) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
b024426ee9
commit
2b0ea48258
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user