diff --git a/clang-tidy.md b/clang-tidy.md index 108af31a354..f54363c9342 100644 --- a/clang-tidy.md +++ b/clang-tidy.md @@ -34,9 +34,7 @@ These are coding guidelines we do not follow. Some of the checks might be explic `readability-braces-around-statements`
`readability-isolate-declaration`
`modernize-use-trailing-return-type`
-`modernize-use-auto`
`readability-uppercase-literal-suffix`
-`readability-else-after-return`
`readability-identifier-length`
These do not reflect the style we are (currently) enforcing. @@ -73,7 +71,7 @@ This leads to a mismatch of raw string literals and regular ones and does reduce `-clang-analyzer-*`
-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`
@@ -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`
This produces a lot of noise and they are not fixable that easily. @@ -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`
`readability-avoid-const-params-in-decls`
`bugprone-signed-char-misuse`
-`readability-redundant-access-specifiers`
`concurrency-mt-unsafe`
`misc-use-anonymous-namespace`
`performance-avoid-endl`
@@ -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`
+ +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`
@@ -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`
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. diff --git a/cli/processexecutor.cpp b/cli/processexecutor.cpp index 912f15c6b63..020c9ab5977 100644 --- a/cli/processexecutor.cpp +++ b/cli/processexecutor.cpp @@ -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(buf[0]); + const auto c = static_cast(buf[0]); // TODO: avoid string copy mErrorLogger.reportOut(buf.substr(1), c); } else if (type == PipeWriter::REPORT_ERROR) { diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 48208121bd4..45820f02de4 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -997,7 +997,7 @@ bool CheckBufferOverrun::analyseWholeProgram(const CTU::FileInfo *ctu, const std const std::map> callsMap = ctu->getCallsMap(); for (const Check::FileInfo* fi1 : fileInfo) { - const MyFileInfo *fi = dynamic_cast(fi1); + const auto *fi = dynamic_cast(fi1); if (!fi) continue; for (const CTU::FileInfo::UnsafeUsage &unsafeUsage : fi->unsafeArrayIndex) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 84ff52c589b..c05d60478ca 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -3652,7 +3652,7 @@ bool CheckClass::analyseWholeProgram(const CTU::FileInfo *ctu, const std::list(fi1); + const auto *fi = dynamic_cast(fi1); if (!fi) continue; for (const MyFileInfo::NameLoc &nameLoc : fi->classDefinitions) { diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index f2421df32cd..35a0219276b 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -614,7 +614,7 @@ bool CheckNullPointer::analyseWholeProgram(const CTU::FileInfo *ctu, const std:: const std::map> callsMap = ctu->getCallsMap(); for (const Check::FileInfo* fi1 : fileInfo) { - const MyFileInfo *fi = dynamic_cast(fi1); + const auto *fi = dynamic_cast(fi1); if (!fi) continue; for (const CTU::FileInfo::UnsafeUsage &unsafeUsage : fi->unsafeUsage) { diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 6c683bd8171..90a6b252394 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1730,7 +1730,7 @@ bool CheckUninitVar::analyseWholeProgram(const CTU::FileInfo *ctu, const std::li const std::map> callsMap = ctu->getCallsMap(); for (const Check::FileInfo* fi1 : fileInfo) { - const MyFileInfo *fi = dynamic_cast(fi1); + const auto *fi = dynamic_cast(fi1); if (!fi) continue; for (const CTU::FileInfo::UnsafeUsage &unsafeUsage : fi->unsafeUsage) { diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 2e70a00a426..58c016272bb 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -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::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) @@ -209,7 +209,7 @@ void Variables::alias(nonneg int varid1, nonneg int varid2, bool replace) } // var1 gets all var2s aliases - for (std::set::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); } @@ -229,7 +229,7 @@ void Variables::clearAliases(nonneg int varid) if (usage) { // remove usage from all aliases - for (std::set::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) @@ -246,7 +246,7 @@ void Variables::eraseAliases(nonneg int varid) VariableUsage *usage = find(varid); if (usage) { - for (std::set::const_iterator aliases = usage->_aliases.cbegin(); aliases != usage->_aliases.cend(); ++aliases) + for (auto aliases = usage->_aliases.cbegin(); aliases != usage->_aliases.cend(); ++aliases) erase(*aliases); } } @@ -326,7 +326,7 @@ void Variables::writeAliases(nonneg int varid, const Token* tok) VariableUsage *usage = find(varid); if (usage) { - for (std::set::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) { @@ -351,7 +351,7 @@ void Variables::use(nonneg int varid, const Token* tok) usage->use(); usage->_lastAccess = tok; - for (std::set::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) { @@ -372,7 +372,7 @@ void Variables::modified(nonneg int varid, const Token* tok) usage->_modified = true; usage->_lastAccess = tok; - for (std::set::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) { @@ -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::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; @@ -1327,7 +1327,7 @@ void CheckUnusedVar::checkFunctionVariableUsage() // Check usage of all variables in the current scope.. - for (std::map::const_iterator it = variables.varUsage().cbegin(); + for (auto it = variables.varUsage().cbegin(); it != variables.varUsage().cend(); ++it) { const Variables::VariableUsage &usage = it->second; diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 345649cfebb..7450f8ab68b 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -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(lineNumString); - const int64_t column = strToInt(columnNumString); + const auto lineNumber = strToInt(lineNumString); + const auto column = strToInt(columnNumString); fixedpath = Path::toNativeSeparators(std::move(fixedpath)); ErrorMessage errmsg; diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index bbeaee3de12..7d900e6a44c 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1741,7 +1741,7 @@ void SymbolDatabase::createSymbolDatabaseExprIds() setParentExprId(tok, exprIdMap, id); } } - for (Token* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { + for (auto* tok = const_cast(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()))) @@ -2121,7 +2121,7 @@ namespace { void SymbolDatabase::validateVariables() const { - for (std::vector::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()) { @@ -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% )"))) @@ -3632,7 +3632,7 @@ bool Type::hasCircularDependencies(std::set* ancestors) const if (!ancestors) { ancestors=&knownAncestors; } - for (std::vector::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) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d84fe688413..ec018d12c9e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3862,7 +3862,7 @@ void Tokenizer::arraySizeAfterValueFlow() } if (maxIndex >= 0) { // insert array size - Token* tok = const_cast(var->nameToken()->next()); + auto* tok = const_cast(var->nameToken()->next()); tok->insertToken(std::to_string(maxIndex + 1)); // ast tok->astOperand2(tok->next()); diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 67e51684ccc..bc1870d0d85 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2055,7 +2055,7 @@ static void valueFlowEnumValue(SymbolDatabase & symboldatabase, const Settings & for (Enumerator & enumerator : scope.enumeratorList) { if (enumerator.start) { - Token* rhs = const_cast(enumerator.start->previous()->astOperand2()); + auto* rhs = const_cast(enumerator.start->previous()->astOperand2()); ValueFlow::valueFlowConstantFoldAST(rhs, settings); if (rhs && rhs->hasKnownIntValue()) { enumerator.value = rhs->values().front().intvalue; @@ -5433,7 +5433,7 @@ static void valueFlowConditionExpressions(const TokenList &tokenlist, const Symb if (settings.daca && !settings.vfOptions.doConditionExpressionAnalysis) continue; - for (Token* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { + for (auto* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { if (!Token::simpleMatch(tok, "if (")) continue; Token* parenTok = tok->next(); @@ -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::const_iterator val = values.cbegin(); val != values.cend(); ++val) { + for (auto val = values.cbegin(); val != values.cend(); ++val) { valueFlowReverse(tokenlist, const_cast(scope.classDef), vartok, @@ -7829,7 +7829,7 @@ static void valueFlowSubFunction(TokenList& tokenlist, SymbolDatabase& symboldat const Function* function = scope->function; if (!function) continue; - for (Token* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { + for (auto* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { if (tok->isKeyword() || !Token::Match(tok, "%name% (")) continue; @@ -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(scope->bodyStart); + auto* tok = const_cast(scope->bodyStart); if (!tok) return start; if (Token::simpleMatch(tok->tokAt(-2), "} else {")) @@ -8930,7 +8930,7 @@ static void valueFlowContainerSize(const TokenList& tokenlist, } if (!staticSize && nonLocal) continue; - Token* nameToken = const_cast(var->nameToken()); + auto* nameToken = const_cast(var->nameToken()); if (nameToken->hasKnownValue(ValueFlow::Value::ValueType::CONTAINER_SIZE)) continue; if (!staticSize) { diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index f022b64ac61..103e9fa8dcd 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -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::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); } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index f096a195f07..2c8fca7827f 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -2166,7 +2166,7 @@ class TestSymbolDatabase : public TestFixture { bool seen_something = false; for (const Scope & scope : db->scopeList) { - for (std::list::const_iterator func = scope.functionList.cbegin(); func != scope.functionList.cend(); ++func) { + for (auto func = scope.functionList.cbegin(); func != scope.functionList.cend(); ++func) { ASSERT_EQUALS("Sub", func->token->str()); ASSERT_EQUALS(true, func->hasBody()); ASSERT_EQUALS(Function::eConstructor, func->type); @@ -2804,7 +2804,7 @@ class TestSymbolDatabase : public TestFixture { "Fred::Fred(Whitespace whitespace) { }"); ASSERT_EQUALS(true, db != nullptr); ASSERT_EQUALS(3, db->scopeList.size()); - std::list::const_iterator scope = db->scopeList.cbegin(); + auto scope = db->scopeList.cbegin(); ++scope; ASSERT_EQUALS((unsigned int)Scope::eClass, (unsigned int)scope->type); ASSERT_EQUALS(1, scope->functionList.size()); @@ -2822,7 +2822,7 @@ class TestSymbolDatabase : public TestFixture { "void Fred::foo(char b[16]) { }"); ASSERT_EQUALS(true, db != nullptr); ASSERT_EQUALS(3, db->scopeList.size()); - std::list::const_iterator scope = db->scopeList.cbegin(); + auto scope = db->scopeList.cbegin(); ++scope; ASSERT_EQUALS((unsigned int)Scope::eClass, (unsigned int)scope->type); ASSERT_EQUALS(1, scope->functionList.size()); @@ -3533,7 +3533,7 @@ class TestSymbolDatabase : public TestFixture { "class Sub;"); ASSERT(db && db->typeList.size() == 5); - std::list::const_iterator i = db->typeList.cbegin(); + auto i = db->typeList.cbegin(); const Type* Foo = &(*i++); const Type* Bar = &(*i++); const Type* Sub = &(*i++); @@ -3601,7 +3601,7 @@ class TestSymbolDatabase : public TestFixture { "};"); ASSERT(db && db->typeList.size() == 3); - std::list::const_iterator i = db->typeList.cbegin(); + auto i = db->typeList.cbegin(); const Type* Fred = &(*i++); const Type* Wilma = &(*i++); const Type* Barney = &(*i++); @@ -3690,7 +3690,7 @@ class TestSymbolDatabase : public TestFixture { ASSERT(db->getVariableFromVarId(i) != nullptr); ASSERT_EQUALS(4U, db->scopeList.size()); - std::list::const_iterator scope = db->scopeList.cbegin(); + auto scope = db->scopeList.cbegin(); ASSERT_EQUALS(Scope::eGlobal, scope->type); ++scope; ASSERT_EQUALS(Scope::eStruct, scope->type); @@ -3708,7 +3708,7 @@ class TestSymbolDatabase : public TestFixture { ASSERT(db != nullptr); ASSERT_EQUALS(4U, db->scopeList.size()); - std::list::const_iterator scope = db->scopeList.cbegin(); + auto scope = db->scopeList.cbegin(); ASSERT_EQUALS(Scope::eGlobal, scope->type); ++scope; ASSERT_EQUALS(Scope::eStruct, scope->type); @@ -3898,7 +3898,7 @@ class TestSymbolDatabase : public TestFixture { "}"); ASSERT(db != nullptr); ASSERT(db->scopeList.size() == 4U); - std::list::const_iterator it = db->scopeList.cbegin(); + auto it = db->scopeList.cbegin(); ASSERT(it->type == Scope::eGlobal); ASSERT((++it)->type == Scope::eFunction); ASSERT((++it)->type == Scope::eIf); @@ -3918,7 +3918,7 @@ class TestSymbolDatabase : public TestFixture { "};"); ASSERT(db != nullptr); ASSERT(db->typeList.size() == 3U); - std::list::const_iterator it = db->typeList.cbegin(); + auto it = db->typeList.cbegin(); const Type * classB = &(*it); const Type * classC = &(*(++it)); const Type * classA = &(*(++it)); @@ -5938,7 +5938,7 @@ class TestSymbolDatabase : public TestFixture { ASSERT_EQUALS(3U, db->scopeList.size()); // Assert that all enum values are known - std::list::const_iterator scope = db->scopeList.cbegin(); + auto scope = db->scopeList.cbegin(); // Offsets ++scope; @@ -6026,7 +6026,7 @@ class TestSymbolDatabase : public TestFixture { ASSERT_EQUALS(2U, db->scopeList.size()); // Assert that all enum values are known - std::list::const_iterator scope = db->scopeList.cbegin(); + auto scope = db->scopeList.cbegin(); ++scope; ASSERT_EQUALS((unsigned int)Scope::eEnum, (unsigned int)scope->type); @@ -6574,7 +6574,7 @@ class TestSymbolDatabase : public TestFixture { " void g();\n" "};"); ASSERT(db && db->scopeList.back().functionList.size() == 4); - std::list::const_iterator it = db->scopeList.back().functionList.cbegin(); + auto it = db->scopeList.back().functionList.cbegin(); ASSERT((it++)->isPure()); ASSERT((it++)->isPure()); ASSERT(!(it++)->isPure()); @@ -8627,7 +8627,7 @@ class TestSymbolDatabase : public TestFixture { "}"); ASSERT(db && db->scopeList.size() == 3); - std::list::const_iterator scope = db->scopeList.cbegin(); + auto scope = db->scopeList.cbegin(); ASSERT_EQUALS(Scope::eGlobal, scope->type); ++scope; ASSERT_EQUALS(Scope::eFunction, scope->type); @@ -8646,7 +8646,7 @@ class TestSymbolDatabase : public TestFixture { "}"); ASSERT(db && db->scopeList.size() == 3); - std::list::const_iterator scope = db->scopeList.cbegin(); + auto scope = db->scopeList.cbegin(); ASSERT_EQUALS(Scope::eGlobal, scope->type); ++scope; ASSERT_EQUALS(Scope::eFunction, scope->type); @@ -8660,7 +8660,7 @@ class TestSymbolDatabase : public TestFixture { "}"); ASSERT(db && db->scopeList.size() == 3); - std::list::const_iterator scope = db->scopeList.cbegin(); + auto scope = db->scopeList.cbegin(); ASSERT_EQUALS(Scope::eGlobal, scope->type); ++scope; ASSERT_EQUALS(Scope::eFunction, scope->type); @@ -8676,7 +8676,7 @@ class TestSymbolDatabase : public TestFixture { "};\n"); ASSERT(db && db->scopeList.size() == 3); - std::list::const_iterator scope = db->scopeList.cbegin(); + auto scope = db->scopeList.cbegin(); ASSERT_EQUALS(Scope::eGlobal, scope->type); ++scope; ASSERT_EQUALS(Scope::eStruct, scope->type); @@ -8699,7 +8699,7 @@ class TestSymbolDatabase : public TestFixture { "}\n"); ASSERT(db && db->scopeList.size() == 3); - std::list::const_iterator scope = db->scopeList.cbegin(); + auto scope = db->scopeList.cbegin(); ASSERT_EQUALS(Scope::eGlobal, scope->type); ++scope; ASSERT_EQUALS(Scope::eFunction, scope->type); @@ -8734,7 +8734,7 @@ class TestSymbolDatabase : public TestFixture { "Fred::foo(const std::string & b) { }"); ASSERT(db && db->scopeList.size() == 3); - std::list::const_iterator scope = db->scopeList.cbegin(); + auto scope = db->scopeList.cbegin(); ASSERT_EQUALS(Scope::eGlobal, scope->type); ++scope; ASSERT_EQUALS(Scope::eClass, scope->type); @@ -8749,7 +8749,7 @@ class TestSymbolDatabase : public TestFixture { "bool f(bool (*g)(int)) { return g(0); }\n"); ASSERT(db && db->scopeList.size() == 2); - std::list::const_iterator scope = db->scopeList.cbegin(); + auto scope = db->scopeList.cbegin(); ASSERT_EQUALS(Scope::eGlobal, scope->type); ASSERT(scope->functionList.size() == 1); ++scope;