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)
{
std::list<const Token *> toks;
toks.push_back(tok1);
std::list<const Token *> toks{ tok1 };
if (tok2)
toks.push_back(tok2);
if (!suggestStatic)

View File

@ -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)

View File

@ -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);

View File

@ -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
{

View File

@ -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);

View File

@ -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();
@ -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() == "<") {

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)
{
std::vector<MathLib::bigint> result = {};
std::vector<MathLib::bigint> result;
if (!tok)
return result;
if (depth < 0)
@ -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())
@ -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 {