From bf81ab5ee73e66bb689a0c38b22f07398d8257bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korina=20=C5=A0imi=C4=8Devi=C4=87?= Date: Tue, 2 Jan 2024 16:01:56 +0100 Subject: [PATCH] Handle all warnings on MSVC Win32 Summary: related to T13409 Reviewers: ivica Reviewed By: ivica Subscribers: miljen, iljazovic Differential Revision: https://repo.mireo.local/D27165 --- example/tcp.cpp | 2 +- include/async_mqtt5/detail/control_packet.hpp | 2 +- include/async_mqtt5/impl/assemble_op.hpp | 8 ++++-- .../async_mqtt5/impl/codecs/base_encoders.hpp | 28 ++++++++++--------- include/async_mqtt5/impl/connect_op.hpp | 4 +-- include/async_mqtt5/impl/disconnect_op.hpp | 7 +++-- include/async_mqtt5/impl/endpoints.hpp | 2 +- include/async_mqtt5/impl/publish_send_op.hpp | 6 ++-- include/async_mqtt5/impl/subscribe_op.hpp | 6 ++-- include/async_mqtt5/impl/unsubscribe_op.hpp | 7 +++-- 10 files changed, 41 insertions(+), 31 deletions(-) diff --git a/example/tcp.cpp b/example/tcp.cpp index cae9cdd..5d0a087 100644 --- a/example/tcp.cpp +++ b/example/tcp.cpp @@ -18,7 +18,7 @@ void publish_qos0_tcp() { client_type c(ioc, ""); connect_props props; - props[prop::maximum_packet_size] = int16_t(1024); + props[prop::maximum_packet_size] = 1024; c.credentials("test-qos0-tcp", "", "") .brokers("emqtt.mireo.local", 1883) diff --git a/include/async_mqtt5/detail/control_packet.hpp b/include/async_mqtt5/detail/control_packet.hpp index 9a89579..ec5139e 100644 --- a/include/async_mqtt5/detail/control_packet.hpp +++ b/include/async_mqtt5/detail/control_packet.hpp @@ -77,7 +77,7 @@ public: EncodeFun&& encode, Args&&... args ) { return control_packet { - alloc, 0, encode(std::forward(args)...) + alloc, uint16_t(0), encode(std::forward(args)...) }; } diff --git a/include/async_mqtt5/impl/assemble_op.hpp b/include/async_mqtt5/impl/assemble_op.hpp index 65640aa..018a7c8 100644 --- a/include/async_mqtt5/impl/assemble_op.hpp +++ b/include/async_mqtt5/impl/assemble_op.hpp @@ -52,7 +52,7 @@ class assemble_op { struct on_read {}; - static constexpr size_t max_recv_size = 65'536; + static constexpr uint32_t max_recv_size = 65'536; client_service& _svc; handler_type _handler; @@ -156,11 +156,13 @@ public: return complete(client::error::malformed_packet, 0, {}, {}); } - auto recv_size = _svc.connect_prop(prop::maximum_packet_size).value_or(max_recv_size); + auto recv_size = static_cast( + _svc.connect_prop(prop::maximum_packet_size).value_or(max_recv_size) + ); if (*varlen > recv_size - std::distance(_data_span.first(), first)) return complete(client::error::malformed_packet, 0, {}, {}); - if (std::distance(first, _data_span.last()) < *varlen) + if (static_cast(std::distance(first, _data_span.last())) < *varlen) return perform(wait_for, asio::transfer_at_least(1)); _data_span.remove_prefix( diff --git a/include/async_mqtt5/impl/codecs/base_encoders.hpp b/include/async_mqtt5/impl/codecs/base_encoders.hpp index 27d167a..6e4a773 100644 --- a/include/async_mqtt5/impl/codecs/base_encoders.hpp +++ b/include/async_mqtt5/impl/codecs/base_encoders.hpp @@ -16,6 +16,8 @@ namespace async_mqtt5::encoders { namespace basic { +using varint_t = int*; + inline void to_variable_bytes(std::string& s, int32_t val) { if (val > 0xfffffff) return; while (val > 127) { @@ -132,7 +134,7 @@ public: private: template static size_t val_length(U&& val) { - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) return variable_length(int32_t(val)); else return sizeof(Repr); @@ -141,7 +143,7 @@ private: template static std::string& encode_val(std::string& s, U&& val) { using namespace boost::endian; - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v) { to_variable_bytes(s, int32_t(val)); return s; } @@ -179,10 +181,10 @@ public: } }; -constexpr auto byte_ = int_def{}; -constexpr auto int16_ = int_def{}; -constexpr auto int32_ = int_def{}; -constexpr auto varlen_ = int_def{}; +constexpr auto byte_ = int_def {}; +constexpr auto int16_ = int_def {}; +constexpr auto int32_ = int_def {}; +constexpr auto varlen_ = int_def {}; template @@ -273,9 +275,9 @@ public: using utf8_def = array_def; -constexpr auto utf8_ = utf8_def{}; -constexpr auto binary_ = array_def{}; // for now -constexpr auto verbatim_ = array_def{}; +constexpr auto utf8_ = utf8_def {}; +constexpr auto binary_ = array_def {}; // for now +constexpr auto verbatim_ = array_def {}; template @@ -368,7 +370,7 @@ using encoder_types = std::tuple< prop_encoder_type, prop_encoder_type, prop_encoder_type, - prop_encoder_type>, // varint + prop_encoder_type>, // varint prop_encoder_type>, prop_encoder_type, prop_encoder_type>, @@ -488,7 +490,7 @@ class props_val : public basic::encoder { static auto to_prop_vals(const pp::properties& props) { return std::make_tuple( to_prop_val( - props[std::integral_constant{}] + props[std::integral_constant {}] )... ); } @@ -554,8 +556,8 @@ public: } }; -constexpr auto props_ = props_def{}; -constexpr auto props_may_omit_ = props_def{}; +constexpr auto props_ = props_def {}; +constexpr auto props_may_omit_ = props_def {}; } // end namespace prop diff --git a/include/async_mqtt5/impl/connect_op.hpp b/include/async_mqtt5/impl/connect_op.hpp index 18cb65f..9d60c2d 100644 --- a/include/async_mqtt5/impl/connect_op.hpp +++ b/include/async_mqtt5/impl/connect_op.hpp @@ -196,7 +196,7 @@ public: encoders::encode_connect, _ctx.creds.client_id, _ctx.creds.username, _ctx.creds.password, - 10u, false, _ctx.co_props, _ctx.will_msg + uint16_t(10), false, _ctx.co_props, _ctx.will_msg ); auto wire_data = packet.wire_data(); @@ -204,7 +204,7 @@ public: detail::async_write( _stream, asio::buffer(wire_data), asio::consign( - asio::prepend(std::move(*this), on_send_connect{}), + asio::prepend(std::move(*this), on_send_connect {}), std::move(packet) ) ); diff --git a/include/async_mqtt5/impl/disconnect_op.hpp b/include/async_mqtt5/impl/disconnect_op.hpp index c90e0c8..794f149 100644 --- a/include/async_mqtt5/impl/disconnect_op.hpp +++ b/include/async_mqtt5/impl/disconnect_op.hpp @@ -71,9 +71,10 @@ public: static_cast(_context.reason_code), _context.props ); - auto max_packet_size = _svc_ptr->connack_prop( - prop::maximum_packet_size - ).value_or(default_max_send_size); + auto max_packet_size = static_cast( + _svc_ptr->connack_prop(prop::maximum_packet_size) + .value_or(default_max_send_size) + ); if (disconnect.size() > max_packet_size) // drop properties return send_disconnect(control_packet::of( diff --git a/include/async_mqtt5/impl/endpoints.hpp b/include/async_mqtt5/impl/endpoints.hpp index 5474c37..eda480d 100644 --- a/include/async_mqtt5/impl/endpoints.hpp +++ b/include/async_mqtt5/impl/endpoints.hpp @@ -60,7 +60,7 @@ public: _owner._current_host++; - if (_owner._current_host + 1 > _owner._servers.size()) { + if (_owner._current_host + 1 > static_cast(_owner._servers.size())) { _owner._current_host = -1; return complete_post(asio::error::try_again, {}, {}); } diff --git a/include/async_mqtt5/impl/publish_send_op.hpp b/include/async_mqtt5/impl/publish_send_op.hpp index f736766..8b19c35 100644 --- a/include/async_mqtt5/impl/publish_send_op.hpp +++ b/include/async_mqtt5/impl/publish_send_op.hpp @@ -120,8 +120,10 @@ public: qos_type, retain, dup_e::no, props ); - auto max_packet_size = _svc_ptr->connack_prop(prop::maximum_packet_size) - .value_or(default_max_send_size); + auto max_packet_size = static_cast( + _svc_ptr->connack_prop(prop::maximum_packet_size) + .value_or(default_max_send_size) + ); if (publish.size() > max_packet_size) return complete_post(client::error::packet_too_large, packet_id); diff --git a/include/async_mqtt5/impl/subscribe_op.hpp b/include/async_mqtt5/impl/subscribe_op.hpp index 10dcde2..80dc884 100644 --- a/include/async_mqtt5/impl/subscribe_op.hpp +++ b/include/async_mqtt5/impl/subscribe_op.hpp @@ -80,8 +80,10 @@ public: topics, props ); - auto max_packet_size = _svc_ptr->connack_prop(prop::maximum_packet_size) - .value_or(default_max_send_size); + auto max_packet_size = static_cast( + _svc_ptr->connack_prop(prop::maximum_packet_size) + .value_or(default_max_send_size) + ); if (subscribe.size() > max_packet_size) return complete_post( client::error::packet_too_large, packet_id, topics.size() diff --git a/include/async_mqtt5/impl/unsubscribe_op.hpp b/include/async_mqtt5/impl/unsubscribe_op.hpp index ec2adf4..8b11f84 100644 --- a/include/async_mqtt5/impl/unsubscribe_op.hpp +++ b/include/async_mqtt5/impl/unsubscribe_op.hpp @@ -75,9 +75,10 @@ public: topics, props ); - auto max_packet_size = _svc_ptr->connack_prop( - prop::maximum_packet_size - ).value_or(default_max_send_size); + auto max_packet_size = static_cast( + _svc_ptr->connack_prop(prop::maximum_packet_size) + .value_or(default_max_send_size) + ); if (unsubscribe.size() > max_packet_size) return complete_post( client::error::packet_too_large, packet_id, topics.size()