From a50d85ca9de3cc894f978d3ab9b7eaa274ea416f Mon Sep 17 00:00:00 2001 From: str4d Date: Sun, 2 Apr 2017 09:57:03 +1200 Subject: [PATCH] Compile with C++11, migrate auto_ptr to unique_ptr --- Makefile | 2 ++ i2psam.cpp | 22 +++++++++++----------- i2psam.h | 12 ++++++------ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 98c4620..5f8af1b 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +CXXFLAGS=-Werror -std=c++11 + SRCS=i2psam.cpp OBJS=$(SRCS:.cpp=.o) TARGET=libi2psam.a diff --git a/i2psam.cpp b/i2psam.cpp index 39e9d7a..12e6329 100644 --- a/i2psam.cpp +++ b/i2psam.cpp @@ -317,16 +317,16 @@ std::string StreamSession::generateSessionID() return result; } -RequestResult > StreamSession::accept(bool silent) +RequestResult > StreamSession::accept(bool silent) { - typedef RequestResult > ResultType; + typedef RequestResult > ResultType; - std::auto_ptr streamSocket(new I2pSocket(socket_)); + std::unique_ptr streamSocket(new I2pSocket(socket_)); const Message::eStatus status = accept(*streamSocket, sessionID_, silent); switch(status) { case Message::OK: - return RequestResult >(streamSocket); + return ResultType(std::move(streamSocket)); case Message::EMPTY_ANSWER: case Message::CLOSED_SOCKET: case Message::INVALID_ID: @@ -339,16 +339,16 @@ RequestResult > StreamSession::accept(bool silent) return ResultType(); } -RequestResult > StreamSession::connect(const std::string& destination, bool silent) +RequestResult > StreamSession::connect(const std::string& destination, bool silent) { - typedef RequestResult > ResultType; + typedef RequestResult > ResultType; - std::auto_ptr streamSocket(new I2pSocket(socket_)); + std::unique_ptr streamSocket(new I2pSocket(socket_)); const Message::eStatus status = connect(*streamSocket, sessionID_, destination, silent); switch(status) { case Message::OK: - return ResultType(streamSocket); + return ResultType(std::move(streamSocket)); case Message::EMPTY_ANSWER: case Message::CLOSED_SOCKET: case Message::INVALID_ID: @@ -365,7 +365,7 @@ RequestResult StreamSession::forward(const std::string& host, uint16_t por { typedef RequestResult ResultType; - std::auto_ptr newSocket(new I2pSocket(socket_)); + std::unique_ptr newSocket(new I2pSocket(socket_)); const Message::eStatus status = forward(*newSocket, sessionID_, host, port, silent); switch(status) { @@ -390,7 +390,7 @@ RequestResult StreamSession::namingLookup(const std::string& typedef RequestResult ResultType; typedef Message::Answer AnswerType; - std::auto_ptr newSocket(new I2pSocket(socket_)); + std::unique_ptr newSocket(new I2pSocket(socket_)); const AnswerType answer = namingLookup(*newSocket, name); switch(answer.status) { @@ -411,7 +411,7 @@ RequestResult StreamSession::destGenerate() const typedef RequestResult ResultType; typedef Message::Answer AnswerType; - std::auto_ptr newSocket(new I2pSocket(socket_)); + std::unique_ptr newSocket(new I2pSocket(socket_)); const AnswerType answer = destGenerate(*newSocket); switch(answer.status) { diff --git a/i2psam.h b/i2psam.h index 415f894..06f7bad 100644 --- a/i2psam.h +++ b/i2psam.h @@ -270,7 +270,7 @@ struct RequestResult }; template -struct RequestResult > +struct RequestResult > { // a class-helper for resolving a problem with conversion from temporary RequestResult to non-const RequestResult& struct RequestResultRef @@ -283,13 +283,13 @@ struct RequestResult > }; bool isOk; - std::auto_ptr value; + std::unique_ptr value; RequestResult() : isOk(false) {} - explicit RequestResult(std::auto_ptr& value) - : isOk(true), value(value) {} + explicit RequestResult(std::unique_ptr&& value) + : isOk(true), value(std::move(value)) {} // some C++ magic @@ -340,8 +340,8 @@ public: static std::string generateSessionID(); - RequestResult > accept(bool silent); - RequestResult > connect(const std::string& destination, bool silent); + RequestResult > accept(bool silent); + RequestResult > connect(const std::string& destination, bool silent); RequestResult forward(const std::string& host, uint16_t port, bool silent); RequestResult namingLookup(const std::string& name) const; RequestResult destGenerate() const;