From c4358807e2e61c6fbc34f17074b8e52223e156f9 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 5 Feb 2020 16:54:57 +0000 Subject: [PATCH] Fix new gcc 9 'deprecated-copy' warning. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Example warning: cppdap/include/dap/future.h:172:14: error: implicitly-declared ‘dap::ResponseOrError& dap::ResponseOrError::operator=(const dap::ResponseOrError&)’ is deprecated [-Werror=deprecated-copy] Add missing constructors and assignment operators. This probably adds more than is absolutely necessary, but there's no harm in being thorough. --- include/dap/session.h | 46 +++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/include/dap/session.h b/include/dap/session.h index b37d297..da05feb 100644 --- a/include/dap/session.h +++ b/include/dap/session.h @@ -84,8 +84,14 @@ struct ResponseOrError { inline ResponseOrError() = default; inline ResponseOrError(const T& response); + inline ResponseOrError(T&& response); inline ResponseOrError(const Error& error); + inline ResponseOrError(Error&& error); inline ResponseOrError(const ResponseOrError& other); + inline ResponseOrError(ResponseOrError&& other); + + inline ResponseOrError& operator=(const ResponseOrError& other); + inline ResponseOrError& operator=(ResponseOrError&& other); T response; Error error; // empty represents success. @@ -94,10 +100,31 @@ struct ResponseOrError { template ResponseOrError::ResponseOrError(const T& response) : response(response) {} template +ResponseOrError::ResponseOrError(T&& response) + : response(std::move(response)) {} +template ResponseOrError::ResponseOrError(const Error& error) : error(error) {} template +ResponseOrError::ResponseOrError(Error&& error) : error(std::move(error)) {} +template ResponseOrError::ResponseOrError(const ResponseOrError& other) : response(other.response), error(other.error) {} +template +ResponseOrError::ResponseOrError(ResponseOrError&& other) + : response(std::move(other.response)), error(std::move(other.error)) {} +template +ResponseOrError& ResponseOrError::operator=( + const ResponseOrError& other) { + response = other.response; + error = other.error; + return *this; +} +template +ResponseOrError& ResponseOrError::operator=(ResponseOrError&& other) { + response = std::move(other.response); + error = std::move(other.error); + return *this; +} //////////////////////////////////////////////////////////////////////////////// // Session @@ -252,16 +279,15 @@ template future> Session::send(const T& request) { using Response = typename T::Response; promise> promise; - auto sent = send( - TypeOf::type(), TypeOf::type(), &request, - [=](const void* result, const Error* error) { - if (error != nullptr) { - promise.set_value(ResponseOrError(*error)); - } else { - promise.set_value(ResponseOrError( - *reinterpret_cast(result))); - } - }); + auto sent = send(TypeOf::type(), TypeOf::type(), &request, + [=](const void* result, const Error* error) { + if (error != nullptr) { + promise.set_value(ResponseOrError(*error)); + } else { + promise.set_value(ResponseOrError( + *reinterpret_cast(result))); + } + }); if (!sent) { promise.set_value(Error("Failed to send request")); }