From 794c72cb44877d6e10d894f2ecb650420b2d9fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korina=20=C5=A0imi=C4=8Devi=C4=87?= Date: Tue, 2 Jan 2024 11:40:53 +0100 Subject: [PATCH] Handle all MSVC warnings Summary: related to T13409 Reviewers: ivica Reviewed By: ivica Subscribers: miljen, iljazovic Differential Revision: https://repo.mireo.local/D27152 --- example/openssl_tls.cpp | 2 +- example/src/run_examples.cpp | 4 ++-- example/tcp.cpp | 4 ++-- example/websocket_tls.cpp | 4 ++-- include/async_mqtt5/detail/control_packet.hpp | 2 +- include/async_mqtt5/impl/async_sender.hpp | 2 +- include/async_mqtt5/impl/client_service.hpp | 2 +- include/async_mqtt5/impl/codecs/message_encoders.hpp | 4 ++-- include/async_mqtt5/impl/connect_op.hpp | 4 ++-- include/async_mqtt5/impl/publish_rec_op.hpp | 2 +- include/async_mqtt5/impl/publish_send_op.hpp | 12 +++++++++--- include/async_mqtt5/impl/read_message_op.hpp | 4 ++-- include/async_mqtt5/impl/subscribe_op.hpp | 4 +++- include/async_mqtt5/impl/unsubscribe_op.hpp | 2 +- test/unit/test/cancellation.cpp | 2 ++ test/unit/test/client_broker.cpp | 2 +- test/unit/test/coroutine.cpp | 4 ++-- test/unit/test/publish_send_op.cpp | 6 +++--- test/unit/test/serialization.cpp | 4 ++-- test/unit/test/session.cpp | 2 +- test/unit/test/subscribe_op.cpp | 4 ++-- 21 files changed, 43 insertions(+), 33 deletions(-) diff --git a/example/openssl_tls.cpp b/example/openssl_tls.cpp index feb6826..883e23d 100644 --- a/example/openssl_tls.cpp +++ b/example/openssl_tls.cpp @@ -21,7 +21,7 @@ struct tls_handshake_type> { template void assign_tls_sni( const authority_path& ap, - asio::ssl::context& ctx, + asio::ssl::context& /* ctx */, asio::ssl::stream& stream ) { SSL_set_tlsext_host_name(stream.native_handle(), ap.host.c_str()); diff --git a/example/src/run_examples.cpp b/example/src/run_examples.cpp index f981058..a12d7fb 100644 --- a/example/src/run_examples.cpp +++ b/example/src/run_examples.cpp @@ -1,10 +1,10 @@ -void run_openssl_tls_examples(); void run_tcp_examples(); +void run_openssl_tls_examples(); void run_websocket_tcp_examples(); void run_websocket_tls_examples(); -int main(int argc, char* argv[]) { +int main() { run_tcp_examples(); run_openssl_tls_examples(); diff --git a/example/tcp.cpp b/example/tcp.cpp index c501323..cae9cdd 100644 --- a/example/tcp.cpp +++ b/example/tcp.cpp @@ -18,11 +18,11 @@ void publish_qos0_tcp() { client_type c(ioc, ""); connect_props props; - props[prop::maximum_packet_size] = 1024; + props[prop::maximum_packet_size] = int16_t(1024); c.credentials("test-qos0-tcp", "", "") .brokers("emqtt.mireo.local", 1883) - .will({ "test/mqtt-test", "Client disconnected!",qos_e::at_least_once }) + .will({ "test/mqtt-test", "Client disconnected!", qos_e::at_least_once }) .connect_properties(std::move(props)) .run(); diff --git a/example/websocket_tls.cpp b/example/websocket_tls.cpp index 335ad84..d510752 100644 --- a/example/websocket_tls.cpp +++ b/example/websocket_tls.cpp @@ -15,7 +15,7 @@ namespace boost::beast::websocket { template void async_teardown( - boost::beast::role_type role, + boost::beast::role_type /* role */, asio::ssl::stream& stream, TeardownHandler&& handler ) { @@ -35,7 +35,7 @@ struct tls_handshake_type> { template void assign_tls_sni( const authority_path& ap, - asio::ssl::context& ctx, + asio::ssl::context& /* ctx */, asio::ssl::stream& stream ) { SSL_set_tlsext_host_name(stream.native_handle(), ap.host.c_str()); diff --git a/include/async_mqtt5/detail/control_packet.hpp b/include/async_mqtt5/detail/control_packet.hpp index 8b5c2e5..9a89579 100644 --- a/include/async_mqtt5/detail/control_packet.hpp +++ b/include/async_mqtt5/detail/control_packet.hpp @@ -125,7 +125,7 @@ class packet_id_allocator { public: packet_id_allocator() { - _free_ids.emplace_back(MAX_PACKET_ID, 0); + _free_ids.emplace_back(MAX_PACKET_ID, uint16_t(0)); } uint16_t allocate() { diff --git a/include/async_mqtt5/impl/async_sender.hpp b/include/async_mqtt5/impl/async_sender.hpp index 8f6cacc..c222e4d 100644 --- a/include/async_mqtt5/impl/async_sender.hpp +++ b/include/async_mqtt5/impl/async_sender.hpp @@ -223,7 +223,7 @@ private: _write_queue.begin(), _write_queue.end(), [](const auto& op) { return !op.throttled(); } ); - uint16_t dist = std::distance(throttled_ptr, _write_queue.end()); + uint16_t dist = static_cast(std::distance(throttled_ptr, _write_queue.end())); uint16_t throttled_num = std::min(dist, _quota); _quota -= throttled_num; throttled_ptr += throttled_num; diff --git a/include/async_mqtt5/impl/client_service.hpp b/include/async_mqtt5/impl/client_service.hpp index 7b7f57d..ed1121e 100644 --- a/include/async_mqtt5/impl/client_service.hpp +++ b/include/async_mqtt5/impl/client_service.hpp @@ -212,7 +212,7 @@ public: client_service( const executor_type& ex, - const std::string& cnf, + const std::string& /* cnf */, tls_context_type tls_context = {} ) : _stream_context(std::move(tls_context)), diff --git a/include/async_mqtt5/impl/codecs/message_encoders.hpp b/include/async_mqtt5/impl/codecs/message_encoders.hpp index df17731..46b7183 100644 --- a/include/async_mqtt5/impl/codecs/message_encoders.hpp +++ b/include/async_mqtt5/impl/codecs/message_encoders.hpp @@ -351,7 +351,7 @@ inline std::string encode_pingreq() { basic::flag<4>(0); auto remaining_len_ = - basic::byte_(0); + basic::byte_(uint8_t(0)); auto ping_req_ = packet_type_ & remaining_len_; @@ -364,7 +364,7 @@ inline std::string encode_pingresp() { basic::flag<4>(0); auto remaining_len_ = - basic::byte_(0); + basic::byte_(uint8_t(0)); auto ping_resp_ = packet_type_ & remaining_len_; diff --git a/include/async_mqtt5/impl/connect_op.hpp b/include/async_mqtt5/impl/connect_op.hpp index a993f34..18cb65f 100644 --- a/include/async_mqtt5/impl/connect_op.hpp +++ b/include/async_mqtt5/impl/connect_op.hpp @@ -279,7 +279,7 @@ public: } void on_connack(byte_citer first, byte_citer last) { - auto packet_length = std::distance(first, last); + auto packet_length = static_cast(std::distance(first, last)); auto rv = decoders::decode_connack(packet_length, first); if (!rv.has_value()) return complete(client::error::malformed_packet); @@ -313,7 +313,7 @@ public: } void on_auth(byte_citer first, byte_citer last) { - auto packet_length = std::distance(first, last); + auto packet_length = static_cast(std::distance(first, last)); auto rv = decoders::decode_auth(packet_length, first); if (!rv.has_value()) return complete(client::error::malformed_packet); diff --git a/include/async_mqtt5/impl/publish_rec_op.hpp b/include/async_mqtt5/impl/publish_rec_op.hpp index 56d349a..a77e60a 100644 --- a/include/async_mqtt5/impl/publish_rec_op.hpp +++ b/include/async_mqtt5/impl/publish_rec_op.hpp @@ -141,7 +141,7 @@ public: if (ec) return; - auto pubrel = decoders::decode_pubrel(std::distance(first, last), first); + auto pubrel = decoders::decode_pubrel(static_cast(std::distance(first, last)), first); if (!pubrel.has_value()) { on_malformed_packet("Malformed PUBREL received: cannot decode"); return wait_pubrel(packet_id); diff --git a/include/async_mqtt5/impl/publish_send_op.hpp b/include/async_mqtt5/impl/publish_send_op.hpp index 557fcef..f736766 100644 --- a/include/async_mqtt5/impl/publish_send_op.hpp +++ b/include/async_mqtt5/impl/publish_send_op.hpp @@ -205,7 +205,9 @@ public: ec, reason_codes::empty, packet_id, puback_props {} ); - auto puback = decoders::decode_puback(std::distance(first, last), first); + auto puback = decoders::decode_puback( + static_cast(std::distance(first, last)), first + ); if (!puback.has_value()) { on_malformed_packet("Malformed PUBACK: cannot decode"); return send_publish(std::move(publish.set_dup())); @@ -239,7 +241,9 @@ public: ec, reason_codes::empty, packet_id, pubcomp_props {} ); - auto pubrec = decoders::decode_pubrec(std::distance(first, last), first); + auto pubrec = decoders::decode_pubrec( + static_cast(std::distance(first, last)), first + ); if (!pubrec.has_value()) { on_malformed_packet("Malformed PUBREC: cannot decode"); return send_publish(std::move(publish.set_dup())); @@ -317,7 +321,9 @@ public: ec, reason_codes::empty, packet_id, pubcomp_props {} ); - auto pubcomp = decoders::decode_pubcomp(std::distance(first, last), first); + auto pubcomp = decoders::decode_pubcomp( + static_cast(std::distance(first, last)), first + ); if (!pubcomp.has_value()) { on_malformed_packet("Malformed PUBCOMP: cannot decode"); return send_pubrel(std::move(pubrel), true); diff --git a/include/async_mqtt5/impl/read_message_op.hpp b/include/async_mqtt5/impl/read_message_op.hpp index 3379bb7..bd8d8d8 100644 --- a/include/async_mqtt5/impl/read_message_op.hpp +++ b/include/async_mqtt5/impl/read_message_op.hpp @@ -88,7 +88,7 @@ private: switch (code) { case control_code_e::publish: { auto msg = decoders::decode_publish( - control_byte, std::distance(first, last), first + control_byte, static_cast(std::distance(first, last)), first ); if (!msg.has_value()) return on_malformed_packet( @@ -105,7 +105,7 @@ private: break; case control_code_e::auth: { auto rv = decoders::decode_auth( - std::distance(first, last), first + static_cast(std::distance(first, last)), first ); if (!rv.has_value()) return on_malformed_packet( diff --git a/include/async_mqtt5/impl/subscribe_op.hpp b/include/async_mqtt5/impl/subscribe_op.hpp index 5ca6cf8..10dcde2 100644 --- a/include/async_mqtt5/impl/subscribe_op.hpp +++ b/include/async_mqtt5/impl/subscribe_op.hpp @@ -134,7 +134,9 @@ public: if (ec) return complete(ec, packet_id, {}, {}); - auto suback = decoders::decode_suback(std::distance(first, last), first); + auto suback = decoders::decode_suback( + static_cast(std::distance(first, last)), first + ); if (!suback.has_value()) { on_malformed_packet("Malformed SUBACK: cannot decode"); return send_subscribe(std::move(packet)); diff --git a/include/async_mqtt5/impl/unsubscribe_op.hpp b/include/async_mqtt5/impl/unsubscribe_op.hpp index ef9fe1d..ec2adf4 100644 --- a/include/async_mqtt5/impl/unsubscribe_op.hpp +++ b/include/async_mqtt5/impl/unsubscribe_op.hpp @@ -131,7 +131,7 @@ public: return complete(ec, packet_id, {}, {}); auto unsuback = decoders::decode_unsuback( - std::distance(first, last), first + static_cast(std::distance(first, last)), first ); if (!unsuback.has_value()) { on_malformed_packet("Malformed UNSUBACK: cannot decode"); diff --git a/test/unit/test/cancellation.cpp b/test/unit/test/cancellation.cpp index a769fd6..0c86e2f 100644 --- a/test/unit/test/cancellation.cpp +++ b/test/unit/test/cancellation.cpp @@ -86,6 +86,7 @@ void cancel_async_publish() { "topic", "payload", retain_e::yes, {}, [&handlers_called](error_code ec, reason_code rc, puback_props) { BOOST_CHECK_EQUAL(ec, asio::error::operation_aborted); + BOOST_CHECK_EQUAL(rc, reason_codes::empty); handlers_called++; } ); @@ -95,6 +96,7 @@ void cancel_async_publish() { "topic", "payload", retain_e::yes, {}, [&handlers_called](error_code ec, reason_code rc, pubcomp_props) { BOOST_CHECK_EQUAL(ec, asio::error::operation_aborted); + BOOST_CHECK_EQUAL(rc, reason_codes::empty); handlers_called++; } ); diff --git a/test/unit/test/client_broker.cpp b/test/unit/test/client_broker.cpp index e9ba930..e1d6cc7 100644 --- a/test/unit/test/client_broker.cpp +++ b/test/unit/test/client_broker.cpp @@ -413,7 +413,7 @@ BOOST_AUTO_TEST_CASE(throttling) { int handlers_called = 0; connack_props props; - props[prop::receive_maximum] = 1; + props[prop::receive_maximum] = int16_t(1); //packets auto connect = encoders::encode_connect( diff --git a/test/unit/test/coroutine.cpp b/test/unit/test/coroutine.cpp index 1d560ef..91e95de 100644 --- a/test/unit/test/coroutine.cpp +++ b/test/unit/test/coroutine.cpp @@ -18,7 +18,7 @@ namespace boost::beast::websocket { template void async_teardown( - boost::beast::role_type role, + boost::beast::role_type /* role */, asio::ssl::stream& stream, TeardownHandler&& handler ) { @@ -62,7 +62,7 @@ struct tls_handshake_type> { template void assign_tls_sni( const authority_path& ap, - asio::ssl::context& ctx, + asio::ssl::context& /* ctx */, asio::ssl::stream& stream ) { SSL_set_tlsext_host_name(stream.native_handle(), ap.host.c_str()); diff --git a/test/unit/test/publish_send_op.cpp b/test/unit/test/publish_send_op.cpp index 0b4a969..8920516 100644 --- a/test/unit/test/publish_send_op.cpp +++ b/test/unit/test/publish_send_op.cpp @@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE(test_invalid_topic_names) { "", "+", "#", "invalid+", "invalid#", "invalid/#", "invalid/+" }; - int expected_handlers_called = invalid_topics.size(); + int expected_handlers_called = static_cast(invalid_topics.size()); int handlers_called = 0; asio::io_context ioc; @@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(test_malformed_packet) { out_of_range_subid_props }; - int expected_handlers_called = testing_props.size(); + int expected_handlers_called = static_cast(testing_props.size()); int handlers_called = 0; asio::io_context ioc; @@ -229,7 +229,7 @@ BOOST_AUTO_TEST_CASE(test_topic_alias_maximum) { ta_allowed_props, connack_props {} /* not allowed */ }; - int expected_handlers_called = test_props.size(); + int expected_handlers_called = static_cast(test_props.size()); int handlers_called = 0; asio::io_context ioc; diff --git a/test/unit/test/serialization.cpp b/test/unit/test/serialization.cpp index 211576f..520f222 100644 --- a/test/unit/test/serialization.cpp +++ b/test/unit/test/serialization.cpp @@ -58,9 +58,9 @@ BOOST_AUTO_TEST_CASE(test_connect) { BOOST_AUTO_TEST_CASE(test_connack) { // testing variables - bool session_present = true; + uint8_t session_present = 1; uint8_t reason_code = 0x89; - bool wildcard_sub = true; + uint8_t wildcard_sub = 1; connack_props cap; cap[prop::wildcard_subscription_available] = wildcard_sub; diff --git a/test/unit/test/session.cpp b/test/unit/test/session.cpp index 461bcbd..afffdb6 100644 --- a/test/unit/test/session.cpp +++ b/test/unit/test/session.cpp @@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE(clear_waiting_on_pubrel) { auto svc_ptr = std::make_shared(ioc.get_executor()); decoders::publish_message pub_msg = std::make_tuple( - "topic", 1, 0b0100, publish_props {}, "payload" + "topic", int16_t(1), uint8_t(0b0100), publish_props {}, "payload" ); detail::publish_rec_op { svc_ptr }.perform(pub_msg); diff --git a/test/unit/test/subscribe_op.cpp b/test/unit/test/subscribe_op.cpp index 7fd02f0..ff777da 100644 --- a/test/unit/test/subscribe_op.cpp +++ b/test/unit/test/subscribe_op.cpp @@ -17,7 +17,7 @@ BOOST_AUTO_TEST_CASE(test_invalid_topic_filters) { "", "+topic", "#topic", "some/#/topic", "topic+", "$share//topic" }; - const int expected_handlers_called = invalid_topics.size(); + const int expected_handlers_called = static_cast(invalid_topics.size()); int handlers_called = 0; asio::io_context ioc; @@ -47,7 +47,7 @@ BOOST_AUTO_TEST_CASE(test_wildcard_subscriptions_not_supported) { connack_props props; props[prop::wildcard_subscription_available] = uint8_t(0); - int expected_handlers_called = wildcard_topics.size(); + int expected_handlers_called = static_cast(wildcard_topics.size()); int handlers_called = 0; asio::io_context ioc;