From fbb98ada4ae8b90f9d76a91fbc0de4ff18662669 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Fri, 3 Feb 2023 19:12:48 +0300 Subject: [PATCH] Fix issues reported by `hicpp` clang-tidy checks (GTK client) (#4711) * Fix `hicpp-vararg` clang-tidy issues * Fix `hicpp-explicit-conversions` clang-tidy issues * Fix `hicpp-signed-bitwise` clang-tidy issues * Enable the rest of `hicpp` clang-tidy checks --- gtk/.clang-tidy | 1 + gtk/Flags.h | 3 ++- gtk/FreeSpaceLabel.h | 2 +- gtk/Torrent.cc | 2 +- gtk/Utils.cc | 8 ++++---- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/gtk/.clang-tidy b/gtk/.clang-tidy index 4f8c8a34c..340e9d0ed 100644 --- a/gtk/.clang-tidy +++ b/gtk/.clang-tidy @@ -10,6 +10,7 @@ Checks: > -cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-avoid-non-const-global-variables, -cppcoreguidelines-narrowing-conversions, + hicpp-*, misc-*, modernize-*, -modernize-use-trailing-return-type, diff --git a/gtk/Flags.h b/gtk/Flags.h index aef741340..8af5afe06 100644 --- a/gtk/Flags.h +++ b/gtk/Flags.h @@ -23,13 +23,14 @@ class Flags { public: using FlagType = T; - using ValueType = std::underlying_type_t; + using ValueType = std::make_unsigned_t>; static_assert(std::is_enum_v && !std::is_convertible_v); public: constexpr Flags() noexcept = default; + // NOLINTNEXTLINE(hicpp-explicit-conversions) constexpr Flags(FlagType flag) noexcept { set(flag); diff --git a/gtk/FreeSpaceLabel.h b/gtk/FreeSpaceLabel.h index 4090b7dc8..53adfff3f 100644 --- a/gtk/FreeSpaceLabel.h +++ b/gtk/FreeSpaceLabel.h @@ -17,7 +17,7 @@ class Session; class FreeSpaceLabel : public Gtk::Label { public: - FreeSpaceLabel(Glib::RefPtr const& core, std::string_view dir = {}); + explicit FreeSpaceLabel(Glib::RefPtr const& core, std::string_view dir = {}); FreeSpaceLabel( BaseObjectType* cast_item, Glib::RefPtr const& builder, diff --git a/gtk/Torrent.cc b/gtk/Torrent.cc index 8eb45a907..a4c34cbf0 100644 --- a/gtk/Torrent.cc +++ b/gtk/Torrent.cc @@ -58,7 +58,7 @@ unsigned int build_torrent_trackers_hash(tr_torrent const& torrent) { for (auto const ch : std::string_view{ tr_torrentTracker(&torrent, i).announce }) { - hash = (hash << 4) ^ (hash >> 28) ^ ch; + hash = (hash << 4U) ^ (hash >> 28U) ^ static_cast(ch); } } diff --git a/gtk/Utils.cc b/gtk/Utils.cc index 147f21f0f..c70f58706 100644 --- a/gtk/Utils.cc +++ b/gtk/Utils.cc @@ -86,19 +86,19 @@ char const* const speed_T_str = N_("TB/s"); void gtr_message(std::string const& message) { - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) + // NOLINTNEXTLINE(*-vararg) g_message("%s", message.c_str()); } void gtr_warning(std::string const& message) { - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) + // NOLINTNEXTLINE(*-vararg) g_warning("%s", message.c_str()); } void gtr_error(std::string const& message) { - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) + // NOLINTNEXTLINE(*-vararg) g_error("%s", message.c_str()); } @@ -488,7 +488,7 @@ Glib::SignalProxy gtr_object_signal_notify(Glib::O void gtr_object_notify_emit(Glib::ObjectBase& object) { - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) + // NOLINTNEXTLINE(*-vararg) g_signal_emit_by_name(object.gobj(), "notify", nullptr); }