From 0096801556df259d557bb690499e312ff4fe5808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Pereira?= Date: Thu, 11 Jan 2018 19:05:41 +0100 Subject: [PATCH] Don't call non-const member functions on temporaries They can detach if the container is shared. Even if they are not shared, using const method when possible is good practice. Differential Revision: https://phabricator.kde.org/D9730 --- src/lib/3rdparty/lineedit.cpp | 2 +- src/lib/app/commandlineoptions.cpp | 2 +- tests/autotests/passwordbackendtest.cpp | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/lib/3rdparty/lineedit.cpp b/src/lib/3rdparty/lineedit.cpp index 6bf6ff630..602fdb9c7 100644 --- a/src/lib/3rdparty/lineedit.cpp +++ b/src/lib/3rdparty/lineedit.cpp @@ -219,7 +219,7 @@ QMenu* LineEdit::createContextMenu() QMenu* tmp = createStandardContextMenu(); tmp->setParent(popup); tmp->hide(); - QAction* lastAction = !tmp->actions().isEmpty() ? tmp->actions().last() : 0; + QAction* lastAction = !tmp->actions().isEmpty() ? tmp->actions().constLast() : 0; if (lastAction && lastAction->menu() && lastAction->menu()->inherits("QUnicodeControlCharacterMenu")) { popup->addAction(lastAction); diff --git a/src/lib/app/commandlineoptions.cpp b/src/lib/app/commandlineoptions.cpp index 681cb42c4..4c5a045e8 100644 --- a/src/lib/app/commandlineoptions.cpp +++ b/src/lib/app/commandlineoptions.cpp @@ -189,7 +189,7 @@ void CommandLineOptions::parseActions() if (parser.positionalArguments().isEmpty()) return; - QString url = parser.positionalArguments().last(); + QString url = parser.positionalArguments().constLast(); QFileInfo fileInfo(url); if (fileInfo.exists()) { diff --git a/tests/autotests/passwordbackendtest.cpp b/tests/autotests/passwordbackendtest.cpp index e80efd8c1..a9f237347 100644 --- a/tests/autotests/passwordbackendtest.cpp +++ b/tests/autotests/passwordbackendtest.cpp @@ -96,14 +96,14 @@ void PasswordBackendTest::storeTest() m_backend->addEntry(entry); // Check entry that may be stored in cache - PasswordEntry stored = m_backend->getEntries(QUrl("org.qupzilla.google.com")).first(); + PasswordEntry stored = m_backend->getEntries(QUrl("org.qupzilla.google.com")).constFirst(); QVERIFY(compareEntries(stored, entry) == true); reloadBackend(); // Check entry retrieved from backend engine QVERIFY(!m_backend->getEntries(QUrl("org.qupzilla.google.com")).isEmpty()); - stored = m_backend->getEntries(QUrl("org.qupzilla.google.com")).first(); + stored = m_backend->getEntries(QUrl("org.qupzilla.google.com")).constFirst(); QVERIFY(compareEntries(stored, entry) == true); @@ -118,13 +118,13 @@ void PasswordBackendTest::storeTest() m_backend->addEntry(entry2); // Check entry that may be stored in cache - PasswordEntry stored2 = m_backend->getEntries(QUrl("org.qupzilla.qupzilla.com")).first(); + PasswordEntry stored2 = m_backend->getEntries(QUrl("org.qupzilla.qupzilla.com")).constFirst(); QVERIFY(compareEntries(stored2, entry2) == true); reloadBackend(); // Check entry retrieved from backend engine - stored2 = m_backend->getEntries(QUrl("org.qupzilla.qupzilla.com")).first(); + stored2 = m_backend->getEntries(QUrl("org.qupzilla.qupzilla.com")).constFirst(); QVERIFY(compareEntries(stored2, entry2) == true); /* Cleanup */ @@ -203,13 +203,13 @@ void PasswordBackendTest::updateLastUsedTest() m_backend->addEntry(entry); QVERIFY(!m_backend->getEntries(QUrl("org.qupzilla.google.com")).isEmpty()); - QVERIFY(compareEntries(entry, m_backend->getEntries(QUrl("org.qupzilla.google.com")).first())); + QVERIFY(compareEntries(entry, m_backend->getEntries(QUrl("org.qupzilla.google.com")).constFirst())); reloadBackend(); QVERIFY(!m_backend->getEntries(QUrl("org.qupzilla.google.com")).isEmpty()); - QVERIFY(compareEntries(entry, m_backend->getEntries(QUrl("org.qupzilla.google.com")).first())); + QVERIFY(compareEntries(entry, m_backend->getEntries(QUrl("org.qupzilla.google.com")).constFirst())); - m_backend->removeEntry(m_backend->getEntries(QUrl("org.qupzilla.google.com")).first()); - m_backend->removeEntry(m_backend->getEntries(QUrl("org.qupzilla.google.com")).first()); + m_backend->removeEntry(m_backend->getEntries(QUrl("org.qupzilla.google.com")).constFirst()); + m_backend->removeEntry(m_backend->getEntries(QUrl("org.qupzilla.google.com")).constFirst()); QCOMPARE(m_backend->getAllEntries().count(), 0); reloadBackend(); @@ -284,7 +284,7 @@ void KWalletPasswordBackendTest::init() msg << quint32(0); QDBusMessage reply = QDBusConnection::sessionBus().call(msg); - if (reply.arguments().isEmpty() || reply.arguments().first().toInt() != 1) + if (reply.arguments().isEmpty() || reply.arguments().constFirst().toInt() != 1) QSKIP("This test requires org.kde.kwalletd5 service."); } @@ -307,7 +307,7 @@ void GnomeKeyringPasswordBackendTest::init() msg << quint32(0); QDBusMessage reply = QDBusConnection::sessionBus().call(msg); - if (reply.arguments().isEmpty() || reply.arguments().first().toInt() != 1) + if (reply.arguments().isEmpty() || reply.arguments().constFirst().toInt() != 1) QSKIP("This test requires org.freedesktop.secrets service."); }