1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-29 13:20:35 +00:00

Fix -Wreturn-local-addr warning

/home/elsid/dev/openmw/apps/opencs/model/world/actoradapter.cpp: In member function ‘const string& CSMWorld::ActorAdapter::ActorData::getPart(ESM::PartReferenceType) const’:
/home/elsid/dev/openmw/apps/opencs/model/world/actoradapter.cpp:142:20: error: returning reference to temporary [-Werror=return-local-addr]
  142 |             return "";
      |                    ^~
This commit is contained in:
elsid 2021-09-04 18:04:43 +02:00
parent 76320aae45
commit a8c16071dc
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40
3 changed files with 9 additions and 4 deletions

View File

@ -9,6 +9,9 @@
#include "data.hpp" #include "data.hpp"
#include <string>
#include <string_view>
namespace CSMWorld namespace CSMWorld
{ {
const std::string& ActorAdapter::RaceData::getId() const const std::string& ActorAdapter::RaceData::getId() const
@ -121,7 +124,7 @@ namespace CSMWorld
return SceneUtil::getActorSkeleton(firstPerson, mFemale, beast, werewolf); return SceneUtil::getActorSkeleton(firstPerson, mFemale, beast, werewolf);
} }
const std::string& ActorAdapter::ActorData::getPart(ESM::PartReferenceType index) const std::string_view ActorAdapter::ActorData::getPart(ESM::PartReferenceType index) const
{ {
auto it = mParts.find(index); auto it = mParts.find(index);
if (it == mParts.end()) if (it == mParts.end())
@ -139,7 +142,7 @@ namespace CSMWorld
return mRaceData->getMalePart(index); return mRaceData->getMalePart(index);
} }
return ""; return {};
} }
const std::string& partName = it->second.first; const std::string& partName = it->second.first;

View File

@ -4,6 +4,8 @@
#include <array> #include <array>
#include <map> #include <map>
#include <unordered_set> #include <unordered_set>
#include <string>
#include <string_view>
#include <QObject> #include <QObject>
#include <QModelIndex> #include <QModelIndex>
@ -93,7 +95,7 @@ namespace CSMWorld
/// Returns the skeleton the actor should use for attaching parts to /// Returns the skeleton the actor should use for attaching parts to
std::string getSkeleton() const; std::string getSkeleton() const;
/// Retrieves the associated actor part /// Retrieves the associated actor part
const std::string& getPart(ESM::PartReferenceType index) const; std::string_view getPart(ESM::PartReferenceType index) const;
/// Checks if the actor has a data dependency /// Checks if the actor has a data dependency
bool hasDependency(const std::string& id) const; bool hasDependency(const std::string& id) const;

View File

@ -96,7 +96,7 @@ namespace CSVRender
for (int i = 0; i < ESM::PRT_Count; ++i) for (int i = 0; i < ESM::PRT_Count; ++i)
{ {
auto type = (ESM::PartReferenceType) i; auto type = (ESM::PartReferenceType) i;
std::string partId = mActorData->getPart(type); const std::string partId(mActorData->getPart(type));
attachBodyPart(type, getBodyPartMesh(partId)); attachBodyPart(type, getBodyPartMesh(partId));
} }
} }