Refactoring: use init list, redundant init (#5552)

This commit is contained in:
chrchr-github 2023-10-15 14:51:12 +02:00 committed by GitHub
parent 16c5a11786
commit f13134a6a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 23 deletions

View File

@ -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) void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname, bool suggestStatic)
{ {
std::list<const Token *> toks; std::list<const Token *> toks{ tok1 };
toks.push_back(tok1);
if (tok2) if (tok2)
toks.push_back(tok2); toks.push_back(tok2);
if (!suggestStatic) if (!suggestStatic)

View File

@ -2707,7 +2707,7 @@ namespace {
const Token* bodyTok = nullptr; const Token* bodyTok = nullptr;
const Token* loopVar = nullptr; const Token* loopVar = nullptr;
const Settings* settings = nullptr; const Settings* settings = nullptr;
std::set<nonneg int> varsChanged = {}; std::set<nonneg int> varsChanged;
explicit LoopAnalyzer(const Token* tok, const Settings* psettings) explicit LoopAnalyzer(const Token* tok, const Settings* psettings)
: bodyTok(tok->next()->link()->next()), settings(psettings) : bodyTok(tok->next()->link()->next()), settings(psettings)

View File

@ -73,8 +73,7 @@ void CheckString::stringLiteralWrite()
void CheckString::stringLiteralWriteError(const Token *tok, const Token *strValue) void CheckString::stringLiteralWriteError(const Token *tok, const Token *strValue)
{ {
std::list<const Token *> callstack; std::list<const Token*> callstack{ tok };
callstack.push_back(tok);
if (strValue) if (strValue)
callstack.push_back(strValue); callstack.push_back(strValue);

View File

@ -49,10 +49,8 @@ static const ValueFlow::Value* getCompareValue(const std::list<ValueFlow::Value>
} }
struct Interval { struct Interval {
std::vector<MathLib::bigint> minvalue = {}; std::vector<MathLib::bigint> minvalue, maxvalue;
std::vector<MathLib::bigint> maxvalue = {}; std::vector<const ValueFlow::Value*> minRef, maxRef;
std::vector<const ValueFlow::Value*> minRef = {};
std::vector<const ValueFlow::Value*> maxRef = {};
std::string str() const std::string str() const
{ {

View File

@ -193,11 +193,12 @@ bool Platform::loadFromFile(const char exename[], const std::string &filename, b
{ {
// TODO: only append .xml if missing // TODO: only append .xml if missing
// TODO: use native separators // TODO: use native separators
std::vector<std::string> filenames; std::vector<std::string> filenames{
filenames.push_back(filename); filename,
filenames.push_back(filename + ".xml"); filename + ".xml",
filenames.push_back("platforms/" + filename); "platforms/" + filename,
filenames.push_back("platforms/" + filename + ".xml"); "platforms/" + filename + ".xml"
};
if (exename && (std::string::npos != Path::fromNativeSeparators(exename).find('/'))) { 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)) + filename);
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + filename); filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + filename);

View File

@ -1131,15 +1131,13 @@ void Tokenizer::simplifyTypedef()
void Tokenizer::simplifyTypedefCpp() void Tokenizer::simplifyTypedefCpp()
{ {
std::vector<Space> spaceInfo;
bool isNamespace = false; bool isNamespace = false;
std::string className; std::string className, fullClassName;
std::string fullClassName;
bool hasClass = false; bool hasClass = false;
bool goback = false; bool goback = false;
// add global namespace // add global namespace
spaceInfo.emplace_back(/*Space{}*/); std::vector<Space> spaceInfo(1);
// Convert "using a::b;" to corresponding typedef statements // Convert "using a::b;" to corresponding typedef statements
simplifyUsingToTypedef(); simplifyUsingToTypedef();
@ -5013,8 +5011,7 @@ void Tokenizer::setVarIdPass2()
const std::string &scopeName(getScopeName(scopeInfo)); const std::string &scopeName(getScopeName(scopeInfo));
const std::string scopeName2(scopeName.empty() ? std::string() : (scopeName + " :: ")); const std::string scopeName2(scopeName.empty() ? std::string() : (scopeName + " :: "));
std::list<const Token *> classnameTokens; std::list<const Token*> classnameTokens{ tok->next() };
classnameTokens.push_back(tok->next());
Token* tokStart = tok->tokAt(2); Token* tokStart = tok->tokAt(2);
while (Token::Match(tokStart, ":: %name%") || tokStart->str() == "<") { while (Token::Match(tokStart, ":: %name%") || tokStart->str() == "<") {
if (tokStart->str() == "<") { if (tokStart->str() == "<") {

View File

@ -1775,7 +1775,7 @@ static void valueFlowRightShift(TokenList &tokenList, const Settings* settings)
static std::vector<MathLib::bigint> minUnsignedValue(const Token* tok, int depth = 8) static std::vector<MathLib::bigint> minUnsignedValue(const Token* tok, int depth = 8)
{ {
std::vector<MathLib::bigint> result = {}; std::vector<MathLib::bigint> result;
if (!tok) if (!tok)
return result; return result;
if (depth < 0) if (depth < 0)
@ -4942,7 +4942,7 @@ static void valueFlowLifetime(TokenList &tokenlist, ErrorLogger *errorLogger, co
continue; continue;
} }
std::vector<const Token*> toks = {}; std::vector<const Token*> toks;
if (tok->isUnaryOp("*") || parent->originalName() == "->") { if (tok->isUnaryOp("*") || parent->originalName() == "->") {
for (const ValueFlow::Value& v : tok->values()) { for (const ValueFlow::Value& v : tok->values()) {
if (!v.isLocalLifetimeValue()) if (!v.isLocalLifetimeValue())
@ -9180,7 +9180,7 @@ struct ValueFlowState {
SymbolDatabase& symboldatabase; SymbolDatabase& symboldatabase;
ErrorLogger* errorLogger = nullptr; ErrorLogger* errorLogger = nullptr;
const Settings* settings = nullptr; const Settings* settings = nullptr;
std::set<const Scope*> skippedFunctions = {}; std::set<const Scope*> skippedFunctions;
}; };
struct ValueFlowPass { struct ValueFlowPass {