From 78f5d58dc64712be97cf50b9b94e7893b5599d34 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Mon, 3 Jul 2023 16:22:15 +0200 Subject: [PATCH] Codechange: use std::string without const as return Otherwise some compilers, e.g. MSVC, do not pick up that these are temporaries and as such it will pass the temporaries to `const std::string &` instead of the wanted `std::string &&` --- src/script/api/script_goal.cpp | 6 +++--- src/script/api/script_league.cpp | 14 +++++++------- src/script/api/script_news.cpp | 2 +- src/script/api/script_text.cpp | 2 +- src/script/api/script_text.hpp | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/script/api/script_goal.cpp b/src/script/api/script_goal.cpp index 4430326101..da19ba464c 100644 --- a/src/script/api/script_goal.cpp +++ b/src/script/api/script_goal.cpp @@ -48,7 +48,7 @@ EnforceDeityMode(GOAL_INVALID); EnforcePrecondition(GOAL_INVALID, goal != nullptr); - const std::string &text = goal->GetEncodedText(); + std::string text = goal->GetEncodedText(); EnforcePreconditionEncodedText(GOAL_INVALID, text); EnforcePrecondition(GOAL_INVALID, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID); EnforcePrecondition(GOAL_INVALID, IsValidGoalDestination(company, type, destination)); @@ -84,7 +84,7 @@ EnforcePrecondition(false, IsValidGoal(goal_id)); EnforceDeityMode(false); EnforcePrecondition(false, goal != nullptr); - const std::string &text = goal->GetEncodedText(); + std::string text = goal->GetEncodedText(); EnforcePreconditionEncodedText(false, text); return ScriptObject::Command::Do(goal_id, text); @@ -123,7 +123,7 @@ EnforceDeityMode(false); EnforcePrecondition(false, question != nullptr); - const std::string &text = question->GetEncodedText(); + std::string text = question->GetEncodedText(); EnforcePreconditionEncodedText(false, text); uint min_buttons = (type == QT_QUESTION ? 1 : 0); EnforcePrecondition(false, CountBits(buttons) >= min_buttons && CountBits(buttons) <= 3); diff --git a/src/script/api/script_league.cpp b/src/script/api/script_league.cpp index 905f8b40ea..28a4e8e674 100644 --- a/src/script/api/script_league.cpp +++ b/src/script/api/script_league.cpp @@ -32,11 +32,11 @@ EnforceDeityMode(LEAGUE_TABLE_INVALID); EnforcePrecondition(LEAGUE_TABLE_INVALID, title != nullptr); - const std::string &encoded_title = title->GetEncodedText(); + std::string encoded_title = title->GetEncodedText(); EnforcePreconditionEncodedText(LEAGUE_TABLE_INVALID, encoded_title); - const std::string &encoded_header = (header != nullptr ? header->GetEncodedText() : std::string{}); - const std::string &encoded_footer = (footer != nullptr ? footer->GetEncodedText() : std::string{}); + std::string encoded_header = (header != nullptr ? header->GetEncodedText() : std::string{}); + std::string encoded_footer = (footer != nullptr ? footer->GetEncodedText() : std::string{}); if (!ScriptObject::Command::Do(&ScriptInstance::DoCommandReturnLeagueTableID, encoded_title, encoded_header, encoded_footer)) return LEAGUE_TABLE_INVALID; @@ -63,11 +63,11 @@ if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY; EnforcePrecondition(LEAGUE_TABLE_ELEMENT_INVALID, text != nullptr); - const std::string &encoded_text = text->GetEncodedText(); + std::string encoded_text = text->GetEncodedText(); EnforcePreconditionEncodedText(LEAGUE_TABLE_ELEMENT_INVALID, encoded_text); EnforcePrecondition(LEAGUE_TABLE_ELEMENT_INVALID, score != nullptr); - const std::string &encoded_score = score->GetEncodedText(); + std::string encoded_score = score->GetEncodedText(); EnforcePreconditionEncodedText(LEAGUE_TABLE_ELEMENT_INVALID, encoded_score); EnforcePrecondition(LEAGUE_TABLE_ELEMENT_INVALID, IsValidLink(Link((::LinkType)link_type, link_target))); @@ -90,7 +90,7 @@ if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY; EnforcePrecondition(false, text != nullptr); - const std::string &encoded_text = text->GetEncodedText(); + std::string encoded_text = text->GetEncodedText(); EnforcePreconditionEncodedText(false, encoded_text); EnforcePrecondition(false, IsValidLink(Link((::LinkType)link_type, link_target))); @@ -106,7 +106,7 @@ EnforcePrecondition(false, IsValidLeagueTableElement(element)); EnforcePrecondition(false, score != nullptr); - const std::string &encoded_score = score->GetEncodedText(); + std::string encoded_score = score->GetEncodedText(); EnforcePreconditionEncodedText(false, encoded_score); return ScriptObject::Command::Do(element, rating, encoded_score); diff --git a/src/script/api/script_news.cpp b/src/script/api/script_news.cpp index 6d668fea05..7f0968db90 100644 --- a/src/script/api/script_news.cpp +++ b/src/script/api/script_news.cpp @@ -26,7 +26,7 @@ EnforceDeityMode(false); EnforcePrecondition(false, text != nullptr); - const std::string &encoded = text->GetEncodedText(); + std::string encoded = text->GetEncodedText(); EnforcePreconditionEncodedText(false, encoded); EnforcePrecondition(false, type == NT_ECONOMY || type == NT_SUBSIDIES || type == NT_GENERAL); EnforcePrecondition(false, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID); diff --git a/src/script/api/script_text.cpp b/src/script/api/script_text.cpp index a4e8dd7196..753050ea8e 100644 --- a/src/script/api/script_text.cpp +++ b/src/script/api/script_text.cpp @@ -158,7 +158,7 @@ SQInteger ScriptText::_set(HSQUIRRELVM vm) return this->_SetParam(k, vm); } -const std::string ScriptText::GetEncodedText() +std::string ScriptText::GetEncodedText() { static StringIDList seen_ids; int param_count = 0; diff --git a/src/script/api/script_text.hpp b/src/script/api/script_text.hpp index 92928b8b8f..7509065fde 100644 --- a/src/script/api/script_text.hpp +++ b/src/script/api/script_text.hpp @@ -26,7 +26,7 @@ public: * @return A string. * @api -all */ - virtual const std::string GetEncodedText() = 0; + virtual std::string GetEncodedText() = 0; /** * Convert a #ScriptText into a decoded normal string. @@ -44,7 +44,7 @@ class RawText : public Text { public: RawText(const std::string &text); - const std::string GetEncodedText() override { return this->text; } + std::string GetEncodedText() override { return this->text; } private: const std::string text; }; @@ -125,7 +125,7 @@ public: /** * @api -all */ - virtual const std::string GetEncodedText(); + virtual std::string GetEncodedText(); private: using ScriptTextRef = ScriptObjectRef;