Skip to content

Commit

Permalink
mitigated some modernize-use-auto clang-tidy warnings (danmar#5838)
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave authored May 24, 2024
1 parent 00a3ae0 commit fa561e9
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 53 deletions.
12 changes: 6 additions & 6 deletions clang-tidy.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ These are coding guidelines we do not follow. Some of the checks might be explic
`readability-braces-around-statements`<br/>
`readability-isolate-declaration`<br/>
`modernize-use-trailing-return-type`<br/>
`modernize-use-auto`<br/>
`readability-uppercase-literal-suffix`<br/>
`readability-else-after-return`<br/>
`readability-identifier-length`<br/>

These do not reflect the style we are (currently) enforcing.
Expand Down Expand Up @@ -73,7 +71,7 @@ This leads to a mismatch of raw string literals and regular ones and does reduce

`-clang-analyzer-*`<br/>

Disabled because of false positives (needs to file an upstream bug report).
Disabled because of false positives (need to file upstream bug reports). The checks are also quite time consuming.

`misc-non-private-member-variables-in-classes`<br/>

Expand All @@ -83,7 +81,6 @@ We intentionally use this.

Leads to lots of "false positives". This seem to enforce a coding guidelines of certain codebases.


`bugprone-easily-swappable-parameters`<br/>

This produces a lot of noise and they are not fixable that easily.
Expand Down Expand Up @@ -122,7 +119,6 @@ We run this separately via `clang-include-cleaner` in the `iwyu.yml` workflow as
`misc-throw-by-value-catch-by-reference`<br/>
`readability-avoid-const-params-in-decls`<br/>
`bugprone-signed-char-misuse`<br/>
`readability-redundant-access-specifiers`<br/>
`concurrency-mt-unsafe`<br/>
`misc-use-anonymous-namespace`<br/>
`performance-avoid-endl`<br/>
Expand Down Expand Up @@ -153,6 +149,10 @@ To be evaluated (need to enable explicitly).

These apply to codebases which use later standards then C++11 (C++17 is used when building with Qt6) so we cannot simply apply them.

`modernize-use-auto`<br/>

This cannot be enabled as it might lead to changes in the constness of iterators - see https://github.com/llvm/llvm-project/issues/84324.

### Disabled for performance reasons

`portability-std-allocator-const`<br/>
Expand Down Expand Up @@ -183,7 +183,7 @@ We are not using SIMD instructions and it suggests to use `std::experiemental::`

It does not seem to produce any warnings for us (needs to be investigated) and it is one of the more expensive checks.

`misc-unused-using-decls`
`misc-unused-using-decls`<br/>

This is the most expensive check for several files and it is providing much in terms of code quality. Reported upstream as https://github.com/llvm/llvm-project/issues/72300.

Expand Down
2 changes: 1 addition & 1 deletion cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
bool res = true;
if (type == PipeWriter::REPORT_OUT) {
// the first character is the color
const Color c = static_cast<Color>(buf[0]);
const auto c = static_cast<Color>(buf[0]);
// TODO: avoid string copy
mErrorLogger.reportOut(buf.substr(1), c);
} else if (type == PipeWriter::REPORT_ERROR) {
Expand Down
2 changes: 1 addition & 1 deletion lib/checkbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ bool CheckBufferOverrun::analyseWholeProgram(const CTU::FileInfo *ctu, const std
const std::map<std::string, std::list<const CTU::FileInfo::CallBase *>> callsMap = ctu->getCallsMap();

for (const Check::FileInfo* fi1 : fileInfo) {
const MyFileInfo *fi = dynamic_cast<const MyFileInfo*>(fi1);
const auto *fi = dynamic_cast<const MyFileInfo*>(fi1);
if (!fi)
continue;
for (const CTU::FileInfo::UnsafeUsage &unsafeUsage : fi->unsafeArrayIndex)
Expand Down
2 changes: 1 addition & 1 deletion lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3652,7 +3652,7 @@ bool CheckClass::analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<C
logChecker("CheckClass::analyseWholeProgram");

for (const Check::FileInfo* fi1 : fileInfo) {
const MyFileInfo *fi = dynamic_cast<const MyFileInfo*>(fi1);
const auto *fi = dynamic_cast<const MyFileInfo*>(fi1);
if (!fi)
continue;
for (const MyFileInfo::NameLoc &nameLoc : fi->classDefinitions) {
Expand Down
2 changes: 1 addition & 1 deletion lib/checknullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ bool CheckNullPointer::analyseWholeProgram(const CTU::FileInfo *ctu, const std::
const std::map<std::string, std::list<const CTU::FileInfo::CallBase *>> callsMap = ctu->getCallsMap();

for (const Check::FileInfo* fi1 : fileInfo) {
const MyFileInfo *fi = dynamic_cast<const MyFileInfo*>(fi1);
const auto *fi = dynamic_cast<const MyFileInfo*>(fi1);
if (!fi)
continue;
for (const CTU::FileInfo::UnsafeUsage &unsafeUsage : fi->unsafeUsage) {
Expand Down
2 changes: 1 addition & 1 deletion lib/checkuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ bool CheckUninitVar::analyseWholeProgram(const CTU::FileInfo *ctu, const std::li
const std::map<std::string, std::list<const CTU::FileInfo::CallBase *>> callsMap = ctu->getCallsMap();

for (const Check::FileInfo* fi1 : fileInfo) {
const MyFileInfo *fi = dynamic_cast<const MyFileInfo*>(fi1);
const auto *fi = dynamic_cast<const MyFileInfo*>(fi1);
if (!fi)
continue;
for (const CTU::FileInfo::UnsafeUsage &unsafeUsage : fi->unsafeUsage) {
Expand Down
18 changes: 9 additions & 9 deletions lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void Variables::alias(nonneg int varid1, nonneg int varid2, bool replace)

if (replace) {
// remove var1 from all aliases
for (std::set<nonneg int>::const_iterator i = var1->_aliases.cbegin(); i != var1->_aliases.cend(); ++i) {
for (auto i = var1->_aliases.cbegin(); i != var1->_aliases.cend(); ++i) {
VariableUsage *temp = find(*i);

if (temp)
Expand All @@ -209,7 +209,7 @@ void Variables::alias(nonneg int varid1, nonneg int varid2, bool replace)
}

// var1 gets all var2s aliases
for (std::set<nonneg int>::const_iterator i = var2->_aliases.cbegin(); i != var2->_aliases.cend(); ++i) {
for (auto i = var2->_aliases.cbegin(); i != var2->_aliases.cend(); ++i) {
if (*i != varid1)
var1->_aliases.insert(*i);
}
Expand All @@ -229,7 +229,7 @@ void Variables::clearAliases(nonneg int varid)

if (usage) {
// remove usage from all aliases
for (std::set<nonneg int>::const_iterator i = usage->_aliases.cbegin(); i != usage->_aliases.cend(); ++i) {
for (auto i = usage->_aliases.cbegin(); i != usage->_aliases.cend(); ++i) {
VariableUsage *temp = find(*i);

if (temp)
Expand All @@ -246,7 +246,7 @@ void Variables::eraseAliases(nonneg int varid)
VariableUsage *usage = find(varid);

if (usage) {
for (std::set<nonneg int>::const_iterator aliases = usage->_aliases.cbegin(); aliases != usage->_aliases.cend(); ++aliases)
for (auto aliases = usage->_aliases.cbegin(); aliases != usage->_aliases.cend(); ++aliases)
erase(*aliases);
}
}
Expand Down Expand Up @@ -326,7 +326,7 @@ void Variables::writeAliases(nonneg int varid, const Token* tok)
VariableUsage *usage = find(varid);

if (usage) {
for (std::set<nonneg int>::const_iterator aliases = usage->_aliases.cbegin(); aliases != usage->_aliases.cend(); ++aliases) {
for (auto aliases = usage->_aliases.cbegin(); aliases != usage->_aliases.cend(); ++aliases) {
VariableUsage *aliased = find(*aliases);

if (aliased) {
Expand All @@ -351,7 +351,7 @@ void Variables::use(nonneg int varid, const Token* tok)
usage->use();
usage->_lastAccess = tok;

for (std::set<nonneg int>::const_iterator aliases = usage->_aliases.cbegin(); aliases != usage->_aliases.cend(); ++aliases) {
for (auto aliases = usage->_aliases.cbegin(); aliases != usage->_aliases.cend(); ++aliases) {
VariableUsage *aliased = find(*aliases);

if (aliased) {
Expand All @@ -372,7 +372,7 @@ void Variables::modified(nonneg int varid, const Token* tok)
usage->_modified = true;
usage->_lastAccess = tok;

for (std::set<nonneg int>::const_iterator aliases = usage->_aliases.cbegin(); aliases != usage->_aliases.cend(); ++aliases) {
for (auto aliases = usage->_aliases.cbegin(); aliases != usage->_aliases.cend(); ++aliases) {
VariableUsage *aliased = find(*aliases);

if (aliased) {
Expand Down Expand Up @@ -693,7 +693,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
// Find declarations if the scope is executable..
if (scope->isExecutable()) {
// Find declarations
for (std::list<Variable>::const_iterator i = scope->varlist.cbegin(); i != scope->varlist.cend(); ++i) {
for (auto i = scope->varlist.cbegin(); i != scope->varlist.cend(); ++i) {
if (i->isThrow() || i->isExtern())
continue;
Variables::VariableType type = Variables::none;
Expand Down Expand Up @@ -1327,7 +1327,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()


// Check usage of all variables in the current scope..
for (std::map<nonneg int, Variables::VariableUsage>::const_iterator it = variables.varUsage().cbegin();
for (auto it = variables.varUsage().cbegin();
it != variables.varUsage().cend();
++it) {
const Variables::VariableUsage &usage = it->second;
Expand Down
4 changes: 2 additions & 2 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1708,8 +1708,8 @@ void CppCheck::analyseClangTidy(const FileSettings &fileSettings)
const std::string errorString = line.substr(endErrorPos, line.length());

std::string fixedpath = Path::simplifyPath(line.substr(0, endNamePos));
const int64_t lineNumber = strToInt<int64_t>(lineNumString);
const int64_t column = strToInt<int64_t>(columnNumString);
const auto lineNumber = strToInt<int64_t>(lineNumString);
const auto column = strToInt<int64_t>(columnNumString);
fixedpath = Path::toNativeSeparators(std::move(fixedpath));

ErrorMessage errmsg;
Expand Down
8 changes: 4 additions & 4 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,7 @@ void SymbolDatabase::createSymbolDatabaseExprIds()
setParentExprId(tok, exprIdMap, id);
}
}
for (Token* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
for (auto* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
if (tok->varId() == 0 && tok->exprId() > 0 && tok->astParent() && !tok->astOperand1() && !tok->astOperand2()) {
if (tok->isNumber() || tok->isKeyword() || Token::Match(tok->astParent(), ".|::") ||
(Token::simpleMatch(tok->astParent(), "(") && precedes(tok, tok->astParent())))
Expand Down Expand Up @@ -2121,7 +2121,7 @@ namespace {

void SymbolDatabase::validateVariables() const
{
for (std::vector<const Variable *>::const_iterator iter = mVariableList.cbegin(); iter!=mVariableList.cend(); ++iter) {
for (auto iter = mVariableList.cbegin(); iter!=mVariableList.cend(); ++iter) {
const Variable * const var = *iter;
if (var) {
if (!var->scope()) {
Expand Down Expand Up @@ -2415,7 +2415,7 @@ void Variable::setValueType(const ValueType &valueType)
if (declType && !declType->next()->valueType())
return;
}
ValueType* vt = new ValueType(valueType);
auto* vt = new ValueType(valueType);
delete mValueType;
mValueType = vt;
if ((mValueType->pointer > 0) && (!isArray() || Token::Match(mNameToken->previous(), "( * %name% )")))
Expand Down Expand Up @@ -3632,7 +3632,7 @@ bool Type::hasCircularDependencies(std::set<BaseInfo>* ancestors) const
if (!ancestors) {
ancestors=&knownAncestors;
}
for (std::vector<BaseInfo>::const_iterator parent=derivedFrom.cbegin(); parent!=derivedFrom.cend(); ++parent) {
for (auto parent=derivedFrom.cbegin(); parent!=derivedFrom.cend(); ++parent) {
if (!parent->type)
continue;
if (this==parent->type)
Expand Down
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3862,7 +3862,7 @@ void Tokenizer::arraySizeAfterValueFlow()
}
if (maxIndex >= 0) {
// insert array size
Token* tok = const_cast<Token*>(var->nameToken()->next());
auto* tok = const_cast<Token*>(var->nameToken()->next());
tok->insertToken(std::to_string(maxIndex + 1));
// ast
tok->astOperand2(tok->next());
Expand Down
12 changes: 6 additions & 6 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2055,7 +2055,7 @@ static void valueFlowEnumValue(SymbolDatabase & symboldatabase, const Settings &

for (Enumerator & enumerator : scope.enumeratorList) {
if (enumerator.start) {
Token* rhs = const_cast<Token*>(enumerator.start->previous()->astOperand2());
auto* rhs = const_cast<Token*>(enumerator.start->previous()->astOperand2());
ValueFlow::valueFlowConstantFoldAST(rhs, settings);
if (rhs && rhs->hasKnownIntValue()) {
enumerator.value = rhs->values().front().intvalue;
Expand Down Expand Up @@ -5433,7 +5433,7 @@ static void valueFlowConditionExpressions(const TokenList &tokenlist, const Symb
if (settings.daca && !settings.vfOptions.doConditionExpressionAnalysis)
continue;

for (Token* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
for (auto* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
if (!Token::simpleMatch(tok, "if ("))
continue;
Token* parenTok = tok->next();
Expand Down Expand Up @@ -7728,7 +7728,7 @@ static void valueFlowSwitchVariable(const TokenList &tokenlist, const SymbolData
values.back().condition = tok;
values.back().errorPath.emplace_back(tok, "case " + tok->next()->str() + ": " + vartok->str() + " is " + tok->next()->str() + " here.");
}
for (std::list<ValueFlow::Value>::const_iterator val = values.cbegin(); val != values.cend(); ++val) {
for (auto val = values.cbegin(); val != values.cend(); ++val) {
valueFlowReverse(tokenlist,
const_cast<Token*>(scope.classDef),
vartok,
Expand Down Expand Up @@ -7829,7 +7829,7 @@ static void valueFlowSubFunction(TokenList& tokenlist, SymbolDatabase& symboldat
const Function* function = scope->function;
if (!function)
continue;
for (Token* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
for (auto* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
if (tok->isKeyword() || !Token::Match(tok, "%name% ("))
continue;

Expand Down Expand Up @@ -8131,7 +8131,7 @@ static Token* findStartToken(const Variable* var, Token* start, const Library& l
scope = scope->nestedIn;
if (!scope)
return start;
Token* tok = const_cast<Token*>(scope->bodyStart);
auto* tok = const_cast<Token*>(scope->bodyStart);
if (!tok)
return start;
if (Token::simpleMatch(tok->tokAt(-2), "} else {"))
Expand Down Expand Up @@ -8930,7 +8930,7 @@ static void valueFlowContainerSize(const TokenList& tokenlist,
}
if (!staticSize && nonLocal)
continue;
Token* nameToken = const_cast<Token*>(var->nameToken());
auto* nameToken = const_cast<Token*>(var->nameToken());
if (nameToken->hasKnownValue(ValueFlow::Value::ValueType::CONTAINER_SIZE))
continue;
if (!staticSize) {
Expand Down
2 changes: 1 addition & 1 deletion test/testgarbage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class TestGarbage : public TestFixture {
ASSERT_LOC(tokenizer.tokenize(code, cpp), file, line);

// call all "runChecks" in all registered Check classes
for (std::list<Check *>::const_iterator it = Check::instances().cbegin(); it != Check::instances().cend(); ++it) {
for (auto it = Check::instances().cbegin(); it != Check::instances().cend(); ++it) {
(*it)->runChecks(tokenizer, this);
}

Expand Down
Loading

0 comments on commit fa561e9

Please sign in to comment.