From 514b7105b52fb98939f2b982651ec876582250f4 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Mon, 9 Oct 2017 18:50:29 +0000 Subject: [PATCH] Fix some C++ value / reference semantics issues. Some functions were taking Twine's not by const&, these are all fixed to take by const&. We also had a case where some functions were overloaded to accept by const& and &&. Now there is only one version which accepts by value and move's the value. llvm-svn: 315229 --- llvm/tools/llvm-rc/ResourceFileWriter.cpp | 2 +- llvm/tools/llvm-rc/ResourceFileWriter.h | 2 +- llvm/tools/llvm-rc/ResourceScriptParser.cpp | 9 +++------ llvm/tools/llvm-rc/ResourceScriptParser.h | 7 +++---- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/llvm/tools/llvm-rc/ResourceFileWriter.cpp b/llvm/tools/llvm-rc/ResourceFileWriter.cpp index 8b7cd92c0532..3d72e16bf6e2 100644 --- a/llvm/tools/llvm-rc/ResourceFileWriter.cpp +++ b/llvm/tools/llvm-rc/ResourceFileWriter.cpp @@ -380,7 +380,7 @@ void ResourceFileWriter::padStream(uint64_t Length) { writeInt(0); } -Error ResourceFileWriter::handleError(Error &&Err, const RCResource *Res) { +Error ResourceFileWriter::handleError(Error Err, const RCResource *Res) { if (Err) return joinErrors(createError("Error in " + Res->getResourceTypeName() + " statement (ID " + Twine(Res->ResName) + diff --git a/llvm/tools/llvm-rc/ResourceFileWriter.h b/llvm/tools/llvm-rc/ResourceFileWriter.h index b44271607112..8d193d6a9488 100644 --- a/llvm/tools/llvm-rc/ResourceFileWriter.h +++ b/llvm/tools/llvm-rc/ResourceFileWriter.h @@ -88,7 +88,7 @@ public: } StringTableData; private: - Error handleError(Error &&Err, const RCResource *Res); + Error handleError(Error Err, const RCResource *Res); Error writeResource(const RCResource *Res, diff --git a/llvm/tools/llvm-rc/ResourceScriptParser.cpp b/llvm/tools/llvm-rc/ResourceScriptParser.cpp index 47f8745837ed..4acae3135581 100644 --- a/llvm/tools/llvm-rc/ResourceScriptParser.cpp +++ b/llvm/tools/llvm-rc/ResourceScriptParser.cpp @@ -28,7 +28,7 @@ namespace llvm { namespace rc { -RCParser::ParserError::ParserError(const Twine Expected, const LocIter CurLoc, +RCParser::ParserError::ParserError(const Twine &Expected, const LocIter CurLoc, const LocIter End) : ErrorLoc(CurLoc), FileEnd(End) { CurMessage = "Error parsing file: expected " + Expected.str() + ", got " + @@ -37,10 +37,7 @@ RCParser::ParserError::ParserError(const Twine Expected, const LocIter CurLoc, char RCParser::ParserError::ID = 0; -RCParser::RCParser(const std::vector &TokenList) - : Tokens(TokenList), CurLoc(Tokens.begin()), End(Tokens.end()) {} - -RCParser::RCParser(std::vector &&TokenList) +RCParser::RCParser(std::vector TokenList) : Tokens(std::move(TokenList)), CurLoc(Tokens.begin()), End(Tokens.end()) {} bool RCParser::isEof() const { return CurLoc == End; } @@ -706,7 +703,7 @@ RCParser::ParseOptionType RCParser::parseStyleStmt() { return llvm::make_unique(*Arg); } -Error RCParser::getExpectedError(const Twine Message, bool IsAlreadyRead) { +Error RCParser::getExpectedError(const Twine &Message, bool IsAlreadyRead) { return make_error( Message, IsAlreadyRead ? std::prev(CurLoc) : CurLoc, End); } diff --git a/llvm/tools/llvm-rc/ResourceScriptParser.h b/llvm/tools/llvm-rc/ResourceScriptParser.h index f2afe6d7c322..1a124d4ee2e5 100644 --- a/llvm/tools/llvm-rc/ResourceScriptParser.h +++ b/llvm/tools/llvm-rc/ResourceScriptParser.h @@ -36,7 +36,7 @@ public: // Class describing a single failure of parser. class ParserError : public ErrorInfo { public: - ParserError(Twine Expected, const LocIter CurLoc, const LocIter End); + ParserError(const Twine &Expected, const LocIter CurLoc, const LocIter End); void log(raw_ostream &OS) const override { OS << CurMessage; } std::error_code convertToErrorCode() const override { @@ -51,8 +51,7 @@ public: LocIter ErrorLoc, FileEnd; }; - RCParser(const std::vector &TokenList); - RCParser(std::vector &&TokenList); + RCParser(std::vector TokenList); // Reads and returns a single resource definition, or error message if any // occurred. @@ -172,7 +171,7 @@ private: // the token that couldn't be parsed. If the flag is on, this complains about // the correctly read token that makes no sense (that is, the current parser // state is beyond the erroneous token.) - Error getExpectedError(const Twine Message, bool IsAlreadyRead = false); + Error getExpectedError(const Twine &Message, bool IsAlreadyRead = false); std::vector Tokens; LocIter CurLoc; -- 2.34.1