diff --git a/examples/metadata.cpp b/examples/metadata.cpp index b7f285b4..81dc1f5f 100644 --- a/examples/metadata.cpp +++ b/examples/metadata.cpp @@ -53,7 +53,7 @@ void main_impl(int argc, char** argv) */ assert(result.fields().size() == 2); - const mysql::field_metadata& company_name = result.fields()[0]; + [[maybe_unused]] const mysql::field_metadata& company_name = result.fields()[0]; assert(company_name.database() == "mysql_asio_examples"); // database name assert(company_name.table() == "comp"); // the alias we assigned to the table in the query assert(company_name.original_table() == "company"); // the original table name @@ -64,7 +64,7 @@ void main_impl(int argc, char** argv) assert(!company_name.is_auto_increment()); // field is not AUTO_INCREMENT assert(company_name.is_not_null()); // field may not be NULL - const mysql::field_metadata& employee_id = result.fields()[1]; + [[maybe_unused]] const mysql::field_metadata& employee_id = result.fields()[1]; assert(employee_id.database() == "mysql_asio_examples");// database name assert(employee_id.table() == "emp"); // the alias we assigned to the table in the query assert(employee_id.original_table() == "employee"); // the original table name diff --git a/examples/query_async.cpp b/examples/query_async.cpp index 11e872fe..9e3e4136 100644 --- a/examples/query_async.cpp +++ b/examples/query_async.cpp @@ -84,7 +84,7 @@ public: void update_slacker() { const char* sql = "UPDATE employee SET salary = 15000 WHERE last_name = 'Slacker'"; - connection.async_query(sql, [this](const mysql::error_code& err, mysql::tcp_resultset&& result) { + connection.async_query(sql, [this](const mysql::error_code& err, [[maybe_unused]] mysql::tcp_resultset&& result) { die_on_error(err); assert(result.fields().size() == 0); query_intern(); @@ -100,7 +100,7 @@ public: resultset.async_fetch_all([](const mysql::error_code& err, const auto& rows) { die_on_error(err); assert(rows.size() == 1); - auto salary = std::get(rows[0].values()[0]); + [[maybe_unused]] auto salary = std::get(rows[0].values()[0]); assert(salary == 15000); }); }); diff --git a/examples/query_sync.cpp b/examples/query_sync.cpp index ffab2398..fbdc27a9 100644 --- a/examples/query_sync.cpp +++ b/examples/query_sync.cpp @@ -99,7 +99,7 @@ void main_impl(int argc, char** argv) result = conn.query("SELECT salary FROM employee WHERE first_name = 'Underpaid'"); auto rows = result.fetch_all(); assert(rows.size() == 1); - auto salary = std::get(rows[0].values()[0]); + [[maybe_unused]] auto salary = std::get(rows[0].values()[0]); assert(salary == 10000); } diff --git a/include/mysql/impl/handshake.ipp b/include/mysql/impl/handshake.ipp index 5deab08f..317fc2c0 100644 --- a/include/mysql/impl/handshake.ipp +++ b/include/mysql/impl/handshake.ipp @@ -24,9 +24,8 @@ inline error_code deserialize_handshake( handshake_packet& output ) { - std::uint8_t msg_type; DeserializationContext ctx (boost::asio::buffer(buffer), capabilities()); - auto err = deserialize_message_type(msg_type, ctx); + auto [err, msg_type] = deserialize_message_type(ctx); if (err) return err; if (msg_type == handshake_protocol_version_9) { @@ -163,9 +162,8 @@ public: bool& auth_complete ) { - std::uint8_t msg_type; DeserializationContext ctx (boost::asio::buffer(buffer), negotiated_caps_); - auto err = deserialize_message_type(msg_type, ctx); + auto [err, msg_type] = deserialize_message_type(ctx); if (err) return err; if (msg_type == ok_packet_header) { @@ -206,8 +204,7 @@ public: ) { DeserializationContext ctx (boost::asio::buffer(buffer), negotiated_caps_); - std::uint8_t msg_type; - auto err = deserialize_message_type(msg_type, ctx); + auto [err, msg_type] = deserialize_message_type(ctx); if (err) return err; if (msg_type == error_packet_header) { diff --git a/include/mysql/impl/messages.hpp b/include/mysql/impl/messages.hpp index 5884d8ce..72d7de1e 100644 --- a/include/mysql/impl/messages.hpp +++ b/include/mysql/impl/messages.hpp @@ -228,8 +228,7 @@ error_code deserialize_message( DeserializationContext& ctx ); -inline error_code deserialize_message_type( - std::uint8_t& output, +inline std::pair deserialize_message_type( DeserializationContext& ctx ); diff --git a/include/mysql/impl/messages.ipp b/include/mysql/impl/messages.ipp index d43ed7d8..2eb105b8 100644 --- a/include/mysql/impl/messages.ipp +++ b/include/mysql/impl/messages.ipp @@ -194,16 +194,22 @@ mysql::error_code mysql::detail::deserialize_message( } -inline mysql::error_code mysql::detail::deserialize_message_type( - std::uint8_t& output, +inline std::pair mysql::detail::deserialize_message_type( DeserializationContext& ctx ) { int1 msg_type; + std::pair res {}; auto err = deserialize(msg_type, ctx); - if (err != Error::ok) return make_error_code(err); - output = msg_type.value; - return error_code(); + if (err == Error::ok) + { + res.second = msg_type.value; + } + else + { + res.first = make_error_code(err); + } + return res; } inline mysql::error_code mysql::detail::process_error_packet( diff --git a/include/mysql/impl/query.ipp b/include/mysql/impl/query.ipp index c0866a28..816135d7 100644 --- a/include/mysql/impl/query.ipp +++ b/include/mysql/impl/query.ipp @@ -48,7 +48,7 @@ public: // a length-encoded int containing the field count DeserializationContext ctx (boost::asio::buffer(buffer_), channel_.current_capabilities()); std::uint8_t msg_type; - err = deserialize_message_type(msg_type, ctx); + std::tie(err, msg_type) = deserialize_message_type(ctx); if (err) return {}; if (msg_type == ok_packet_header) { @@ -122,7 +122,7 @@ inline fetch_result process_fetch_message( // Message type: row, error or eof? std::uint8_t msg_type; DeserializationContext ctx (boost::asio::buffer(buffer), current_capabilities); - err = deserialize_message_type(msg_type, ctx); + std::tie(err, msg_type) = deserialize_message_type(ctx); if (err) return fetch_result::error; if (msg_type == eof_packet_header) { diff --git a/test/serialization_test_common.hpp b/test/serialization_test_common.hpp index d216bd43..f0d67a84 100644 --- a/test/serialization_test_common.hpp +++ b/test/serialization_test_common.hpp @@ -124,8 +124,7 @@ public: } std::shared_ptr default_construct() const override { - T res; // intentionally not value-initializing it - return std::make_shared>(res); + return std::make_shared>(T{}); } bool equals(const TypeErasedValue& rhs) const override {