From bd72b8c3fc9fb87480dbfaa317632ee054d414a8 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Sat, 21 Jan 2023 15:06:20 +0300 Subject: [PATCH] Fix clang-tidy issues stemming from header files (GTK client) (#4623) * Fix `readability-avoid-const-params-in-decls` clang-tidy issues * Fix `bugprone-macro-parentheses` clang-tidy issues * Fix `modernize-use-using` clang-tidy issues * Fix `readability-named-parameter` clang-tidy issues * Fix `cppcoreguidelines-owning-memory` clang-tidy issues * Fix `cppcoreguidelines-special-member-functions` clang-tidy issues * Fix `cppcoreguidelines-macro-usage` clang-tidy issues * Fix `modernize-use-nodiscard` clang-tidy issues * Fix `cppcoreguidelines-macro-usage` clang-tidy issues * Add headers filter for /gtk/ subdirectory --- gtk/.clang-tidy | 2 ++ gtk/DetailsDialog.cc | 4 ++-- gtk/FilterBase.h | 5 +++++ gtk/FilterListModel.hh | 1 + gtk/Flags.h | 18 +++++++++++------- gtk/GtkCompat.h | 4 ++++ gtk/ListModelAdapter.h | 1 + gtk/OptionsDialog.cc | 6 +++--- gtk/OptionsDialog.h | 6 +++++- gtk/Prefs.h | 20 ++++++++++---------- gtk/SortListModel.hh | 1 + gtk/SorterBase.h | 5 +++++ gtk/Utils.cc | 12 ++++++------ gtk/Utils.h | 8 +++----- 14 files changed, 59 insertions(+), 34 deletions(-) diff --git a/gtk/.clang-tidy b/gtk/.clang-tidy index 9421c5dcc..4f8c8a34c 100644 --- a/gtk/.clang-tidy +++ b/gtk/.clang-tidy @@ -1,4 +1,6 @@ --- +HeaderFilterRegex: .*/gtk/.* + Checks: > -*, bugprone-*, diff --git a/gtk/DetailsDialog.cc b/gtk/DetailsDialog.cc index 15351caf6..26f7ed2aa 100644 --- a/gtk/DetailsDialog.cc +++ b/gtk/DetailsDialog.cc @@ -363,7 +363,7 @@ void DetailsDialog::Impl::refreshOptions(std::vector const& torrent if (is_uniform) { bandwidth_combo_tag_.block(); - gtr_priority_combo_set_value(*bandwidth_combo_, baseline); + gtr_combo_box_set_active_enum(*bandwidth_combo_, baseline); bandwidth_combo_tag_.unblock(); } else @@ -510,7 +510,7 @@ void DetailsDialog::Impl::options_page_init(Glib::RefPtr const& /* gtr_priority_combo_init(*bandwidth_combo_); bandwidth_combo_tag_ = bandwidth_combo_->signal_changed().connect( - [this]() { torrent_set_int(TR_KEY_bandwidthPriority, gtr_priority_combo_get_value(*bandwidth_combo_)); }); + [this]() { torrent_set_int(TR_KEY_bandwidthPriority, gtr_combo_box_get_active_enum(*bandwidth_combo_)); }); gtr_combo_box_set_enum( *ratio_combo_, diff --git a/gtk/FilterBase.h b/gtk/FilterBase.h index 050907d45..7d2a49b6a 100644 --- a/gtk/FilterBase.h +++ b/gtk/FilterBase.h @@ -7,6 +7,8 @@ #include "GtkCompat.h" +#include + #if GTKMM_CHECK_VERSION(4, 0, 0) #include #else @@ -26,8 +28,11 @@ public: #endif public: + FilterBase() = default; ~FilterBase() override = default; + TR_DISABLE_COPY_MOVE(FilterBase) + virtual bool match(T const& item) const = 0; virtual bool matches_all() const; diff --git a/gtk/FilterListModel.hh b/gtk/FilterListModel.hh index 219a5e03b..d47595243 100644 --- a/gtk/FilterListModel.hh +++ b/gtk/FilterListModel.hh @@ -92,5 +92,6 @@ Glib::RefPtr> FilterListModel::create( Glib::RefPtr const& model, Glib::RefPtr const& filter) { + // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) return Glib::make_refptr_for_instance(new FilterListModel(model, filter)); } diff --git a/gtk/Flags.h b/gtk/Flags.h index d423d6aa3..6dbd475ad 100644 --- a/gtk/Flags.h +++ b/gtk/Flags.h @@ -8,12 +8,16 @@ #include #include +// NOLINTBEGIN(bugprone-macro-parentheses, cppcoreguidelines-macro-usage) + #define DEFINE_FLAGS_OPERATORS(FlagType) \ constexpr inline Flags operator|(FlagType lhs, FlagType rhs) noexcept \ { \ return { lhs, rhs }; \ } +// NOLINTEND(bugprone-macro-parentheses, cppcoreguidelines-macro-usage) + template class Flags { @@ -39,22 +43,22 @@ public: } } - constexpr bool none() const noexcept + [[nodiscard]] constexpr bool none() const noexcept { return value_ == 0; } - constexpr bool any() const noexcept + [[nodiscard]] constexpr bool any() const noexcept { return !none(); } - constexpr bool test(FlagType flag) const noexcept + [[nodiscard]] constexpr bool test(FlagType flag) const noexcept { return (value_ & get_mask(flag)) != 0; } - constexpr bool test(Flags rhs) const noexcept + [[nodiscard]] constexpr bool test(Flags rhs) const noexcept { return (value_ & rhs.value_) != 0; } @@ -64,7 +68,7 @@ public: value_ |= get_mask(flag); } - constexpr Flags operator|(Flags rhs) noexcept + [[nodiscard]] constexpr Flags operator|(Flags rhs) noexcept { return Flags(value_ | rhs.value_); } @@ -75,7 +79,7 @@ public: return *this; } - constexpr Flags operator~() const noexcept + [[nodiscard]] constexpr Flags operator~() const noexcept { return Flags(~value_); } @@ -86,7 +90,7 @@ private: { } - static constexpr ValueType get_mask(FlagType flag) noexcept + [[nodiscard]] static constexpr ValueType get_mask(FlagType flag) noexcept { return ValueType{ 1 } << static_cast(flag); } diff --git a/gtk/GtkCompat.h b/gtk/GtkCompat.h index 6f49d7dee..b557f044d 100644 --- a/gtk/GtkCompat.h +++ b/gtk/GtkCompat.h @@ -12,6 +12,8 @@ #include +// NOLINTBEGIN(cppcoreguidelines-macro-usage) + #ifndef GTKMM_CHECK_VERSION #define GTKMM_CHECK_VERSION(major, minor, micro) \ (GTKMM_MAJOR_VERSION > (major) || (GTKMM_MAJOR_VERSION == (major) && GTKMM_MINOR_VERSION > (minor)) || \ @@ -103,6 +105,8 @@ #define TR_PANGO_ELLIPSIZE_MODE(Code) IF_PANGOMM2_48(Pango::EllipsizeMode::Code, Pango::ELLIPSIZE_##Code) #define TR_PANGO_WEIGHT(Code) IF_PANGOMM2_48(Pango::Weight::Code, Pango::WEIGHT_##Code) +// NOLINTEND(cppcoreguidelines-macro-usage) + namespace Glib { diff --git a/gtk/ListModelAdapter.h b/gtk/ListModelAdapter.h index 14b5ce08a..e14a16426 100644 --- a/gtk/ListModelAdapter.h +++ b/gtk/ListModelAdapter.h @@ -44,6 +44,7 @@ public: static Glib::RefPtr create(Glib::RefPtr const& adaptee) { return Glib::make_refptr_for_instance( + // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) new ListModelAdapter(adaptee, T::get_columns(), &T::get_item_id, &T::get_item_value)); } diff --git a/gtk/OptionsDialog.cc b/gtk/OptionsDialog.cc index bf19de1ff..4258b0493 100644 --- a/gtk/OptionsDialog.cc +++ b/gtk/OptionsDialog.cc @@ -12,7 +12,7 @@ #include "Prefs.h" #include "PrefsDialog.h" #include "Session.h" -#include "Utils.h" /* gtr_priority_combo_get_value() */ +#include "Utils.h" #include #include /* tr_sys_path_is_same() */ @@ -118,7 +118,7 @@ void OptionsDialog::Impl::addResponseCB(int response) { if (response == TR_GTK_RESPONSE_TYPE(ACCEPT)) { - tr_torrentSetPriority(tor_, gtr_priority_combo_get_value(*priority_combo_)); + tr_torrentSetPriority(tor_, gtr_combo_box_get_active_enum(*priority_combo_)); if (run_check_->get_active()) { @@ -284,7 +284,7 @@ OptionsDialog::Impl::Impl( dialog.signal_response().connect(sigc::mem_fun(*this, &Impl::addResponseCB)); gtr_priority_combo_init(*priority_combo_); - gtr_priority_combo_set_value(*priority_combo_, TR_PRI_NORMAL); + gtr_combo_box_set_active_enum(*priority_combo_, TR_PRI_NORMAL); auto* source_chooser = gtr_get_widget_derived(builder, "source_button"); addTorrentFilters(source_chooser); diff --git a/gtk/OptionsDialog.h b/gtk/OptionsDialog.h index 84cb6f40b..03312b791 100644 --- a/gtk/OptionsDialog.h +++ b/gtk/OptionsDialog.h @@ -17,7 +17,8 @@ #include class Session; -typedef struct tr_ctor tr_ctor; + +struct tr_ctor; class TorrentUrlChooserDialog : public Gtk::Dialog { @@ -27,6 +28,7 @@ public: Glib::RefPtr const& builder, Gtk::Window& parent, Glib::RefPtr const& core); + ~TorrentUrlChooserDialog() override = default; TR_DISABLE_COPY_MOVE(TorrentUrlChooserDialog) @@ -39,6 +41,8 @@ private: class TorrentFileChooserDialog : public Gtk::FileChooserDialog { public: + ~TorrentFileChooserDialog() override = default; + TR_DISABLE_COPY_MOVE(TorrentFileChooserDialog) static std::unique_ptr create(Gtk::Window& parent, Glib::RefPtr const& core); diff --git a/gtk/Prefs.h b/gtk/Prefs.h index e2d40fa31..b0e860651 100644 --- a/gtk/Prefs.h +++ b/gtk/Prefs.h @@ -14,19 +14,19 @@ void gtr_pref_init(std::string_view config_dir); -int64_t gtr_pref_int_get(tr_quark const key); -void gtr_pref_int_set(tr_quark const key, int64_t value); +int64_t gtr_pref_int_get(tr_quark key); +void gtr_pref_int_set(tr_quark key, int64_t value); -double gtr_pref_double_get(tr_quark const key); -void gtr_pref_double_set(tr_quark const key, double value); +double gtr_pref_double_get(tr_quark key); +void gtr_pref_double_set(tr_quark key, double value); -bool gtr_pref_flag_get(tr_quark const key); -void gtr_pref_flag_set(tr_quark const key, bool value); +bool gtr_pref_flag_get(tr_quark key); +void gtr_pref_flag_set(tr_quark key, bool value); -std::vector gtr_pref_strv_get(tr_quark const key); +std::vector gtr_pref_strv_get(tr_quark key); -std::string gtr_pref_string_get(tr_quark const key); -void gtr_pref_string_set(tr_quark const key, std::string_view value); +std::string gtr_pref_string_get(tr_quark key); +void gtr_pref_string_set(tr_quark key, std::string_view value); -void gtr_pref_save(tr_session*); +void gtr_pref_save(tr_session* /*session*/); tr_variant* gtr_pref_get_all(); diff --git a/gtk/SortListModel.hh b/gtk/SortListModel.hh index bb1cbf579..f0b325ac9 100644 --- a/gtk/SortListModel.hh +++ b/gtk/SortListModel.hh @@ -67,5 +67,6 @@ Glib::RefPtr> SortListModel::create( Glib::RefPtr const& model, Glib::RefPtr const& sorter) { + // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) return Glib::make_refptr_for_instance(new SortListModel(model, sorter)); } diff --git a/gtk/SorterBase.h b/gtk/SorterBase.h index fdc56ae72..bce117f66 100644 --- a/gtk/SorterBase.h +++ b/gtk/SorterBase.h @@ -7,6 +7,8 @@ #include "GtkCompat.h" +#include + #if GTKMM_CHECK_VERSION(4, 0, 0) #include #else @@ -27,8 +29,11 @@ public: #endif public: + SorterBase() = default; ~SorterBase() override = default; + TR_DISABLE_COPY_MOVE(SorterBase) + virtual int compare(T const& lhs, T const& rhs) const = 0; #if !GTKMM_CHECK_VERSION(4, 0, 0) diff --git a/gtk/Utils.cc b/gtk/Utils.cc index 2ffd83166..147f21f0f 100644 --- a/gtk/Utils.cc +++ b/gtk/Utils.cc @@ -563,12 +563,12 @@ EnumComboModelColumns const enum_combo_cols; } // namespace -void gtr_combo_box_set_active_enum(Gtk::ComboBox& combo_box, int value) +void gtr_combo_box_set_active_enum(Gtk::ComboBox& combo, int value) { auto const& column = enum_combo_cols.value; /* do the value and current value match? */ - if (auto const iter = combo_box.get_active(); iter) + if (auto const iter = combo.get_active(); iter) { if (iter->get_value(column) == value) { @@ -577,11 +577,11 @@ void gtr_combo_box_set_active_enum(Gtk::ComboBox& combo_box, int value) } /* find the one to select */ - for (auto const& row : combo_box.get_model()->children()) + for (auto const& row : combo.get_model()->children()) { if (row.get_value(column) == value) { - combo_box.set_active(TR_GTK_TREE_MODEL_CHILD_ITER(row)); + combo.set_active(TR_GTK_TREE_MODEL_CHILD_ITER(row)); return; } } @@ -606,11 +606,11 @@ void gtr_combo_box_set_enum(Gtk::ComboBox& combo, std::vectorproperty_text(), enum_combo_cols.label); } -int gtr_combo_box_get_active_enum(Gtk::ComboBox const& combo_box) +int gtr_combo_box_get_active_enum(Gtk::ComboBox const& combo) { int value = 0; - if (auto const iter = combo_box.get_active(); iter) + if (auto const iter = combo.get_active(); iter) { iter->get_value(0, value); } diff --git a/gtk/Utils.h b/gtk/Utils.h index 46152d5ab..636b0590e 100644 --- a/gtk/Utils.h +++ b/gtk/Utils.h @@ -78,7 +78,7 @@ enum class GtrUnicode Bullet }; -Glib::ustring gtr_get_unicode_string(GtrUnicode); +Glib::ustring gtr_get_unicode_string(GtrUnicode uni); /* return a human-readable string for the size given in bytes. */ Glib::ustring tr_strlsize(guint64 size_in_bytes); @@ -123,12 +123,10 @@ void gtr_window_raise(Gtk::Window& window); ***/ void gtr_priority_combo_init(Gtk::ComboBox& combo); -#define gtr_priority_combo_get_value(w) gtr_combo_box_get_active_enum(w) -#define gtr_priority_combo_set_value(w, val) gtr_combo_box_set_active_enum(w, val) void gtr_combo_box_set_enum(Gtk::ComboBox& combo, std::vector> const& items); -int gtr_combo_box_get_active_enum(Gtk::ComboBox const&); -void gtr_combo_box_set_active_enum(Gtk::ComboBox&, int value); +int gtr_combo_box_get_active_enum(Gtk::ComboBox const& combo); +void gtr_combo_box_set_active_enum(Gtk::ComboBox& combo, int value); /*** ****