Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clang-tidy findings #435

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
clang-analyzer-*,
modernize-*,
performance-*,
-performance-enum-size,
-bugprone-easily-swappable-parameters,
-bugprone-forward-declaration-namespace,
-clang-analyzer-cplusplus.NewDeleteLeaks,
Expand Down
2 changes: 1 addition & 1 deletion libbroker/broker/configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool openssl_options::authentication_enabled() const noexcept {
namespace {

template <class... Ts>
auto concat(Ts... xs) {
auto concat(const Ts&... xs) {
std::string result;
((result += xs), ...);
return result;
Expand Down
4 changes: 2 additions & 2 deletions libbroker/broker/detail/appliers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct retriever {

template <class T>
result_type operator()(const T& x) const {
return x;
return data{x};
}

static result_type at_index(const vector& v, count index) {
Expand All @@ -149,7 +149,7 @@ struct retriever {
}

result_type operator()(const set& s) const {
return s.count(aspect) == 1;
return data{s.count(aspect) == 1};
}

result_type operator()(const table& t) const {
Expand Down
2 changes: 1 addition & 1 deletion libbroker/broker/detail/die.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void render(T&& x, Ts&&... xs) {
template <class... Ts>
[[noreturn]] void die(Ts&&... xs) {
render(std::forward<Ts>(xs)...);
std::cerr << std::endl;
std::cerr << '\n';
std::abort();
}

Expand Down
8 changes: 4 additions & 4 deletions libbroker/broker/envelope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ std::string to_string(envelope_type x) {
}

bool from_string(std::string_view str, envelope_type& x) {
auto tmp = p2p_message_type{0};
auto tmp = p2p_message_type::data;
if (from_string(str, tmp) && static_cast<uint8_t>(tmp) <= 5) {
x = static_cast<envelope_type>(tmp);
return true;
Expand All @@ -57,7 +57,7 @@ bool from_string(std::string_view str, envelope_type& x) {

bool from_integer(uint8_t val, envelope_type& x) {
if (val <= 0x04) {
auto tmp = p2p_message_type{0};
auto tmp = p2p_message_type::data;
if (from_integer(val, tmp)) {
x = static_cast<envelope_type>(tmp);
return true;
Expand Down Expand Up @@ -134,7 +134,7 @@ expected<envelope_ptr> envelope::deserialize(const std::byte* data,
case envelope_type::data:
if (auto res = data_envelope::deserialize(sender, receiver, ttl,
topic_str, data, size))
return *res;
return envelope_ptr{std::move(*res)};
else
return res.error();
case envelope_type::command:
Expand Down Expand Up @@ -180,7 +180,7 @@ expected<envelope_ptr> envelope::deserialize_json(const char* data,
// Note: must manually "unbox" the expected to convert from
// expected<data_envelope_ptr> to expected<envelope_ptr>.
if (res)
return *res;
return envelope_ptr{std::move(*res)};
else
return res.error();
}
Expand Down
6 changes: 0 additions & 6 deletions libbroker/broker/expected.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ public:

// -- constructors, destructors, and assignment operators --------------------

template <class U>
expected(U x, std::enable_if_t<std::is_convertible_v<U, T>>* = nullptr)
: engaged_(true) {
new (std::addressof(value_)) T(std::move(x));
}

expected(T&& x) noexcept(nothrow_move) : engaged_(true) {
new (std::addressof(value_)) T(std::move(x));
}
Expand Down
2 changes: 1 addition & 1 deletion libbroker/broker/internal/wire_format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ std::string stringify(const var_msg& msg) {

var_msg decode(caf::const_byte_span bytes) {
format::bin::v1::decoder src{bytes.data(), bytes.size()};
auto msg_type = p2p_message_type{0};
auto msg_type = p2p_message_type::data;
if (!src.apply(msg_type)) {
BROKER_ERROR("decode: failed to read the type tag");
return make_var_msg_error(ec::invalid_message, "invalid message type tag"s);
Expand Down
5 changes: 3 additions & 2 deletions libbroker/broker/ping_envelope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ expected<envelope_ptr> ping_envelope::deserialize(
const endpoint_id& sender, const endpoint_id& receiver, uint16_t ttl,
std::string_view topic_str, const std::byte* payload, size_t payload_size) {
using impl_ptr = intrusive_ptr<envelope::deserialized<ping_envelope>>;
return impl_ptr::make(sender, receiver, ttl, topic_str, payload,
payload_size);
auto ptr = impl_ptr::make(sender, receiver, ttl, topic_str, payload,
payload_size);
return envelope_ptr{std::move(ptr)};
}

} // namespace broker
5 changes: 3 additions & 2 deletions libbroker/broker/pong_envelope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ expected<envelope_ptr> pong_envelope::deserialize(
const endpoint_id& sender, const endpoint_id& receiver, uint16_t ttl,
std::string_view topic_str, const std::byte* payload, size_t payload_size) {
using impl_ptr = intrusive_ptr<envelope::deserialized<pong_envelope>>;
return impl_ptr::make(sender, receiver, ttl, topic_str, payload,
payload_size);
auto ptr = impl_ptr::make(sender, receiver, ttl, topic_str, payload,
payload_size);
return envelope_ptr{std::move(ptr)};
}

} // namespace broker
Loading