Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Checks: >
-modernize-replace-auto-ptr,
-modernize-return-braced-init-list,
-modernize-type-traits,
-modernize-use-auto,
-modernize-use-designated-initializers,
-modernize-use-nodiscard,
-modernize-use-trailing-return-type,
Expand Down
106 changes: 53 additions & 53 deletions Makefile

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions clang-tidy.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ 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
2 changes: 1 addition & 1 deletion cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])

// Check that all include paths exist
{
for (std::list<std::string>::const_iterator iter = mSettings.includePaths.cbegin();
for (auto iter = mSettings.includePaths.cbegin();
iter != mSettings.includePaths.cend();
) {
const std::string path(Path::toNativeSeparators(*iter));
Expand Down
6 changes: 3 additions & 3 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,12 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, const Suppre
// the two inputs may only be used exclusively
assert(!(!files.empty() && !fileSettings.empty()));

for (std::list<FileWithDetails>::const_iterator i = files.cbegin(); i != files.cend(); ++i) {
for (auto i = files.cbegin(); i != files.cend(); ++i) {
err |= SuppressionList::reportUnmatchedSuppressions(
suppressions.getUnmatchedLocalSuppressions(*i, unusedFunctionCheckEnabled), errorLogger);
}

for (std::list<FileSettings>::const_iterator i = fileSettings.cbegin(); i != fileSettings.cend(); ++i) {
for (auto i = fileSettings.cbegin(); i != fileSettings.cend(); ++i) {
err |= SuppressionList::reportUnmatchedSuppressions(
suppressions.getUnmatchedLocalSuppressions(i->file, unusedFunctionCheckEnabled), errorLogger);
}
Expand All @@ -419,7 +419,7 @@ int CppCheckExecutor::check_internal(const Settings& settings) const

if (!settings.buildDir.empty()) {
std::list<std::string> fileNames;
for (std::list<FileWithDetails>::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i)
for (auto i = mFiles.cbegin(); i != mFiles.cend(); ++i)
fileNames.emplace_back(i->path());
AnalyzerInformation::writeFilesTxt(settings.buildDir, fileNames, settings.userDefines, mFileSettings);
}
Expand Down
13 changes: 7 additions & 6 deletions cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "settings.h"
#include "suppressions.h"
#include "timer.h"
#include "utils.h"

#include <algorithm>
#include <numeric>
Expand Down Expand Up @@ -242,8 +243,8 @@ unsigned int ProcessExecutor::check()
std::map<pid_t, std::string> childFile;
std::map<int, std::string> pipeFile;
std::size_t processedsize = 0;
std::list<FileWithDetails>::const_iterator iFile = mFiles.cbegin();
std::list<FileSettings>::const_iterator iFileSettings = mFileSettings.cbegin();
auto iFile = mFiles.cbegin();
auto iFileSettings = mFileSettings.cbegin();
for (;;) {
// Start a new child
const size_t nchildren = childFile.size();
Expand Down Expand Up @@ -310,19 +311,19 @@ unsigned int ProcessExecutor::check()
if (!rpipes.empty()) {
fd_set rfds;
FD_ZERO(&rfds);
for (std::list<int>::const_iterator rp = rpipes.cbegin(); rp != rpipes.cend(); ++rp)
for (auto rp = rpipes.cbegin(); rp != rpipes.cend(); ++rp)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a range for loop right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably can - but so do others. modernize-loop-convert is currently disabled and that should report by it. Now that we have made more cleanups I will give that another spin.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR enabling that warning is coming up after this.

FD_SET(*rp, &rfds);
timeval tv; // for every second polling of load average condition
tv.tv_sec = 1;
tv.tv_usec = 0;
const int r = select(*std::max_element(rpipes.cbegin(), rpipes.cend()) + 1, &rfds, nullptr, nullptr, &tv);

if (r > 0) {
std::list<int>::const_iterator rp = rpipes.cbegin();
auto rp = rpipes.cbegin();
while (rp != rpipes.cend()) {
if (FD_ISSET(*rp, &rfds)) {
std::string name;
const std::map<int, std::string>::const_iterator p = pipeFile.find(*rp);
const auto p = utils::as_const(pipeFile).find(*rp);
if (p != pipeFile.cend()) {
name = p->second;
}
Expand Down Expand Up @@ -358,7 +359,7 @@ unsigned int ProcessExecutor::check()
const pid_t child = waitpid(0, &stat, WNOHANG);
if (child > 0) {
std::string childname;
const std::map<pid_t, std::string>::const_iterator c = childFile.find(child);
const auto c = utils::as_const(childFile).find(child);
if (c != childFile.cend()) {
childname = c->second;
childFile.erase(c);
Expand Down
6 changes: 4 additions & 2 deletions cli/signalhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#if defined(USE_UNIX_SIGNAL_HANDLING)

#include "utils.h"

#ifdef USE_UNIX_BACKTRACE_SUPPORT
#include "stacktrace.h"
#endif
Expand Down Expand Up @@ -119,7 +121,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
killid = getpid();
#endif

const Signalmap_t::const_iterator it=listofsignals.find(signo);
const auto it = utils::as_const(listofsignals).find(signo);
const char * const signame = (it==listofsignals.end()) ? "unknown" : it->second.c_str();
bool unexpectedSignal=true; // unexpected indicates program failure
bool terminate=true; // exit process/thread
Expand Down Expand Up @@ -320,7 +322,7 @@ void register_signal_handler(FILE * const output)
memset(&act, 0, sizeof(act));
act.sa_flags=SA_SIGINFO|SA_ONSTACK;
act.sa_sigaction=CppcheckSignalHandler;
for (std::map<int, std::string>::const_iterator sig=listofsignals.cbegin(); sig!=listofsignals.cend(); ++sig) {
for (auto sig=listofsignals.cbegin(); sig!=listofsignals.cend(); ++sig) {
sigaction(sig->first, &act, nullptr);
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/singleexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ unsigned int SingleExecutor::check()
std::size_t processedsize = 0;
unsigned int c = 0;

for (std::list<FileWithDetails>::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i) {
for (auto i = mFiles.cbegin(); i != mFiles.cend(); ++i) {
result += mCppcheck.check(*i);
processedsize += i->size();
++c;
Expand Down
4 changes: 2 additions & 2 deletions gui/checkthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ void CheckThread::runAddonsAndTools(const Settings& settings, const FileSettings
continue;

QStringList args;
for (std::list<std::string>::const_iterator incIt = fileSettings->includePaths.cbegin(); incIt != fileSettings->includePaths.cend(); ++incIt)
for (auto incIt = fileSettings->includePaths.cbegin(); incIt != fileSettings->includePaths.cend(); ++incIt)
args << ("-I" + QString::fromStdString(*incIt));
for (std::list<std::string>::const_iterator i = fileSettings->systemIncludePaths.cbegin(); i != fileSettings->systemIncludePaths.cend(); ++i)
for (auto i = fileSettings->systemIncludePaths.cbegin(); i != fileSettings->systemIncludePaths.cend(); ++i)
args << "-isystem" << QString::fromStdString(*i);
for (const QString& def : QString::fromStdString(fileSettings->defines).split(";")) {
args << ("-D" + def);
Expand Down
2 changes: 1 addition & 1 deletion gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ void MainWindow::analyzeFiles()

if (file0.endsWith(".sln")) {
QStringList configs;
for (std::list<FileSettings>::const_iterator it = p.fileSettings.cbegin(); it != p.fileSettings.cend(); ++it) {
for (auto it = p.fileSettings.cbegin(); it != p.fileSettings.cend(); ++it) {
const QString cfg(QString::fromStdString(it->cfg));
if (!configs.contains(cfg))
configs.push_back(cfg);
Expand Down
2 changes: 1 addition & 1 deletion gui/platforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int Platforms::getCount() const

PlatformData& Platforms::get(Platform::Type platform)
{
QList<PlatformData>::iterator iter = mPlatforms.begin();
auto iter = mPlatforms.begin();
while (iter != mPlatforms.end()) {
if (iter->mType == platform) {
return *iter;
Expand Down
2 changes: 1 addition & 1 deletion lib/checkautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static bool isAutoVarArray(const Token *tok)

// ValueFlow
if (var->isPointer() && !var->isArgument()) {
for (std::list<ValueFlow::Value>::const_iterator it = tok->values().cbegin(); it != tok->values().cend(); ++it) {
for (auto it = tok->values().cbegin(); it != tok->values().cend(); ++it) {
const ValueFlow::Value &val = *it;
if (val.isTokValue() && isAutoVarArray(val.tokvalue))
return true;
Expand Down
23 changes: 11 additions & 12 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ void CheckClass::copyconstructors()
}
if (!funcDestructor || funcDestructor->isDefault()) {
const Token * mustDealloc = nullptr;
for (std::map<int, const Token*>::const_iterator it = allocatedVars.cbegin(); it != allocatedVars.cend(); ++it) {
for (auto it = allocatedVars.cbegin(); it != allocatedVars.cend(); ++it) {
if (!Token::Match(it->second, "%var% [(=] new %type%")) {
mustDealloc = it->second;
break;
Expand Down Expand Up @@ -515,7 +515,7 @@ void CheckClass::copyconstructors()
copyConstructorShallowCopyError(cv, cv->str());
// throw error if count mismatch
/* FIXME: This doesn't work. See #4154
for (std::map<int, const Token*>::const_iterator i = allocatedVars.begin(); i != allocatedVars.end(); ++i) {
for (auto i = allocatedVars.cbegin(); i != allocatedVars.end(); ++i) {
copyConstructorMallocError(copyCtor, i->second, i->second->str());
}
*/
Expand Down Expand Up @@ -1232,7 +1232,7 @@ static bool checkFunctionUsage(const Function *privfunc, const Scope* scope)
if (!scope)
return true; // Assume it is used, if scope is not seen

for (std::list<Function>::const_iterator func = scope->functionList.cbegin(); func != scope->functionList.cend(); ++func) {
for (auto func = scope->functionList.cbegin(); func != scope->functionList.cend(); ++func) {
if (func->functionScope) {
if (Token::Match(func->tokenDef, "%name% (")) {
for (const Token *ftok = func->tokenDef->tokAt(2); ftok && ftok->str() != ")"; ftok = ftok->next()) {
Expand All @@ -1254,8 +1254,7 @@ static bool checkFunctionUsage(const Function *privfunc, const Scope* scope)
return true;
}

const std::map<std::string, Type*>::const_iterator end = scope->definedTypesMap.cend();
for (std::map<std::string, Type*>::const_iterator iter = scope->definedTypesMap.cbegin(); iter != end; ++iter) {
for (auto iter = scope->definedTypesMap.cbegin(); iter != scope->definedTypesMap.cend(); ++iter) {
const Type *type = iter->second;
if (type->enclosingScope == scope && checkFunctionUsage(privfunc, type->classScope))
return true;
Expand Down Expand Up @@ -1300,7 +1299,7 @@ void CheckClass::privateFunctions()
// Bailout for overridden virtual functions of base classes
if (!scope->definedType->derivedFrom.empty()) {
// Check virtual functions
for (std::list<const Function*>::const_iterator it = privateFuncs.cbegin(); it != privateFuncs.cend();) {
for (auto it = privateFuncs.cbegin(); it != privateFuncs.cend();) {
if ((*it)->isImplicitlyVirtual(true)) // Give true as default value to be returned if we don't see all base classes
it = privateFuncs.erase(it);
else
Expand Down Expand Up @@ -1578,7 +1577,7 @@ void CheckClass::operatorEqRetRefThis()
logChecker("CheckClass::operatorEqRetRefThis"); // style

for (const Scope * scope : mSymbolDatabase->classAndStructScopes) {
for (std::list<Function>::const_iterator func = scope->functionList.cbegin(); func != scope->functionList.cend(); ++func) {
for (auto func = scope->functionList.cbegin(); func != scope->functionList.cend(); ++func) {
if (func->type == Function::eOperatorEqual && func->hasBody()) {
// make sure return signature is correct
if (func->retType == func->nestedIn->definedType && func->tokenDef->strAt(-1) == "&") {
Expand Down Expand Up @@ -1626,7 +1625,7 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
if (tok->strAt(2) == "(" &&
tok->linkAt(2)->strAt(1) == ";") {
// check if it is a member function
for (std::list<Function>::const_iterator it = scope->functionList.cbegin(); it != scope->functionList.cend(); ++it) {
for (auto it = scope->functionList.cbegin(); it != scope->functionList.cend(); ++it) {
// check for a regular function with the same name and a body
if (it->type == Function::eFunction && it->hasBody() &&
it->token->str() == tok->strAt(1)) {
Expand Down Expand Up @@ -2028,7 +2027,7 @@ void CheckClass::virtualDestructor()
if (baseDestructor->access == AccessControl::Public) {
virtualDestructorError(baseDestructor->token, derivedFrom->name(), derivedClass->str(), false);
// check for duplicate error and remove it if found
const std::list<const Function *>::const_iterator found = std::find(inconclusiveErrors.cbegin(), inconclusiveErrors.cend(), baseDestructor);
const auto found = std::find(inconclusiveErrors.cbegin(), inconclusiveErrors.cend(), baseDestructor);
if (found != inconclusiveErrors.cend())
inconclusiveErrors.erase(found);
}
Expand Down Expand Up @@ -2701,7 +2700,7 @@ void CheckClass::initializerListOrder()
for (const Scope * scope : mSymbolDatabase->classAndStructScopes) {

// iterate through all member functions looking for constructors
for (std::list<Function>::const_iterator func = scope->functionList.cbegin(); func != scope->functionList.cend(); ++func) {
for (auto func = scope->functionList.cbegin(); func != scope->functionList.cend(); ++func) {
if (func->isConstructor() && func->hasBody()) {
// check for initializer list
const Token *tok = func->arg->link()->next();
Expand Down Expand Up @@ -2854,7 +2853,7 @@ void CheckClass::checkVirtualFunctionCallInConstructor()
const std::list<const Token *> & CheckClass::getVirtualFunctionCalls(const Function & function,
std::map<const Function *, std::list<const Token *>> & virtualFunctionCallsMap)
{
const std::map<const Function *, std::list<const Token *>>::const_iterator found = virtualFunctionCallsMap.find(&function);
const auto found = utils::as_const(virtualFunctionCallsMap).find(&function);
if (found != virtualFunctionCallsMap.end())
return found->second;

Expand Down Expand Up @@ -2919,7 +2918,7 @@ void CheckClass::getFirstVirtualFunctionCallStack(
pureFuncStack.push_back(callFunction->tokenDef);
return;
}
std::map<const Function *, std::list<const Token *>>::const_iterator found = virtualFunctionCallsMap.find(callFunction);
auto found = utils::as_const(virtualFunctionCallsMap).find(callFunction);
if (found == virtualFunctionCallsMap.cend() || found->second.empty()) {
pureFuncStack.clear();
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/checkfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class CPPCHECKLIB CheckFunctions : public Check {
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
CheckFunctions c(nullptr, settings, errorLogger);

for (std::map<std::string, Library::WarnInfo>::const_iterator i = settings->library.functionwarn().cbegin(); i != settings->library.functionwarn().cend(); ++i) {
for (auto i = settings->library.functionwarn().cbegin(); i != settings->library.functionwarn().cend(); ++i) {
c.reportError(nullptr, Severity::style, i->first+"Called", i->second.message);
}

Expand Down
3 changes: 1 addition & 2 deletions lib/checkinternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ void CheckInternal::checkMissingPercentCharacter()

const std::string pattern = patternTok->strValue();

std::set<std::string>::const_iterator knownPattern, knownPatternsEnd = knownPatterns.cend();
for (knownPattern = knownPatterns.cbegin(); knownPattern != knownPatternsEnd; ++knownPattern) {
for (auto knownPattern = knownPatterns.cbegin(); knownPattern != knownPatterns.cend(); ++knownPattern) {
const std::string brokenPattern = knownPattern->substr(0, knownPattern->size() - 1);

std::string::size_type pos = 0;
Expand Down
8 changes: 4 additions & 4 deletions lib/checkio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void CheckIO::checkFileUsage()
} else if (Token::Match(tok, "%var% =") &&
(tok->strAt(2) != "fopen" && tok->strAt(2) != "freopen" && tok->strAt(2) != "tmpfile" &&
(windows ? (tok->str() != "_wfopen" && tok->str() != "_wfreopen") : true))) {
const std::map<int, Filepointer>::iterator i = filepointers.find(tok->varId());
const auto i = filepointers.find(tok->varId());
if (i != filepointers.end()) {
i->second.mode = OpenMode::UNKNOWN_OM;
i->second.lastOperation = Filepointer::Operation::UNKNOWN_OP;
Expand Down Expand Up @@ -289,7 +289,7 @@ void CheckIO::checkFileUsage()
switch (operation) {
case Filepointer::Operation::OPEN:
if (fileNameTok) {
for (std::map<int, Filepointer>::const_iterator it = filepointers.cbegin(); it != filepointers.cend(); ++it) {
for (auto it = filepointers.cbegin(); it != filepointers.cend(); ++it) {
const Filepointer &fptr = it->second;
if (fptr.filename == fileNameTok->str() && (fptr.mode == OpenMode::RW_MODE || fptr.mode == OpenMode::WRITE_MODE))
incompatibleFileOpenError(tok, fileNameTok->str());
Expand Down Expand Up @@ -509,7 +509,7 @@ static bool findFormat(nonneg int arg, const Token *firstArg,
argTok->variable()->dimension(0) != 0))) {
formatArgTok = argTok->nextArgument();
if (!argTok->values().empty()) {
const std::list<ValueFlow::Value>::const_iterator value = std::find_if(
const auto value = std::find_if(
argTok->values().cbegin(), argTok->values().cend(), std::mem_fn(&ValueFlow::Value::isTokValue));
if (value != argTok->values().cend() && value->isTokValue() && value->tokvalue &&
value->tokvalue->tokType() == Token::eString) {
Expand Down Expand Up @@ -615,7 +615,7 @@ void CheckIO::checkFormatString(const Token * const tok,
bool percent = false;
const Token* argListTok2 = argListTok;
std::set<int> parameterPositionsUsed;
for (std::string::const_iterator i = formatString.cbegin(); i != formatString.cend(); ++i) {
for (auto i = formatString.cbegin(); i != formatString.cend(); ++i) {
if (*i == '%') {
percent = !percent;
} else if (percent && *i == '[') {
Expand Down
Loading