Skip to content

Conversation

@tbleher
Copy link

@tbleher tbleher commented Jan 21, 2025

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::FormattedData> jsonrpc::Server::HandleRequest(const std::string&, const std::string&)' at jsonrpc-lean/server.h:74:17:
  jsonrpc-lean/value.h:124:63: error: '<unnamed>.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::FormattedData> jsonrpc::Server::HandleRequest(const std::string&, const std::string&)':
  jsonrpc-lean/server.h:74:62: note: '<anonymous>' declared here
     74 |                 Response(ex.GetCode(), ex.GetString(), Value()).Write(*writer);
        |

Fix this by initializing the member in the default constructor.

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::FormattedData> jsonrpc::Server::HandleRequest(const std::string&, const std::string&)' at jsonrpc-lean/server.h:74:17:
  jsonrpc-lean/value.h:124:63: error: '<unnamed>.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::FormattedData> jsonrpc::Server::HandleRequest(const std::string&, const std::string&)':
  jsonrpc-lean/server.h:74:62: note: '<anonymous>' declared here
     74 |                 Response(ex.GetCode(), ex.GetString(), Value()).Write(*writer);
        |

Fix this by initializing the member in the default constructor.
@tbleher
Copy link
Author

tbleher commented Jan 23, 2025

@uskr I would appreciate if you could have a look at this patch :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant