Skip to content

Commit

Permalink
Refactoring: use init list, redundant init (#5552)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Oct 15, 2023
1 parent 16c5a11 commit f13134a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 23 deletions.
3 changes: 1 addition & 2 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2586,8 +2586,7 @@ void CheckClass::checkConstError(const Token *tok, const std::string &classname,

void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname, bool suggestStatic)
{
std::list<const Token *> toks;
toks.push_back(tok1);
std::list<const Token *> toks{ tok1 };
if (tok2)
toks.push_back(tok2);
if (!suggestStatic)
Expand Down
2 changes: 1 addition & 1 deletion lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2707,7 +2707,7 @@ namespace {
const Token* bodyTok = nullptr;
const Token* loopVar = nullptr;
const Settings* settings = nullptr;
std::set<nonneg int> varsChanged = {};
std::set<nonneg int> varsChanged;

explicit LoopAnalyzer(const Token* tok, const Settings* psettings)
: bodyTok(tok->next()->link()->next()), settings(psettings)
Expand Down
3 changes: 1 addition & 2 deletions lib/checkstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ void CheckString::stringLiteralWrite()

void CheckString::stringLiteralWriteError(const Token *tok, const Token *strValue)
{
std::list<const Token *> callstack;
callstack.push_back(tok);
std::list<const Token*> callstack{ tok };
if (strValue)
callstack.push_back(strValue);

Expand Down
6 changes: 2 additions & 4 deletions lib/infer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ static const ValueFlow::Value* getCompareValue(const std::list<ValueFlow::Value>
}

struct Interval {
std::vector<MathLib::bigint> minvalue = {};
std::vector<MathLib::bigint> maxvalue = {};
std::vector<const ValueFlow::Value*> minRef = {};
std::vector<const ValueFlow::Value*> maxRef = {};
std::vector<MathLib::bigint> minvalue, maxvalue;
std::vector<const ValueFlow::Value*> minRef, maxRef;

std::string str() const
{
Expand Down
11 changes: 6 additions & 5 deletions lib/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,12 @@ bool Platform::loadFromFile(const char exename[], const std::string &filename, b
{
// TODO: only append .xml if missing
// TODO: use native separators
std::vector<std::string> filenames;
filenames.push_back(filename);
filenames.push_back(filename + ".xml");
filenames.push_back("platforms/" + filename);
filenames.push_back("platforms/" + filename + ".xml");
std::vector<std::string> filenames{
filename,
filename + ".xml",
"platforms/" + filename,
"platforms/" + filename + ".xml"
};
if (exename && (std::string::npos != Path::fromNativeSeparators(exename).find('/'))) {
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + filename);
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + filename);
Expand Down
9 changes: 3 additions & 6 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,15 +1131,13 @@ void Tokenizer::simplifyTypedef()

void Tokenizer::simplifyTypedefCpp()
{
std::vector<Space> spaceInfo;
bool isNamespace = false;
std::string className;
std::string fullClassName;
std::string className, fullClassName;
bool hasClass = false;
bool goback = false;

// add global namespace
spaceInfo.emplace_back(/*Space{}*/);
std::vector<Space> spaceInfo(1);

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

std::list<const Token *> classnameTokens;
classnameTokens.push_back(tok->next());
std::list<const Token*> classnameTokens{ tok->next() };
Token* tokStart = tok->tokAt(2);
while (Token::Match(tokStart, ":: %name%") || tokStart->str() == "<") {
if (tokStart->str() == "<") {
Expand Down
6 changes: 3 additions & 3 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ static void valueFlowRightShift(TokenList &tokenList, const Settings* settings)

static std::vector<MathLib::bigint> minUnsignedValue(const Token* tok, int depth = 8)
{
std::vector<MathLib::bigint> result = {};
std::vector<MathLib::bigint> result;
if (!tok)
return result;
if (depth < 0)
Expand Down Expand Up @@ -4942,7 +4942,7 @@ static void valueFlowLifetime(TokenList &tokenlist, ErrorLogger *errorLogger, co
continue;
}

std::vector<const Token*> toks = {};
std::vector<const Token*> toks;
if (tok->isUnaryOp("*") || parent->originalName() == "->") {
for (const ValueFlow::Value& v : tok->values()) {
if (!v.isLocalLifetimeValue())
Expand Down Expand Up @@ -9180,7 +9180,7 @@ struct ValueFlowState {
SymbolDatabase& symboldatabase;
ErrorLogger* errorLogger = nullptr;
const Settings* settings = nullptr;
std::set<const Scope*> skippedFunctions = {};
std::set<const Scope*> skippedFunctions;
};

struct ValueFlowPass {
Expand Down

0 comments on commit f13134a

Please sign in to comment.