From d694b81f3b0dbd26ec8333d6181cabd971be03a6 Mon Sep 17 00:00:00 2001 From: Thomas Bleher Date: Tue, 21 Jan 2025 18:13:42 +0100 Subject: [PATCH] Value: init "as" member to avoid -Wmaybe-uninitialized warning GCC (at least version 13.3) warns when moving a freshly constructed value, since the "as" member is not initialized: In constructor 'jsonrpc::Value::Value(jsonrpc::Value&&)', inlined from 'jsonrpc::Response::Response(int32_t, std::string, jsonrpc::Value)' at jsonrpc-lean/response.h:27:13, inlined from 'std::shared_ptr jsonrpc::Server::HandleRequest(const std::string&, const std::string&)' at jsonrpc-lean/server.h:74:17: jsonrpc-lean/value.h:124:63: error: '.jsonrpc::Value::as' may be used uninitialized [-Werror=maybe-uninitialized] 124 | Value(Value&& other) noexcept : myType(other.myType), as(other.as) { | ^~~~~~~~~~~~ jsonrpc-lean/server.h: In member function 'std::shared_ptr jsonrpc::Server::HandleRequest(const std::string&, const std::string&)': jsonrpc-lean/server.h:74:62: note: '' declared here 74 | Response(ex.GetCode(), ex.GetString(), Value()).Write(*writer); | Fix this by initializing the member in the default constructor. --- include/jsonrpc-lean/value.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/jsonrpc-lean/value.h b/include/jsonrpc-lean/value.h index 2cdf1f5..1c24301 100644 --- a/include/jsonrpc-lean/value.h +++ b/include/jsonrpc-lean/value.h @@ -39,7 +39,7 @@ namespace jsonrpc { STRUCT }; - Value() : myType(Type::NIL) {} + Value() : myType(Type::NIL) { as.myArray = nullptr; } Value(Array value) : myType(Type::ARRAY) { as.myArray = new Array(std::move(value));