Skip to content

Commit f13134a

Browse files
Refactoring: use init list, redundant init (#5552)
1 parent 16c5a11 commit f13134a

7 files changed

Lines changed: 17 additions & 23 deletions

File tree

lib/checkclass.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,8 +2586,7 @@ void CheckClass::checkConstError(const Token *tok, const std::string &classname,
25862586

25872587
void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname, bool suggestStatic)
25882588
{
2589-
std::list<const Token *> toks;
2590-
toks.push_back(tok1);
2589+
std::list<const Token *> toks{ tok1 };
25912590
if (tok2)
25922591
toks.push_back(tok2);
25932592
if (!suggestStatic)

lib/checkstl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2707,7 +2707,7 @@ namespace {
27072707
const Token* bodyTok = nullptr;
27082708
const Token* loopVar = nullptr;
27092709
const Settings* settings = nullptr;
2710-
std::set<nonneg int> varsChanged = {};
2710+
std::set<nonneg int> varsChanged;
27112711

27122712
explicit LoopAnalyzer(const Token* tok, const Settings* psettings)
27132713
: bodyTok(tok->next()->link()->next()), settings(psettings)

lib/checkstring.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ void CheckString::stringLiteralWrite()
7373

7474
void CheckString::stringLiteralWriteError(const Token *tok, const Token *strValue)
7575
{
76-
std::list<const Token *> callstack;
77-
callstack.push_back(tok);
76+
std::list<const Token*> callstack{ tok };
7877
if (strValue)
7978
callstack.push_back(strValue);
8079

lib/infer.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ static const ValueFlow::Value* getCompareValue(const std::list<ValueFlow::Value>
4949
}
5050

5151
struct Interval {
52-
std::vector<MathLib::bigint> minvalue = {};
53-
std::vector<MathLib::bigint> maxvalue = {};
54-
std::vector<const ValueFlow::Value*> minRef = {};
55-
std::vector<const ValueFlow::Value*> maxRef = {};
52+
std::vector<MathLib::bigint> minvalue, maxvalue;
53+
std::vector<const ValueFlow::Value*> minRef, maxRef;
5654

5755
std::string str() const
5856
{

lib/platform.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,12 @@ bool Platform::loadFromFile(const char exename[], const std::string &filename, b
193193
{
194194
// TODO: only append .xml if missing
195195
// TODO: use native separators
196-
std::vector<std::string> filenames;
197-
filenames.push_back(filename);
198-
filenames.push_back(filename + ".xml");
199-
filenames.push_back("platforms/" + filename);
200-
filenames.push_back("platforms/" + filename + ".xml");
196+
std::vector<std::string> filenames{
197+
filename,
198+
filename + ".xml",
199+
"platforms/" + filename,
200+
"platforms/" + filename + ".xml"
201+
};
201202
if (exename && (std::string::npos != Path::fromNativeSeparators(exename).find('/'))) {
202203
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + filename);
203204
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + filename);

lib/tokenize.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,15 +1131,13 @@ void Tokenizer::simplifyTypedef()
11311131

11321132
void Tokenizer::simplifyTypedefCpp()
11331133
{
1134-
std::vector<Space> spaceInfo;
11351134
bool isNamespace = false;
1136-
std::string className;
1137-
std::string fullClassName;
1135+
std::string className, fullClassName;
11381136
bool hasClass = false;
11391137
bool goback = false;
11401138

11411139
// add global namespace
1142-
spaceInfo.emplace_back(/*Space{}*/);
1140+
std::vector<Space> spaceInfo(1);
11431141

11441142
// Convert "using a::b;" to corresponding typedef statements
11451143
simplifyUsingToTypedef();
@@ -5013,8 +5011,7 @@ void Tokenizer::setVarIdPass2()
50135011
const std::string &scopeName(getScopeName(scopeInfo));
50145012
const std::string scopeName2(scopeName.empty() ? std::string() : (scopeName + " :: "));
50155013

5016-
std::list<const Token *> classnameTokens;
5017-
classnameTokens.push_back(tok->next());
5014+
std::list<const Token*> classnameTokens{ tok->next() };
50185015
Token* tokStart = tok->tokAt(2);
50195016
while (Token::Match(tokStart, ":: %name%") || tokStart->str() == "<") {
50205017
if (tokStart->str() == "<") {

lib/valueflow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,7 @@ static void valueFlowRightShift(TokenList &tokenList, const Settings* settings)
17751775

17761776
static std::vector<MathLib::bigint> minUnsignedValue(const Token* tok, int depth = 8)
17771777
{
1778-
std::vector<MathLib::bigint> result = {};
1778+
std::vector<MathLib::bigint> result;
17791779
if (!tok)
17801780
return result;
17811781
if (depth < 0)
@@ -4942,7 +4942,7 @@ static void valueFlowLifetime(TokenList &tokenlist, ErrorLogger *errorLogger, co
49424942
continue;
49434943
}
49444944

4945-
std::vector<const Token*> toks = {};
4945+
std::vector<const Token*> toks;
49464946
if (tok->isUnaryOp("*") || parent->originalName() == "->") {
49474947
for (const ValueFlow::Value& v : tok->values()) {
49484948
if (!v.isLocalLifetimeValue())
@@ -9180,7 +9180,7 @@ struct ValueFlowState {
91809180
SymbolDatabase& symboldatabase;
91819181
ErrorLogger* errorLogger = nullptr;
91829182
const Settings* settings = nullptr;
9183-
std::set<const Scope*> skippedFunctions = {};
9183+
std::set<const Scope*> skippedFunctions;
91849184
};
91859185

91869186
struct ValueFlowPass {

0 commit comments

Comments
 (0)