From 66b9acfc4dd2e17a4399a16e68b25ff6442a2dcd Mon Sep 17 00:00:00 2001 From: Dominik Charousset Date: Mon, 30 Sep 2024 16:23:49 +0200 Subject: [PATCH] Fix bugprone and modernize clang-tidy findings --- libbroker/broker/detail/memory_backend.cc | 2 +- libbroker/broker/error.cc | 7 ++++--- libbroker/broker/error.hh | 12 ++++++------ libbroker/broker/format/bin.hh | 6 +++--- libbroker/broker/internal/channel.hh | 10 ++++++---- libbroker/broker/internal/flow_scope.hh | 2 +- libbroker/broker/internal/master_actor.cc | 2 +- libbroker/broker/subnet.cc | 4 ++-- 8 files changed, 24 insertions(+), 21 deletions(-) diff --git a/libbroker/broker/detail/memory_backend.cc b/libbroker/broker/detail/memory_backend.cc index 29125feda..99fb77363 100644 --- a/libbroker/broker/detail/memory_backend.cc +++ b/libbroker/broker/detail/memory_backend.cc @@ -109,7 +109,7 @@ expected memory_backend::expiries() const { for (auto& p : store_) { if (p.second.second) - rval.emplace_back(expirable(p.first, *p.second.second)); + rval.emplace_back(p.first, *p.second.second); } return {std::move(rval)}; diff --git a/libbroker/broker/error.cc b/libbroker/broker/error.cc index f9d5a21cb..bcb2691cf 100644 --- a/libbroker/broker/error.cc +++ b/libbroker/broker/error.cc @@ -216,7 +216,8 @@ bool convertible_to_ec(uint8_t src) noexcept { } template -bool convertible_to_error_impl(const List& xs) noexcept { +bool convertible_to_error_impl(const List& xs) noexcept( + std::is_same_v) { if (!contains(xs)) { // There is one special case: default errors with enum value "none" fail to // convert to ec but are still legal. @@ -234,11 +235,11 @@ bool convertible_to_error_impl(const List& xs) noexcept { || contains(args); } -bool convertible_to_error(const vector& xs) noexcept { +bool convertible_to_error(const vector& xs) { return convertible_to_error_impl(xs); } -bool convertible_to_error(const data& src) noexcept { +bool convertible_to_error(const data& src) { return convertible_to_error_impl(src.to_list()); } diff --git a/libbroker/broker/error.hh b/libbroker/broker/error.hh index 1c5cad8c2..970e79616 100644 --- a/libbroker/broker/error.hh +++ b/libbroker/broker/error.hh @@ -276,22 +276,22 @@ struct can_convert_predicate { /// Checks whethter `src` is convertible to a `caf::error` with /// `category() == caf::atom("broker")`. -bool convertible_to_error(const data& src) noexcept; +bool convertible_to_error(const data& src); + +/// @copydoc convertible_to_error +bool convertible_to_error(const vector& xs); /// Checks whethter `src` is convertible to a `caf::error` with /// `category() == caf::atom("broker")`. bool convertible_to_error(const variant& src) noexcept; -/// @copydoc convertible_to_error -bool convertible_to_error(const vector& xs) noexcept; - template <> struct can_convert_predicate { - static bool check(const data& src) noexcept { + static bool check(const data& src) { return convertible_to_error(src); } - static bool check(const vector& src) noexcept { + static bool check(const vector& src) { return convertible_to_error(src); } diff --git a/libbroker/broker/format/bin.hh b/libbroker/broker/format/bin.hh index ec0d4ea03..aea76518c 100644 --- a/libbroker/broker/format/bin.hh +++ b/libbroker/broker/format/bin.hh @@ -203,7 +203,7 @@ std::enable_if_t, OutIter> encode(T value, } else if constexpr (std::is_unsigned_v) { return write_unsigned(value, out); } else { - static_assert(std::is_signed::value); + static_assert(std::is_signed_v); using unsigned_t = std::make_unsigned_t; return write_unsigned(static_cast(value), out); } @@ -435,8 +435,8 @@ public: } template - const T& field(std::string_view, const T& value) { - return value; + decltype(auto) field(std::string_view, T&& value) { + return std::forward(value); } bool fields() { diff --git a/libbroker/broker/internal/channel.hh b/libbroker/broker/internal/channel.hh index d32ec5e21..78af7e15a 100644 --- a/libbroker/broker/internal/channel.hh +++ b/libbroker/broker/internal/channel.hh @@ -198,9 +198,10 @@ public: } void shipped(int64_t num) { + auto dbl_num = static_cast(num); if (unacknowledged) { - unacknowledged->Decrement(num); - processed->Increment(num); + unacknowledged->Decrement(dbl_num); + processed->Increment(dbl_num); } } }; @@ -844,8 +845,9 @@ public: void try_consume_buffer() { auto i = buf_.begin(); for (; i != buf_.end() && i->seq == next_seq_; ++i) { - if (i->content) { - backend_->consume(this, *i->content); + auto& content = i->content; + if (content) { + backend_->consume(this, *content); } else { if (auto err = backend_->consume_nil(this)) { buf_.erase(buf_.begin(), i); diff --git a/libbroker/broker/internal/flow_scope.hh b/libbroker/broker/internal/flow_scope.hh index 44e39d364..abfc7d84d 100644 --- a/libbroker/broker/internal/flow_scope.hh +++ b/libbroker/broker/internal/flow_scope.hh @@ -50,7 +50,7 @@ public: if (deregister_cb_) { try { deregister_cb_(stats_); - } catch (...) { + } catch (...) { // NOLINT // The callbacks may not throw. However, we can't specify them noexcept // because std::function does not support noexcept signatures. Hence, // this catch-all to silence tool warnings. diff --git a/libbroker/broker/internal/master_actor.cc b/libbroker/broker/internal/master_actor.cc index 3f232a857..1533e20fd 100644 --- a/libbroker/broker/internal/master_actor.cc +++ b/libbroker/broker/internal/master_actor.cc @@ -76,7 +76,7 @@ master_state::master_state( detail::die("failed to get master expiries while initializing"); } if (auto entries = backend->size(); entries && *entries > 0) { - metrics.entries->Set(*entries); + metrics.entries->Set(static_cast(*entries)); } BROKER_INFO("attached master" << id << "to" << store_name); } diff --git a/libbroker/broker/subnet.cc b/libbroker/broker/subnet.cc index 6fc161750..9483cd24b 100644 --- a/libbroker/broker/subnet.cc +++ b/libbroker/broker/subnet.cc @@ -78,8 +78,8 @@ bool convert(const std::string& str, subnet& sn) { sn = subnet{addr, static_cast(len)}; return true; } - } catch (std::exception&) { - // nop + } catch (const std::exception&) { + return false; } } return false;