Skip to content

Commit fdef434

Browse files
committed
Token: use std::unique_ptr for mRef and mRefTemp
1 parent d095f21 commit fdef434

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

lib/token.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,8 +2647,6 @@ Token::Impl::~Impl()
26472647
delete mOriginalName;
26482648
delete mValueType;
26492649
delete mValues;
2650-
delete mRefs;
2651-
delete mRefsTemp;
26522650

26532651
if (mTemplateSimplifierPointers) {
26542652
for (auto *p : *mTemplateSimplifierPointers) {
@@ -2745,11 +2743,11 @@ const SmallVector<ReferenceToken>& Token::refs(bool temporary) const
27452743
{
27462744
if (temporary) {
27472745
if (!mImpl->mRefsTemp)
2748-
mImpl->mRefsTemp = new SmallVector<ReferenceToken>(followAllReferences(this, true));
2746+
mImpl->mRefsTemp.reset(new SmallVector<ReferenceToken>(followAllReferences(this, true)));
27492747
return *mImpl->mRefsTemp;
27502748
}
27512749

27522750
if (!mImpl->mRefs)
2753-
mImpl->mRefs = new SmallVector<ReferenceToken>(followAllReferences(this, false));
2751+
mImpl->mRefs.reset(new SmallVector<ReferenceToken>(followAllReferences(this, false)));
27542752
return *mImpl->mRefs;
27552753
}

lib/token.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class CPPCHECKLIB Token {
120120
// symbol database information
121121
const Scope* mScope{};
122122
union {
123-
const Function *mFunction;
123+
const Function *mFunction{};
124124
const Variable *mVariable;
125125
const ::Type* mType;
126126
const Enumerator *mEnumerator;
@@ -168,14 +168,13 @@ class CPPCHECKLIB Token {
168168

169169
TokenDebug mDebug{};
170170

171-
SmallVector<ReferenceToken>* mRefs{};
172-
SmallVector<ReferenceToken>* mRefsTemp{};
171+
std::unique_ptr<SmallVector<ReferenceToken>> mRefs;
172+
std::unique_ptr<SmallVector<ReferenceToken>> mRefsTemp;
173173

174174
void setCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint value);
175175
bool getCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint &value) const;
176176

177-
Impl() : mFunction(nullptr) {}
178-
177+
Impl() = default;
179178
~Impl();
180179

181180
Impl(const Impl &) = delete;

0 commit comments

Comments
 (0)