From c19c6aa11e3d35bdd2741e9f31725c495be431aa Mon Sep 17 00:00:00 2001 From: Ville Voutilainen Date: Tue, 15 Nov 2022 03:28:11 +0200 Subject: [PATCH] Fix dangling references These were found with the help of -Wdangling-reference, which is new in GCC 13. The one in qtpaths.cpp is a false positive: parseLocationOrError() returns a reference, so there's nothing for the full expression to destroy. Moreover, it returns a reference to a static object, so there's no destruction inside the function either. The other two aren't, but are also harmless. QDBusMessage::arguments() and QVariant::toList() return a stored QVariantList by value, so QList's COW mechanism means at() returns a reference that will not be destroyed. However, the compiler has no way of knowing that. And since it depends on the implementation details, change the code to not depend on that. Change-Id: If53aa16fcc24586d752ffc76c193c81e43dc9d95 Reviewed-by: Thiago Macieira (cherry picked from commit 18def77d27f88ce26b6af29fe56a80429fed555d) Reviewed-by: Qt Cherry-pick Bot --- src/dbus/qdbusintegrator.cpp | 3 ++- src/gui/text/qcssparser.cpp | 3 ++- src/tools/qtpaths/qtpaths.cpp | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index db746d16dab..78b87c25c17 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -913,7 +913,8 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q if (id == QDBusMetaTypeId::message()) break; - const QVariant &arg = msg.arguments().at(i - 1); + const QList args = msg.arguments(); + const QVariant &arg = args.at(i - 1); if (arg.metaType() == id) // no conversion needed params.append(const_cast(arg.constData())); diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp index 2f3c04dc54e..f79369a36b0 100644 --- a/src/gui/text/qcssparser.cpp +++ b/src/gui/text/qcssparser.cpp @@ -1439,7 +1439,8 @@ QColor Declaration::colorValue(const QPalette &pal) const return pal.color((QPalette::ColorRole)(d->parsed.toInt())); case qMetaTypeId>(): if (d->parsed.toList().size() == 1) { - const auto &value = d->parsed.toList().at(0); + auto parsedList = d->parsed.toList(); + const auto &value = parsedList.at(0); return qvariant_cast(value); } break; diff --git a/src/tools/qtpaths/qtpaths.cpp b/src/tools/qtpaths/qtpaths.cpp index b4e2d749aa3..fa29381d789 100644 --- a/src/tools/qtpaths/qtpaths.cpp +++ b/src/tools/qtpaths/qtpaths.cpp @@ -252,6 +252,10 @@ int main(int argc, char **argv) results << typesList.join('\n'); } + QT_WARNING_PUSH +#if defined(Q_CC_GNU_ONLY) && Q_CC_GNU >= 1300 && Q_CC_GNU < 1400 + QT_WARNING_DISABLE_GCC("-Wdangling-reference") +#endif if (parser.isSet(display)) { const StringEnum &location = parseLocationOrError(parser.value(display)); QString text = QStandardPaths::displayName(location.enumvalue); @@ -303,6 +307,7 @@ int main(int argc, char **argv) QStringList paths = QStandardPaths::locateAll(location.enumvalue, searchitem, QStandardPaths::LocateFile); results << location.mapName(paths.join(pathsep)); } + QT_WARNING_POP #if !QT_CONFIG(settings) if (parser.isSet(query) || parser.isSet(qtconf) || parser.isSet(queryformat)) {