From 05acc13582e62cb31bae1658c627d0edcca6a2eb Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 15 Sep 2021 20:28:58 +0200 Subject: [PATCH] Shadow variables, const, rename function (#3456) --- lib/checkother.cpp | 4 ++-- lib/exprengine.cpp | 2 +- lib/preprocessor.cpp | 32 ++++++++++++++++---------------- lib/templatesimplifier.cpp | 8 ++++---- test/testnullpointer.cpp | 6 +++--- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index dc9e6012a..f4fb2a923 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2988,8 +2988,8 @@ void CheckOther::checkAccessOfMovedVariable() else inconclusive = true; } else { - const bool isVariableChanged = isVariableChangedByFunctionCall(tok, 0, mSettings, &inconclusive); - accessOfMoved = !isVariableChanged && checkUninitVar.isVariableUsage(tok, false, CheckUninitVar::NO_ALLOC); + const bool variableChanged = isVariableChangedByFunctionCall(tok, 0, mSettings, &inconclusive); + accessOfMoved = !variableChanged && checkUninitVar.isVariableUsage(tok, false, CheckUninitVar::NO_ALLOC); if (inconclusive) { accessOfMoved = !isMovedParameterAllowedForInconclusiveFunction(tok); if (accessOfMoved) diff --git a/lib/exprengine.cpp b/lib/exprengine.cpp index 2e5a95882..d1abb24dd 100644 --- a/lib/exprengine.cpp +++ b/lib/exprengine.cpp @@ -303,7 +303,7 @@ namespace { } } - void report(std::ostream &out, const Scope *functionScope) { + void report(std::ostream &out, const Scope *functionScope) const { int linenr = -1; std::string code; for (const Token *tok = functionScope->bodyStart->next(); tok != functionScope->bodyEnd; tok = tok->next()) { diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 9b735f8f0..79b5e3e6b 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -127,7 +127,7 @@ static bool parseInlineSuppressionCommentToken(const simplecpp::Token *tok, std: return true; } -static void inlineSuppressions(const simplecpp::TokenList &tokens, Settings &mSettings, std::list *bad) +static void addinlineSuppressions(const simplecpp::TokenList &tokens, Settings &mSettings, std::list *bad) { for (const simplecpp::Token *tok = tokens.cfront(); tok; tok = tok->next) { if (!tok->comment) @@ -187,10 +187,10 @@ void Preprocessor::inlineSuppressions(const simplecpp::TokenList &tokens) if (!mSettings.inlineSuppressions) return; std::list err; - ::inlineSuppressions(tokens, mSettings, &err); + ::addinlineSuppressions(tokens, mSettings, &err); for (std::map::const_iterator it = mTokenLists.begin(); it != mTokenLists.end(); ++it) { if (it->second) - ::inlineSuppressions(*it->second, mSettings, &err); + ::addinlineSuppressions(*it->second, mSettings, &err); } for (const BadInlineSuppression &bad : err) { error(bad.location.file(), bad.location.line, bad.errmsg); @@ -292,13 +292,13 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::setname && defined.find(dtok->str()) == defined.end() && undefined.find(dtok->str()) == undefined.end()) configset.insert(dtok->str()); } - std::string cfg; + std::string cfgStr; for (const std::string &s : configset) { - if (!cfg.empty()) - cfg += ';'; - cfg += s; + if (!cfgStr.empty()) + cfgStr += ';'; + cfgStr += s; } - return cfg; + return cfgStr; } static bool hasDefine(const std::string &userDefines, const std::string &cfg) @@ -324,16 +324,16 @@ static std::string cfg(const std::vector &configs, const std::strin { std::set configs2(configs.begin(), configs.end()); std::string ret; - for (const std::string &cfg : configs2) { - if (cfg.empty()) + for (const std::string &c : configs2) { + if (c.empty()) continue; - if (cfg == "0") + if (c == "0") return ""; - if (hasDefine(userDefines, cfg)) + if (hasDefine(userDefines, c)) continue; if (!ret.empty()) ret += ';'; - ret += cfg; + ret += c; } return ret; } @@ -552,9 +552,9 @@ void Preprocessor::preprocess(std::istream &istr, std::map configs = getConfigs(tokens1); - for (const std::string &cfg : configs) { - if (mSettings.userUndefs.find(cfg) == mSettings.userUndefs.end()) { - result[cfg] = getcode(tokens1, cfg, files, false); + for (const std::string &c : configs) { + if (mSettings.userUndefs.find(c) == mSettings.userUndefs.end()) { + result[c] = getcode(tokens1, c, files, false); } } } diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 770dd259d..dca99e050 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1680,9 +1680,9 @@ void TemplateSimplifier::expandTemplate( const bool isVariadicTemplateArg = templateDeclaration.isVariadic() && itype + 1 == typeParametersInDeclaration.size(); if (isVariadicTemplateArg && Token::Match(start, "%name% ... %name%")) start = start->tokAt(2); - const std::string endsWith(isVariadicTemplateArg ? ">" : ",>"); + const std::string endStr(isVariadicTemplateArg ? ">" : ",>"); for (const Token *typetok = mTypesUsedInTemplateInstantiation[itype].token(); - typetok && (typeindentlevel > 0 || endsWith.find(typetok->str()[0]) == std::string::npos); + typetok && (typeindentlevel > 0 || endStr.find(typetok->str()[0]) == std::string::npos); typetok = typetok->next()) { if (typeindentlevel == 0 && typetok->str() == "*") pointerType = true; @@ -2041,9 +2041,9 @@ void TemplateSimplifier::expandTemplate( const bool isVariadicTemplateArg = templateDeclaration.isVariadic() && itype + 1 == typeParametersInDeclaration.size(); if (isVariadicTemplateArg && Token::Match(tok3, "%name% ... %name%")) tok3 = tok3->tokAt(2); - const std::string endsWith(isVariadicTemplateArg ? ">" : ",>"); + const std::string endStr(isVariadicTemplateArg ? ">" : ",>"); for (const Token *typetok = mTypesUsedInTemplateInstantiation[itype].token(); - typetok && (typeindentlevel > 0 || endsWith.find(typetok->str()[0]) == std::string::npos); + typetok && (typeindentlevel > 0 || endStr.find(typetok->str()[0]) == std::string::npos); typetok = typetok->next()) { if (typeindentlevel == 0 && typetok->str() == "*") pointerType = true; diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 299eb06fc..b4586485c 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -3928,9 +3928,9 @@ private: // Check code.. std::list fileInfo; - CheckNullPointer check(&tokenizer, &settings, this); - fileInfo.push_back(check.getFileInfo(&tokenizer, &settings)); - check.analyseWholeProgram(ctu, fileInfo, settings, *this); + CheckNullPointer checkNullPointer(&tokenizer, &settings, this); + fileInfo.push_back(checkNullPointer.getFileInfo(&tokenizer, &settings)); + checkNullPointer.analyseWholeProgram(ctu, fileInfo, settings, *this); while (!fileInfo.empty()) { delete fileInfo.back(); fileInfo.pop_back();