From e6f07a6fe45193fae96e381c164d42b150ae7330 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 28 Nov 2021 18:35:15 +0800 Subject: [PATCH 1/5] Use implicit copy-constructor generated by compiler This also suppresses the following clang warning: warning: definition of implicit copy assignment operator for 'Version' is deprecated because it has a user-declared copy constructor [-Wdeprecated-copy] --- src/base/bittorrent/infohash.h | 1 - src/base/digest32.h | 1 - src/base/utils/version.h | 9 ++------- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/base/bittorrent/infohash.h b/src/base/bittorrent/infohash.h index 31fd0ee55..d7848a151 100644 --- a/src/base/bittorrent/infohash.h +++ b/src/base/bittorrent/infohash.h @@ -64,7 +64,6 @@ namespace BitTorrent #endif InfoHash() = default; - InfoHash(const InfoHash &other) = default; InfoHash(const WrappedType &nativeHash); bool isValid() const; diff --git a/src/base/digest32.h b/src/base/digest32.h index ece84af41..2241ef691 100644 --- a/src/base/digest32.h +++ b/src/base/digest32.h @@ -41,7 +41,6 @@ public: using UnderlyingType = lt::digest32; Digest32() = default; - Digest32(const Digest32 &other) = default; Digest32(const UnderlyingType &nativeDigest) : m_valid {true} diff --git a/src/base/utils/version.h b/src/base/utils/version.h index a03ea9155..12c7f75d1 100644 --- a/src/base/utils/version.h +++ b/src/base/utils/version.h @@ -48,12 +48,7 @@ namespace Utils typedef T ComponentType; typedef Version ThisType; - constexpr Version() - : m_components {{}} - { - } - - constexpr Version(const ThisType &other) = default; + constexpr Version() = default; template constexpr Version(Other ... components) @@ -187,7 +182,7 @@ namespace Utils { } - ComponentsArray m_components; + ComponentsArray m_components {{}}; }; template From c8b66b25e8d241180ed9bf621eef51c9be51e1a4 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 28 Nov 2021 19:42:35 +0800 Subject: [PATCH 2/5] Avoid potential container detachment Suppress clazy warning: warning: Don't call QList::operator[]() on temporary [-Wclazy-detaching-temporary] --- src/base/bittorrent/torrentimpl.cpp | 2 +- src/base/utils/misc.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index 27a968356..f2f65ab4d 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -1616,7 +1616,7 @@ void TorrentImpl::renameFile(const int index, const QString &path) m_oldPath[index].push_back(oldPath); #endif ++m_renameCount; - m_nativeHandle.rename_file(m_torrentInfo.nativeIndexes()[index], Utils::Fs::toNativePath(path).toStdString()); + m_nativeHandle.rename_file(m_torrentInfo.nativeIndexes().at(index), Utils::Fs::toNativePath(path).toStdString()); } void TorrentImpl::handleStateUpdate(const lt::torrent_status &nativeStatus) diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index ad3e15665..d72db3cd1 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -498,7 +498,7 @@ QString Utils::Misc::opensslVersionString() #else static const auto version {QString::fromLatin1(SSLeay_version(SSLEAY_VERSION))}; #endif - return QStringView(version).split(u' ', Qt::SkipEmptyParts)[1].toString(); + return QStringView(version).split(u' ', Qt::SkipEmptyParts).at(1).toString(); } QString Utils::Misc::zlibVersionString() From 0f34e3bed9636b6b0221213a0e0e8e2a4cebc823 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 28 Nov 2021 19:51:47 +0800 Subject: [PATCH 3/5] Don't use deprecated Q_ENUMS See: https://doc.qt.io/qt-5/qobject-obsolete.html#Q_ENUMS --- src/gui/fspathedit.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/fspathedit.h b/src/gui/fspathedit.h index 25e747500..d9f9d5e63 100644 --- a/src/gui/fspathedit.h +++ b/src/gui/fspathedit.h @@ -44,7 +44,6 @@ namespace Private class FileSystemPathEdit : public QWidget { Q_OBJECT - Q_ENUMS(Mode) Q_PROPERTY(Mode mode READ mode WRITE setMode) Q_PROPERTY(QString selectedPath READ selectedPath WRITE setSelectedPath NOTIFY selectedPathChanged) Q_PROPERTY(QString fileNameFilter READ fileNameFilter WRITE setFileNameFilter) @@ -60,6 +59,7 @@ public: DirectoryOpen, //!< selecting existing directories DirectorySave //!< selecting directories for saving }; + Q_ENUM(Mode) Mode mode() const; void setMode(Mode mode); From 0e1849346bf184bd8be480352eb5768085f976e7 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 28 Nov 2021 20:34:14 +0800 Subject: [PATCH 4/5] Avoid iterating over a temporary variable --- src/gui/categoryfiltermodel.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/categoryfiltermodel.cpp b/src/gui/categoryfiltermodel.cpp index 7a910d463..8e288a449 100644 --- a/src/gui/categoryfiltermodel.cpp +++ b/src/gui/categoryfiltermodel.cpp @@ -412,7 +412,8 @@ void CategoryFilterModel::populate() , [](Torrent *torrent) { return torrent->category().isEmpty(); }))); using Torrent = BitTorrent::Torrent; - for (auto i = session->categories().cbegin(); i != session->categories().cend(); ++i) + const QStringMap categories = session->categories(); + for (auto i = categories.cbegin(); i != categories.cend(); ++i) { const QString &category = i.key(); if (m_isSubcategoriesEnabled) From 19d95ebd10dffc8cbec3b926c3fd2a7204cef356 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 29 Nov 2021 01:28:07 +0800 Subject: [PATCH 5/5] Add comment for qHash implementation requirements As clazy report false-positive on this. --- src/base/bittorrent/ltqhash.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/base/bittorrent/ltqhash.h b/src/base/bittorrent/ltqhash.h index 668aaa850..ad0625c62 100644 --- a/src/base/bittorrent/ltqhash.h +++ b/src/base/bittorrent/ltqhash.h @@ -34,6 +34,9 @@ #include +// From https://doc.qt.io/qt-6/qhash.html#the-hashing-function: +// A hashing function for a key type K may be provided in two different ways. +// The first way is by having an overload of qHash() in K's namespace. namespace libtorrent { namespace aux