diff --git a/.clang-tidy b/.clang-tidy index aa78ee99..67064ff4 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -4,6 +4,7 @@ clang-analyzer-*, modernize-*, performance-*, + -performance-enum-size, -bugprone-easily-swappable-parameters, -bugprone-forward-declaration-namespace, -clang-analyzer-cplusplus.NewDeleteLeaks, diff --git a/libbroker/broker/configuration.cc b/libbroker/broker/configuration.cc index f9fa8af7..9c0410b5 100644 --- a/libbroker/broker/configuration.cc +++ b/libbroker/broker/configuration.cc @@ -57,7 +57,7 @@ bool openssl_options::authentication_enabled() const noexcept { namespace { template -auto concat(Ts... xs) { +auto concat(const Ts&... xs) { std::string result; ((result += xs), ...); return result; diff --git a/libbroker/broker/detail/appliers.hh b/libbroker/broker/detail/appliers.hh index 8b3eb2f2..e302f09b 100644 --- a/libbroker/broker/detail/appliers.hh +++ b/libbroker/broker/detail/appliers.hh @@ -125,7 +125,7 @@ struct retriever { template result_type operator()(const T& x) const { - return x; + return data{x}; } static result_type at_index(const vector& v, count index) { @@ -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 { diff --git a/libbroker/broker/detail/die.hh b/libbroker/broker/detail/die.hh index 53eed51f..a554d596 100644 --- a/libbroker/broker/detail/die.hh +++ b/libbroker/broker/detail/die.hh @@ -21,7 +21,7 @@ void render(T&& x, Ts&&... xs) { template [[noreturn]] void die(Ts&&... xs) { render(std::forward(xs)...); - std::cerr << std::endl; + std::cerr << '\n'; std::abort(); } diff --git a/libbroker/broker/envelope.cc b/libbroker/broker/envelope.cc index bcb9f35b..dc9f37fd 100644 --- a/libbroker/broker/envelope.cc +++ b/libbroker/broker/envelope.cc @@ -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(tmp) <= 5) { x = static_cast(tmp); return true; @@ -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(tmp); return true; @@ -134,7 +134,7 @@ expected 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: @@ -180,7 +180,7 @@ expected envelope::deserialize_json(const char* data, // Note: must manually "unbox" the expected to convert from // expected to expected. if (res) - return *res; + return envelope_ptr{std::move(*res)}; else return res.error(); } diff --git a/libbroker/broker/expected.hh b/libbroker/broker/expected.hh index b8295147..d507d22b 100644 --- a/libbroker/broker/expected.hh +++ b/libbroker/broker/expected.hh @@ -40,12 +40,6 @@ public: // -- constructors, destructors, and assignment operators -------------------- - template - expected(U x, std::enable_if_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)); } diff --git a/libbroker/broker/internal/wire_format.cc b/libbroker/broker/internal/wire_format.cc index c674bcf5..808b2a61 100644 --- a/libbroker/broker/internal/wire_format.cc +++ b/libbroker/broker/internal/wire_format.cc @@ -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); diff --git a/libbroker/broker/ping_envelope.cc b/libbroker/broker/ping_envelope.cc index 17e5148a..87122501 100644 --- a/libbroker/broker/ping_envelope.cc +++ b/libbroker/broker/ping_envelope.cc @@ -80,8 +80,9 @@ expected 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>; - 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 diff --git a/libbroker/broker/pong_envelope.cc b/libbroker/broker/pong_envelope.cc index c0217baf..90e6b72f 100644 --- a/libbroker/broker/pong_envelope.cc +++ b/libbroker/broker/pong_envelope.cc @@ -85,8 +85,9 @@ expected 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>; - 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