From 9ae7b542c63aaedb29cbc0178ed903268150e4a1 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 16 Mar 2024 02:34:46 +0100 Subject: [PATCH] Fix warning: -Wmaybe-uninitialized MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In file included from apps/opencs/model/world/pathgrid.hpp:7, from apps/opencs/model/world/idcollection.hpp:15, from apps/opencs/model/world/idcollection.cpp:1: In constructor ‘constexpr ESM::Pathgrid::Pathgrid(ESM::Pathgrid&&)’, inlined from ‘constexpr CSMWorld::Pathgrid::Pathgrid(CSMWorld::Pathgrid&&)’ at apps/opencs/model/world/pathgrid.hpp:24:12, inlined from ‘constexpr CSMWorld::Record::Record(CSMWorld::Record&&)’ at apps/opencs/model/world/record.hpp:39:12, inlined from ‘std::__detail::__unique_ptr_t<_Tp> std::make_unique(_Args&& ...) [with _Tp = CSMWorld::Record; _Args = {CSMWorld::Record}]’ at /usr/include/c++/13.2.1/bits/unique_ptr.h:1070:30, inlined from ‘std::unique_ptr CSMWorld::Record::modifiedCopy() const [with ESXRecordT = CSMWorld::Pathgrid]’ at apps/opencs/model/world/record.hpp:92:116: components/esm3/loadpgrd.hpp:19:12: warning: ‘.CSMWorld::Record::mBase.CSMWorld::Pathgrid::.ESM::Pathgrid::mData’ may be used uninitialized [-Wmaybe-uninitialized] 19 | struct Pathgrid | ^~~~~~~~ In file included from apps/opencs/model/world/idcollection.hpp:8: apps/opencs/model/world/record.hpp: In member function ‘std::unique_ptr CSMWorld::Record::modifiedCopy() const [with ESXRecordT = CSMWorld::Pathgrid]’: apps/opencs/model/world/record.hpp:92:53: note: ‘’ declared here 92 | return std::make_unique>(Record(State_ModifiedOnly, nullptr, &(this->get()))); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- apps/opencs/model/world/record.hpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/apps/opencs/model/world/record.hpp b/apps/opencs/model/world/record.hpp index d1f64fbfef..35e4c82a35 100644 --- a/apps/opencs/model/world/record.hpp +++ b/apps/opencs/model/world/record.hpp @@ -19,6 +19,11 @@ namespace CSMWorld State mState; + explicit RecordBase(State state) + : mState(state) + { + } + virtual ~RecordBase() = default; virtual std::unique_ptr clone() const = 0; @@ -69,21 +74,18 @@ namespace CSMWorld template Record::Record() - : mBase() + : RecordBase(State_BaseOnly) + , mBase() , mModified() { } template Record::Record(State state, const ESXRecordT* base, const ESXRecordT* modified) + : RecordBase(state) + , mBase(base == nullptr ? ESXRecordT{} : *base) + , mModified(modified == nullptr ? ESXRecordT{} : *modified) { - if (base) - mBase = *base; - - if (modified) - mModified = *modified; - - this->mState = state; } template