Fix new gcc 9 'deprecated-copy' warning.

Example warning:

cppdap/include/dap/future.h:172:14: error: implicitly-declared ‘dap::ResponseOrError<dap::StackTraceResponse>& dap::ResponseOrError<dap::StackTraceResponse>::operator=(const dap::ResponseOrError<dap::StackTraceResponse>&)’ 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.
This commit is contained in:
Ben Clayton 2020-02-05 16:54:57 +00:00
parent de7dffaf66
commit c4358807e2

View File

@ -84,8 +84,14 @@ struct ResponseOrError {
inline ResponseOrError() = default; inline ResponseOrError() = default;
inline ResponseOrError(const T& response); inline ResponseOrError(const T& response);
inline ResponseOrError(T&& response);
inline ResponseOrError(const Error& error); inline ResponseOrError(const Error& error);
inline ResponseOrError(Error&& error);
inline ResponseOrError(const ResponseOrError& other); inline ResponseOrError(const ResponseOrError& other);
inline ResponseOrError(ResponseOrError&& other);
inline ResponseOrError& operator=(const ResponseOrError& other);
inline ResponseOrError& operator=(ResponseOrError&& other);
T response; T response;
Error error; // empty represents success. Error error; // empty represents success.
@ -94,10 +100,31 @@ struct ResponseOrError {
template <typename T> template <typename T>
ResponseOrError<T>::ResponseOrError(const T& response) : response(response) {} ResponseOrError<T>::ResponseOrError(const T& response) : response(response) {}
template <typename T> template <typename T>
ResponseOrError<T>::ResponseOrError(T&& response)
: response(std::move(response)) {}
template <typename T>
ResponseOrError<T>::ResponseOrError(const Error& error) : error(error) {} ResponseOrError<T>::ResponseOrError(const Error& error) : error(error) {}
template <typename T> template <typename T>
ResponseOrError<T>::ResponseOrError(Error&& error) : error(std::move(error)) {}
template <typename T>
ResponseOrError<T>::ResponseOrError(const ResponseOrError& other) ResponseOrError<T>::ResponseOrError(const ResponseOrError& other)
: response(other.response), error(other.error) {} : response(other.response), error(other.error) {}
template <typename T>
ResponseOrError<T>::ResponseOrError(ResponseOrError&& other)
: response(std::move(other.response)), error(std::move(other.error)) {}
template <typename T>
ResponseOrError<T>& ResponseOrError<T>::operator=(
const ResponseOrError& other) {
response = other.response;
error = other.error;
return *this;
}
template <typename T>
ResponseOrError<T>& ResponseOrError<T>::operator=(ResponseOrError&& other) {
response = std::move(other.response);
error = std::move(other.error);
return *this;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Session // Session
@ -252,16 +279,15 @@ template <typename T, typename>
future<ResponseOrError<typename T::Response>> Session::send(const T& request) { future<ResponseOrError<typename T::Response>> Session::send(const T& request) {
using Response = typename T::Response; using Response = typename T::Response;
promise<ResponseOrError<Response>> promise; promise<ResponseOrError<Response>> promise;
auto sent = send( auto sent = send(TypeOf<T>::type(), TypeOf<Response>::type(), &request,
TypeOf<T>::type(), TypeOf<Response>::type(), &request, [=](const void* result, const Error* error) {
[=](const void* result, const Error* error) { if (error != nullptr) {
if (error != nullptr) { promise.set_value(ResponseOrError<Response>(*error));
promise.set_value(ResponseOrError<Response>(*error)); } else {
} else { promise.set_value(ResponseOrError<Response>(
promise.set_value(ResponseOrError<Response>( *reinterpret_cast<const Response*>(result)));
*reinterpret_cast<const Response*>(result))); }
} });
});
if (!sent) { if (!sent) {
promise.set_value(Error("Failed to send request")); promise.set_value(Error("Failed to send request"));
} }