Shadow variables, const, rename function (#3456)

This commit is contained in:
chrchr-github 2021-09-15 20:28:58 +02:00 committed by GitHub
parent a9a093e7cc
commit 05acc13582
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 26 deletions

View File

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

View File

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

View File

@ -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<BadInlineSuppression> *bad)
static void addinlineSuppressions(const simplecpp::TokenList &tokens, Settings &mSettings, std::list<BadInlineSuppression> *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<BadInlineSuppression> err;
::inlineSuppressions(tokens, mSettings, &err);
::addinlineSuppressions(tokens, mSettings, &err);
for (std::map<std::string,simplecpp::TokenList*>::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::set<s
if (sameline(iftok,dtok) && dtok->name && 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<std::string> &configs, const std::strin
{
std::set<std::string> 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<std::string, std::str
const std::set<std::string> 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);
}
}
}

View File

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

View File

@ -3928,9 +3928,9 @@ private:
// Check code..
std::list<Check::FileInfo*> 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();